0

support for mixed png/jpg tilesets, and overlays with imgformat=jpg

This commit is contained in:
Aaron Griffith
2011-04-16 19:25:40 -04:00
parent 26b35906a4
commit 05c4083b7e
5 changed files with 26 additions and 24 deletions

View File

@@ -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

View File

@@ -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}
];

View File

@@ -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)

View File

@@ -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):

View File

@@ -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]);