0

The AssetManager will now create a kinda working html output

This commit is contained in:
Andrew Chin
2012-01-07 23:04:42 -05:00
parent 9aa3847068
commit 25db39463f
5 changed files with 109 additions and 54 deletions

View File

@@ -13,6 +13,10 @@
# You should have received a copy of the GNU General Public License along
# with the Overviewer. If not, see <http://www.gnu.org/licenses/>.
import json
import os
import codecs
from PIL import Image
class AssetManager(object):
"""\
@@ -28,6 +32,7 @@ It can read/parse and write/dump the overviewerConfig.js file into this top-leve
directory.
"""
self.outputdir = outputdir
self.renders = dict()
# stores Points Of Interest to be mapped with markers
# This is a dictionary of lists of dictionaries
@@ -41,18 +46,70 @@ directory.
POI[regionset.name].append
def finalize(self):
def finalize(self, tilesets):
# the following bit of code came from googlemap.py
zoomlevel = self.p
# dictionary to hold the overviewerConfig.js settings that we will dumps
dump = dict()
dump['CONST'] = dict(tileSize=384)
dump['CONST']['image'] = {
'defaultMarker': 'signpost.png',
'signMarker': 'signpost_icon.png',
'compass': 'compass_lower-left.png',
'spawnMarker': 'http://google-maps-icons.googlecode.com/files/home.png',
'queryMarker': 'http://google-maps-icons.googlecode.com/files/regroup.png'
}
dump['CONST']['mapDivId'] = 'mcmap'
dump['CONST']['regionStrokeWeight'] = 2
bgcolor = (int(self.bg_color[1:3],16), int(self.bg_color[3:5],16), int(self.bg_color[5:7],16), 0)
blank = Image.new("RGBA", (1,1), bgcolor)
# Write a blank image
for quadtree in self.quadtrees:
tileDir = os.path.join(self.destdir, quadtree.tiledir)
if not os.path.exists(tileDir): os.mkdir(tileDir)
blank.save(os.path.join(tileDir, "blank."+quadtree.imgformat))
# based on the tilesets we have, group them by worlds
worlds = []
for tileset in tilesets:
if tileset.options.get('worldname_orig') not in worlds:
worlds.append(tileset.options.get('worldname_orig'))
dump['worlds'] = worlds
dump['map'] = dict()
dump['map']['debug'] = True
dump['map']['center'] = [-314, 67, 94]
dump['map']['controls'] = {
'pan': True,
'zoom': True,
'spawn': True,
'compass': True,
'mapType': True,
'overlays': True,
'coordsBox': True,
'searchBox': True
}
dump['tilesets'] = []
def bgcolorformat(color):
return "#%02x%02x%02x" % color[0:3]
for tileset in tilesets:
js_tileset = dict()
js_tileset['name'] = tileset.options.get('name')
js_tileset['zoomLevels'] = tileset.treedepth
js_tileset['minZoom'] = 0
js_tileset['defaultZoom'] = 1
js_tileset['maxZoom'] = tileset.treedepth
js_tileset['path'] = tileset.options.get('name')
js_tileset['base'] = ''
js_tileset['bgcolor'] = bgcolorformat(tileset.options.get('bgcolor'))
dump['tilesets'].append(js_tileset)
# write a blank image
blank = Image.new("RGBA", (1,1), tileset.options.get('bgcolor'))
blank.save(os.path.join(self.outputdir, tileset.options.get('name'), "blank."+tileset.options.get('imgformat')))
jsondump = json.dumps(dump, indent=4)
with codecs.open(os.path.join(self.outputdir, 'overviewerConfig.js'), 'w', encoding='UTF-8') as f:
f.write("var overviewerConfig = " + jsondump + ";\n")
# copy web assets into destdir:
global_assets = os.path.join(util.get_program_path(), "overviewer_core", "data", "web_assets")
@@ -64,21 +121,6 @@ directory.
if self.web_assets_path:
mirror_dir(self.web_assets_path, self.destdir)
# replace the config js stuff
# TODO don't replace stuff, but generate it from scratch
config = codecs.open(os.path.join(self.outputdir, 'overviewerConfig.js'), 'r', encoding='UTF-8').read()
config = config.replace(
"{minzoom}", str(0))
config = config.replace(
"{maxzoom}", str(zoomlevel))
config = config.replace(
"{zoomlevels}", str(zoomlevel))
config = config.replace(
"{north_direction}", self.north_direction)
config = config.replace("{spawn_coords}",
json.dumps(list(self.world.spawn)))
# helper function to get a label for the given rendermode

View File

@@ -268,6 +268,7 @@ class MultiWorldParser(object):
if not os.path.exists(self.world[worldname]):
raise Exception("%r does not exist for %s" % (self.world[worldname], worldname))
origs = dict()
for worldname in self.render:
world = dict()
@@ -282,10 +283,14 @@ class MultiWorldParser(object):
definition = settingsDefinition.render[key]
try:
val = definition['validator'](world[key], world = self.world)
if definition.get('save_orig', False):
origs[key + "_orig"] = world[key]
world[key] = val
except Exception as e:
print "Error validating %s: %r" % (key, e)
raise e
world['name'] = worldname
world.update(origs)
self.render[worldname] = world

View File

@@ -121,12 +121,13 @@ var overviewer = {
*/
'initializeMapTypes': function() {
var mapOptions = {};
for (i in overviewerConfig.mapTypes) {
var view = overviewerConfig.mapTypes[i];
for (i in overviewerConfig.tilesets) {
var view = overviewerConfig.tilesets[i];
overviewer.util.debug("initializeMapTypes: " + view.name);
var imageFormat = view.imgformat ? view.imgformat : 'png';
if (view.shortname == null)
view.shortname = view.label.replace(/\s+/g, "");
view.shortname = view.name.replace(/\s+/g, "");
mapOptions[view.shortname] = {
'getTileUrl': overviewer.gmap.getTileUrlGenerator(view.path,
@@ -134,16 +135,16 @@ var overviewer = {
'tileSize': new google.maps.Size(
overviewerConfig.CONST.tileSize,
overviewerConfig.CONST.tileSize),
'maxZoom': overviewerConfig.map.maxZoom,
'minZoom': overviewerConfig.map.minZoom,
'maxZoom': view.maxZoom,
'minZoom': view.minZoom,
'isPng': imageFormat.toLowerCase() == 'png'
}
overviewer.collections.mapTypes[view.shortname] = new google.maps.ImageMapType(
mapOptions[view.shortname]);
overviewer.collections.mapTypes[view.shortname].name = view.label;
overviewer.collections.mapTypes[view.shortname].name = view.name;
overviewer.collections.mapTypes[view.shortname].shortname = view.shortname;
overviewer.collections.mapTypes[view.shortname].alt = 'Minecraft ' +
view.label + ' Map';
view.name + ' Map';
overviewer.collections.mapTypes[view.shortname].projection =
new overviewer.classes.MapProjection();
if (view.overlay) {
@@ -162,12 +163,16 @@ var overviewer = {
* the default view.
*/
'initializeMap': function() {
// use the first map as the default one
var defaultCenter = overviewer.util.fromWorldToLatLng(
overviewerConfig.map.center[0], overviewerConfig.map.center[1],
overviewerConfig.map.center[2]);
overviewerConfig.map.center[0],
overviewerConfig.map.center[1],
overviewerConfig.map.center[2],
overviewerConfig.tilesets[0].zoomLevels);
var lat = defaultCenter.lat();
var lng = defaultCenter.lng();
var zoom = overviewerConfig.map.defaultZoom;
var zoom = overviewerConfig.tilesets[0].defaultZoom;
var mapcenter;
var queryParams = overviewer.util.parseQueryString();
if (queryParams.debug) {
@@ -223,8 +228,7 @@ var overviewer = {
streetViewControl: false,
overviewMapControl: true,
zoomControl: overviewerConfig.map.controls.zoom,
backgroundColor: overviewer.util.getMapTypeBackgroundColor(
overviewer.util.getDefaultMapTypeId())
backgroundColor: overviewer.util.getMapTypeBackgroundColor(0)
};
overviewer.map = new google.maps.Map(document.getElementById(
overviewerConfig.CONST.mapDivId), mapOptions);
@@ -287,12 +291,14 @@ var overviewer = {
*/
'initializeMarkers': function() {
//first, give all collections an empty array to work with
/* TODO reimplement
for (i in overviewerConfig.objectGroups.signs) {
overviewer.util.debug('Found sign group: ' +
overviewerConfig.objectGroups.signs[i].label);
overviewer.collections.markers[
overviewerConfig.objectGroups.signs[i].label] = [];
}
*/
for (i in overviewer.collections.markerDatas) {
var markerData = overviewer.collections.markerDatas[i];
for (j in markerData) {
@@ -390,9 +396,11 @@ var overviewer = {
* Same as initializeMarkers() for the most part.
*/
'initializeRegions': function() {
/* TODO reimplement
for (i in overviewerConfig.objectGroups.regions) {
overviewer.collections.regions[overviewerConfig.objectGroups.regions[i].label] = [];
}
*/
for (i in overviewer.collections.regionDatas) {
var regionData = overviewer.collections.regionDatas[i];
for (j in regionData) {
@@ -484,15 +492,8 @@ var overviewer = {
* @param string mapTypeId
* @return string
*/
'getMapTypeBackgroundColor': function(mapTypeId) {
for(i in overviewerConfig.mapTypes) {
if( overviewerConfig.CONST.mapDivId +
overviewerConfig.mapTypes[i].shortname == mapTypeId ) {
overviewer.util.debug('Found background color for: ' +
overviewerConfig.mapTypes[i].bg_color);
return overviewerConfig.mapTypes[i].bg_color;
}
}
'getMapTypeBackgroundColor': function(id) {
return overviewerConfig.tilesets[id].bgcolor;
},
/**
* Gee, I wonder what this does.
@@ -538,11 +539,11 @@ var overviewer = {
*
* @return google.maps.LatLng
*/
'fromWorldToLatLng': function(x, z, y) {
'fromWorldToLatLng': function(x, z, y, zoomLevels) {
// the width and height of all the highest-zoom tiles combined,
// inverted
var perPixel = 1.0 / (overviewerConfig.CONST.tileSize *
Math.pow(2, overviewerConfig.map.zoomLevels));
Math.pow(2, zoomLevels));
if(overviewerConfig.map.north_direction == 'upper-left'){
temp = x;
@@ -565,7 +566,7 @@ var overviewer = {
// so the Y coordinate is at 0.5, and the X is at 0.5 -
// ((tileSize / 2) / (tileSize * 2^zoomLevels))
// or equivalently, 0.5 - (1 / 2^(zoomLevels + 1))
var lng = 0.5 - (1.0 / Math.pow(2, overviewerConfig.map.zoomLevels + 1));
var lng = 0.5 - (1.0 / Math.pow(2, zoomLevels + 1));
var lat = 0.5;
// the following metrics mimic those in
@@ -597,7 +598,7 @@ var overviewer = {
*
* @return Array
*/
'fromLatLngToWorld': function(lat, lng) {
'fromLatLngToWorld': function(lat, lng, zoomLevels) {
// Initialize world x/y/z object to be returned
var point = Array();
point.x = 0;
@@ -607,11 +608,11 @@ var overviewer = {
// the width and height of all the highest-zoom tiles combined,
// inverted
var perPixel = 1.0 / (overviewerConfig.CONST.tileSize *
Math.pow(2, overviewerConfig.map.zoomLevels));
Math.pow(2, zoomLevels));
// Revert base positioning
// See equivalent code in fromWorldToLatLng()
lng -= 0.5 - (1.0 / Math.pow(2, overviewerConfig.map.zoomLevels + 1));
lng -= 0.5 - (1.0 / Math.pow(2, zoomLevels + 1));
lat -= 0.5;
// I'll admit, I plugged this into Wolfram Alpha:
@@ -678,13 +679,16 @@ var overviewer = {
}
// Update coords on mousemove
/* TODO reenable
google.maps.event.addListener(overviewer.map, 'mousemove', function (event) {
var worldcoords = overviewer.util.fromLatLngToWorld(event.latLng.lat(), event.latLng.lng());
coordsDiv.innerHTML = "Coords: X " + Math.round(worldcoords.x) + ", Z " + Math.round(worldcoords.z);
});
*/
// only need to create the control if there are items in the list.
// as defined in config.js
/* TODO reimplement
if (overviewerConfig.objectGroups.signs.length > 0) {
// signpost display control
var items = [];
@@ -719,8 +723,10 @@ var overviewer = {
overviewer.util.createDropDown('Markers', items);
}
}
*/
// if there are any regions data, lets show the option to hide/show them.
/* TODO reimplement
if (overviewerConfig.objectGroups.regions.length > 0) {
// region display control
var items = [];
@@ -742,6 +748,7 @@ var overviewer = {
}
overviewer.util.createDropDown('Regions', items);
}
*/
if (overviewerConfig.map.controls.overlays && overviewer.collections.overlays.length > 0) {
// overlay maps control

View File

@@ -17,7 +17,7 @@ from settingsValidators import *
# note that all defaults go thought the validator
render = {
"worldname": dict(required=True, validator=validateWorldPath),
"worldname": dict(required=True, validator=validateWorldPath, save_orig=True),
"rendermode": dict(required=False, validator=validateRenderMode),
"northdirection": dict(required=False, validator=validateNorthDirection),
"renderrange": dict(required=False, validator=validateRenderRange),