From 05c4083b7e1d15ae79ab9de5adf8165b2ec28123 Mon Sep 17 00:00:00 2001 From: Aaron Griffith Date: Sat, 16 Apr 2011 19:25:40 -0400 Subject: [PATCH] support for mixed png/jpg tilesets, and overlays with imgformat=jpg --- chunk.py | 4 ++++ config.js | 11 ++++++----- googlemap.py | 16 ++++++---------- quadtree.py | 10 +++++----- web_assets/functions.js | 9 +++++---- 5 files changed, 26 insertions(+), 24 deletions(-) diff --git a/chunk.py b/chunk.py index baf9efc..0fdce6c 100644 --- a/chunk.py +++ b/chunk.py @@ -129,6 +129,10 @@ fluid_blocks = set([8,9,10,11]) # (glass, half blocks) nospawn_blocks = set([20,44]) +# overlay rendermodes +# FIXME hook this into render_modes in setup.py, somehow +overlay_rendermodes = ['spawn'] + class ChunkCorrupt(Exception): pass diff --git a/config.js b/config.js index ed28985..8627c1e 100644 --- a/config.js +++ b/config.js @@ -1,6 +1,5 @@ var config = { - fileExt: '{imgformat}', tileSize: 384, defaultZoom: 2, maxZoom: {maxzoom}, @@ -59,15 +58,17 @@ var regionGroups = [ * the first one being the default. * * Required: - * label : string. Displayed on the control. - * path : string. Location of the rendered tiles. + * label : string. Displayed on the control. + * path : string. Location of the rendered tiles. * Optional: - * base : string. Base of the url path for tile locations, useful for serving tiles from a different server than the js/html server. + * base : string. Base of the url path for tile locations, useful for serving tiles from a different server than the js/html server. + * imgformat : string. File extension used for these tiles. Defaults to png. + * overlay : bool. If true, this tile set will be treated like an overlay var mapTypeData=[ {'label': 'Unlit', 'path': 'tiles'}, // {'label': 'Day', 'path': 'lighting/tiles'}, -// {'label': 'Night', 'path': 'night/tiles'}, +// {'label': 'Night', 'path': 'night/tiles', 'imgformat': 'jpg'}, // {'label': 'Spawn', 'path': 'spawn/tiles', 'base': 'http://example.cdn.amazon.com/'}, // {'label': 'Overlay', 'path': 'overlay/tiles', 'overlay': true} ]; diff --git a/googlemap.py b/googlemap.py index dde8ad7..0f883d3 100644 --- a/googlemap.py +++ b/googlemap.py @@ -23,6 +23,7 @@ from time import strftime, gmtime import json import util +from chunk import overlay_rendermodes """ This module has routines related to generating a Google Maps-based @@ -72,12 +73,11 @@ class MapGen(object): raise ValueError("there must be at least one quadtree to work on") self.destdir = quadtrees[0].destdir - self.imgformat = quadtrees[0].imgformat self.world = quadtrees[0].world self.p = quadtrees[0].p for i in quadtrees: - if i.destdir != self.destdir or i.imgformat != self.imgformat or i.world != self.world: - raise ValueError("all the given quadtrees must have the same destdir") + if i.destdir != self.destdir or i.world != self.world: + raise ValueError("all the given quadtrees must have the same destdir and world") self.quadtrees = quadtrees @@ -85,24 +85,20 @@ class MapGen(object): """Writes out config.js, marker.js, and region.js Copies web assets into the destdir""" zoomlevel = self.p - imgformat = self.imgformat configpath = os.path.join(util.get_program_path(), "config.js") config = open(configpath, 'r').read() config = config.replace( "{maxzoom}", str(zoomlevel)) - config = config.replace( - "{imgformat}", str(imgformat)) config = config.replace("{spawn_coords}", json.dumps(list(self.world.spawn))) # create generated map type data, from given quadtrees - # FIXME hook this into render_modes in setup.py, somehow - overlay_types = ['spawn'] maptypedata = map(lambda q: {'label' : q.rendermode.capitalize(), 'path' : q.tiledir, - 'overlay' : q.rendermode in overlay_types}, + 'overlay' : q.rendermode in overlay_rendermodes, + 'imgformat' : q.imgformat}, self.quadtrees) config = config.replace("{maptypedata}", json.dumps(maptypedata)) @@ -114,7 +110,7 @@ class MapGen(object): blank = Image.new("RGBA", (1,1)) tileDir = os.path.join(self.destdir, quadtree.tiledir) if not os.path.exists(tileDir): os.mkdir(tileDir) - blank.save(os.path.join(tileDir, "blank."+self.imgformat)) + blank.save(os.path.join(tileDir, "blank."+quadtree.imgformat)) # copy web assets into destdir: mirror_dir(os.path.join(util.get_program_path(), "web_assets"), self.destdir) diff --git a/quadtree.py b/quadtree.py index 51cb46e..40773e9 100644 --- a/quadtree.py +++ b/quadtree.py @@ -60,12 +60,12 @@ class QuadtreeGen(object): """ assert(imgformat) self.imgformat = imgformat - self.optimizeimg = optimizeimg - - self.lighting = rendermode in ("lighting", "night", "spawn") - self.night = rendermode in ("night", "spawn") - self.spawn = rendermode in ("spawn",) + self.optimizeimg = optimizeimg self.rendermode = rendermode + + # force png renderformat if we're using an overlay mode + if rendermode in chunk.overlay_rendermodes: + self.imgformat = "png" # Make the destination dir if not os.path.exists(destdir): diff --git a/web_assets/functions.js b/web_assets/functions.js index 038f0c2..9c8b46a 100644 --- a/web_assets/functions.js +++ b/web_assets/functions.js @@ -532,7 +532,7 @@ function fromWorldToLatLng(x, z, y) return new google.maps.LatLng(lat, lng); } -function getTileUrlGenerator(path, path_base) { +function getTileUrlGenerator(path, path_base, path_ext) { return function(tile, zoom) { var url = path; var url_base = ( path_base ? path_base : '' ); @@ -547,7 +547,7 @@ function getTileUrlGenerator(path, path_base) { url += '/' + (x + 2 * y); } } - url = url + '.' + config.fileExt; + url = url + '.' + path_ext; if(config.cacheMinutes > 0) { var d = new Date(); url += '?c=' + Math.floor(d.getTime() / (1000 * 60 * config.cacheMinutes)); @@ -563,13 +563,14 @@ var mapTypeIds = []; var overlayMapTypes = []; for (idx in mapTypeData) { var view = mapTypeData[idx]; + var imgformat = view.imgformat ? view.imgformat : 'png'; MCMapOptions[view.label] = { - getTileUrl: getTileUrlGenerator(view.path, view.base), + getTileUrl: getTileUrlGenerator(view.path, view.base, imgformat), tileSize: new google.maps.Size(config.tileSize, config.tileSize), maxZoom: config.maxZoom, minZoom: 0, - isPng: !(config.fileExt.match(/^png$/i) == null) + isPng: !(imgformat.match(/^png$/i) == null) }; MCMapType[view.label] = new google.maps.ImageMapType(MCMapOptions[view.label]);