def _output_assets(self, tilesets, initial): if not initial: get_data = lambda tileset: tileset.get_persistent_data() else: get_data = lambda tileset: tileset.get_initial_data() # 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', 'bedMarker': 'bed.png', 'compass': '******', '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 dump['CONST']['UPPERLEFT'] = world.UPPER_LEFT dump['CONST']['UPPERRIGHT'] = world.UPPER_RIGHT dump['CONST']['LOWERLEFT'] = world.LOWER_LEFT dump['CONST']['LOWERRIGHT'] = world.LOWER_RIGHT # based on the tilesets we have, group them by worlds worlds = [] for tileset in tilesets: full_name = get_data(tileset)['world'] if full_name not in worlds: worlds.append(full_name) dump['worlds'] = worlds dump['map'] = dict() dump['map']['debug'] = True dump['map']['cacheTag'] = str(int(time.time())) dump['map']['north_direction'] = 'lower-left' # only temporary 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'] = [] for tileset in tilesets: dump['tilesets'].append(get_data(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'))) # copy web assets into destdir: global_assets = os.path.join(util.get_program_path(), "overviewer_core", "data", "web_assets") if not os.path.isdir(global_assets): global_assets = os.path.join(util.get_program_path(), "web_assets") mirror_dir(global_assets, self.outputdir) # write a dummy baseMarkers.js if none exists if not os.path.exists(os.path.join(self.outputdir, "baseMarkers.js")): with open(os.path.join(self.outputdir, "baseMarkers.js"), "w") as f: f.write("// if you wants signs, please see genPOI.py\n") # create overviewer.js from the source js files js_src = os.path.join(util.get_program_path(), "overviewer_core", "data", "js_src") if not os.path.isdir(js_src): js_src = os.path.join(util.get_program_path(), "js_src") with FileReplacer(os.path.join(self.outputdir, "overviewer.js")) as tmpfile: with open(tmpfile, "w") as fout: # first copy in js_src/overviewer.js with open(os.path.join(js_src, "overviewer.js"), 'r') as f: fout.write(f.read()) # now copy in the rest for js in os.listdir(js_src): if not js.endswith("overviewer.js") and js.endswith(".js"): with open(os.path.join(js_src, js)) as f: fout.write(f.read()) # write out config jsondump = json.dumps(dump, indent=4) with FileReplacer(os.path.join(self.outputdir, "overviewerConfig.js")) as tmpfile: with codecs.open(tmpfile, 'w', encoding='UTF-8') as f: f.write("var overviewerConfig = " + jsondump + ";\n") # Add time and version in index.html indexpath = os.path.join(self.outputdir, "index.html") index = codecs.open(indexpath, 'r', encoding='UTF-8').read() index = index.replace("{title}", "Minecraft Overviewer") index = index.replace( "{time}", time.strftime("%a, %d %b %Y %H:%M:%S %Z", time.localtime()).decode( locale.getpreferredencoding())) versionstr = "%s (%s)" % (util.findGitVersion(), util.findGitHash()[:7]) index = index.replace("{version}", versionstr) with FileReplacer(indexpath) as indexpath: with codecs.open(indexpath, 'w', encoding='UTF-8') as output: output.write(index)
def _output_assets(self, tilesets, initial): if not initial: get_data = lambda tileset: tileset.get_persistent_data() else: get_data = lambda tileset: tileset.get_initial_data() # 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', 'bedMarker': 'bed.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 # Obselete dump['CONST']['UPPERLEFT'] = world.UPPER_LEFT dump['CONST']['UPPERRIGHT'] = world.UPPER_RIGHT dump['CONST']['LOWERLEFT'] = world.LOWER_LEFT dump['CONST']['LOWERRIGHT'] = world.LOWER_RIGHT # based on the tilesets we have, group them by worlds worlds = [] for tileset in tilesets: full_name = get_data(tileset)['world'] if full_name not in worlds: worlds.append(full_name) dump['worlds'] = worlds dump['map'] = dict() dump['map']['debug'] = True dump['map']['cacheTag'] = str(int(time.time())) dump['map']['north_direction'] = 'lower-left' # only temporary 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 # Lolwat. Obselete } dump['tilesets'] = [] for tileset in tilesets: dump['tilesets'].append(get_data(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'))) # write out config jsondump = json.dumps(dump, indent=4) with FileReplacer(os.path.join(self.outputdir, "overviewerConfig.js")) as tmpfile: with codecs.open(tmpfile, 'w', encoding='UTF-8') as f: f.write("var overviewerConfig = " + jsondump + ";\n") #Copy assets, modify index.html self.output_noconfig()