def __init__(self, worldobj, destdir, bgcolor, depth=None, tiledir=None, imgformat=None, imgquality=95, optimizeimg=None, rendermode="normal"): """Generates a quadtree from the world given into the given dest directory worldobj is a world.WorldRenderer object that has already been processed If depth is given, it overrides the calculated value. Otherwise, the minimum depth that contains all chunks is calculated and used. """ assert(imgformat) self.imgformat = imgformat self.imgquality = imgquality self.optimizeimg = optimizeimg self.bgcolor = bgcolor self.rendermode = rendermode # force png renderformat if we're using an overlay mode if 'overlay' in get_render_mode_inheritance(rendermode): self.imgformat = "png" # Make the destination dir if not os.path.exists(destdir): os.makedirs(os.path.abspath(destdir)) if tiledir is None: tiledir = rendermode self.tiledir = tiledir if depth is None: # Determine quadtree depth (midpoint is always 0,0) for p in xrange(15): # Will 2^p tiles wide and high suffice? # X has twice as many chunks as tiles, then halved since this is a # radius xradius = 2**p # Y has 4 times as many chunks as tiles, then halved since this is # a radius yradius = 2*2**p if xradius >= worldobj.maxcol and -xradius <= worldobj.mincol and \ yradius >= worldobj.maxrow and -yradius <= worldobj.minrow: break else: raise ValueError("Your map is waaaay too big! Use the 'zoom' option in 'settings.py'.") self.p = p else: self.p = depth xradius = 2**depth yradius = 2*2**depth # Make new row and column ranges self.mincol = -xradius self.maxcol = xradius self.minrow = -yradius self.maxrow = yradius self.world = worldobj self.destdir = destdir self.full_tiledir = os.path.join(destdir, tiledir)
def go(self, procs): """Writes out config.js, marker.js, and region.js Copies web assets into the destdir""" zoomlevel = self.p 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)) # copy web assets into destdir: mirror_dir(os.path.join(util.get_program_path(), "web_assets"), self.destdir) # do the same with the local copy, if we have it if self.web_assets_path: mirror_dir(self.web_assets_path, self.destdir) # replace the config js stuff config = open(os.path.join(self.destdir, "overviewerConfig.js"), "r").read() config = config.replace("{minzoom}", str(0)) config = config.replace("{maxzoom}", str(zoomlevel)) config = config.replace("{spawn_coords}", json.dumps(list(self.world.spawn))) # config = config.replace("{bg_color}", self.bg_color) # create generated map type data, from given quadtrees maptypedata = map( lambda q: { "label": q.rendermode.capitalize(), "path": q.tiledir, "bg_color": self.bg_color, "overlay": "overlay" in get_render_mode_inheritance(q.rendermode), "imgformat": q.imgformat, }, self.quadtrees, ) config = config.replace("{maptypedata}", json.dumps(maptypedata)) with open(os.path.join(self.destdir, "overviewerConfig.js"), "w") as output: output.write(config) # Add time and version in index.html indexpath = os.path.join(self.destdir, "index.html") index = open(indexpath, "r").read() index = index.replace("{time}", str(strftime("%a, %d %b %Y %H:%M:%S %Z", localtime()))) index = index.replace("{version}", util.findGitVersion()) with open(os.path.join(self.destdir, "index.html"), "w") as output: output.write(index) if self.skipjs: if self.web_assets_hook: self.web_assets_hook(self) return
def go(self, procs): """Writes out config.js, marker.js, and region.js Copies web assets into the destdir""" zoomlevel = self.p 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)) # 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.destdir) # do the same with the local copy, if we have it if self.web_assets_path: mirror_dir(self.web_assets_path, self.destdir) # replace the config js stuff config = open(os.path.join(self.destdir, 'overviewerConfig.js'), 'r').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))) #config = config.replace("{bg_color}", self.bg_color) # create generated map type data, from given quadtrees maptypedata = map(lambda q: {'label' : q.rendermode.capitalize(), 'path' : q.tiledir, 'bg_color': self.bg_color, 'overlay' : 'overlay' in get_render_mode_inheritance(q.rendermode), 'imgformat' : q.imgformat}, self.quadtrees) config = config.replace("{maptypedata}", json.dumps(maptypedata)) with open(os.path.join(self.destdir, "overviewerConfig.js"), 'w') as output: output.write(config) # Add time and version in index.html indexpath = os.path.join(self.destdir, "index.html") index = open(indexpath, 'r').read() index = index.replace("{time}", str(strftime("%a, %d %b %Y %H:%M:%S %Z", localtime()))) versionstr = "%s (%s)" % (overviewer_version.VERSION, overviewer_version.HASH[:7]) index = index.replace("{version}", versionstr) with open(os.path.join(self.destdir, "index.html"), 'w') as output: output.write(index) if self.skipjs: if self.web_assets_hook: self.web_assets_hook(self) return
def go(self, procs): """Writes out config.js, marker.js, and region.js Copies web assets into the destdir""" zoomlevel = self.p 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)) # 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.destdir) # do the same with the local copy, if we have it if self.web_assets_path: mirror_dir(self.web_assets_path, self.destdir) # replace the config js stuff config = codecs.open(os.path.join(self.destdir, '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))) #config = config.replace("{bg_color}", self.bg_color) # helper function to get a label for the given rendermode def get_render_mode_label(rendermode): info = get_render_mode_info(rendermode) if 'label' in info: return info['label'] return rendermode.capitalize() # create generated map type data, from given quadtrees maptypedata = map( lambda q: { 'label': get_render_mode_label(q.rendermode), 'shortname': q.rendermode, 'path': q.tiledir, 'bg_color': self.bg_color, 'overlay': 'overlay' in get_render_mode_inheritance( q.rendermode), 'imgformat': q.imgformat }, self.quadtrees) config = config.replace("{maptypedata}", json.dumps(maptypedata)) with codecs.open(os.path.join(self.destdir, "overviewerConfig.js"), 'w', encoding='UTF-8') as output: output.write(config) # Add time and version in index.html indexpath = os.path.join(self.destdir, "index.html") index = codecs.open(indexpath, 'r', encoding='UTF-8').read() index = index.replace( "{title}", "%s Map - Minecraft Overviewer" % self.world.name) index = index.replace( "{time}", strftime("%a, %d %b %Y %H:%M:%S %Z", localtime()).decode(locale.getpreferredencoding())) versionstr = "%s (%s)" % (overviewer_version.VERSION, overviewer_version.HASH[:7]) index = index.replace("{version}", versionstr) with codecs.open(os.path.join(self.destdir, "index.html"), 'w', encoding='UTF-8') as output: output.write(index) if self.skipjs: if self.web_assets_hook: self.web_assets_hook(self) return
def go(self, procs): """Writes out config.js, marker.js, and region.js Copies web assets into the destdir""" zoomlevel = self.p 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)) # 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.destdir) # do the same with the local copy, if we have it if self.web_assets_path: mirror_dir(self.web_assets_path, self.destdir) # replace the config js stuff config = codecs.open(os.path.join(self.destdir, "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))) config = config.replace("{cache_tag}", str(int(time()))) # config = config.replace("{bg_color}", self.bg_color) # helper function to get a label for the given rendermode def get_render_mode_label(rendermode): info = get_render_mode_info(rendermode) if "label" in info: return info["label"] return rendermode.capitalize() # create generated map type data, from given quadtrees maptypedata = map( lambda q: { "label": get_render_mode_label(q.rendermode), "shortname": q.rendermode, "path": q.tiledir, "bg_color": self.bg_color, "overlay": "overlay" in get_render_mode_inheritance(q.rendermode), "imgformat": q.imgformat, }, self.quadtrees, ) config = config.replace("{maptypedata}", json.dumps(maptypedata)) with codecs.open(os.path.join(self.destdir, "overviewerConfig.js"), "w", encoding="UTF-8") as output: output.write(config) # Add time and version in index.html indexpath = os.path.join(self.destdir, "index.html") index = codecs.open(indexpath, "r", encoding="UTF-8").read() index = index.replace("{title}", "%s Map - Minecraft Overviewer" % self.world.name) index = index.replace( "{time}", strftime("%a, %d %b %Y %H:%M:%S %Z", localtime()).decode(locale.getpreferredencoding()) ) versionstr = "%s (%s)" % (overviewer_version.VERSION, overviewer_version.HASH[:7]) index = index.replace("{version}", versionstr) with codecs.open(os.path.join(self.destdir, "index.html"), "w", encoding="UTF-8") as output: output.write(index) if self.skipjs: if self.web_assets_hook: self.web_assets_hook(self) return
def __init__(self, worldobj, destdir, bgcolor="#1A1A1A", depth=None, tiledir=None, forcerender=False, imgformat='png', imgquality=95, optimizeimg=None, rendermode="normal", rerender_prob=0.0): """Generates a quadtree from the world given into the given dest directory worldobj is a world.WorldRenderer object that has already been processed If depth is given, it overrides the calculated value. Otherwise, the minimum depth that contains all chunks is calculated and used. """ self.forcerender = forcerender self.rerender_probability = rerender_prob self.imgformat = imgformat self.imgquality = imgquality self.optimizeimg = optimizeimg self.bgcolor = bgcolor self.rendermode = rendermode # force png renderformat if we're using an overlay mode if 'overlay' in get_render_mode_inheritance(rendermode): self.imgformat = "png" # Make the destination dir if not os.path.exists(destdir): os.makedirs(os.path.abspath(destdir)) if tiledir is None: tiledir = rendermode self.tiledir = tiledir if depth is None: # Determine quadtree depth (midpoint is always 0,0) for p in xrange(33): # Will 2^p tiles wide and high suffice? # X has twice as many chunks as tiles, then halved since this is a # radius xradius = 2**p # Y has 4 times as many chunks as tiles, then halved since this is # a radius yradius = 2*2**p if xradius >= worldobj.maxcol and -xradius <= worldobj.mincol and \ yradius >= worldobj.maxrow and -yradius <= worldobj.minrow: break if p < 15: self.p = p else: raise ValueError("Your map is waaaay too big! Use the 'zoom' option in 'settings.py'. Overviewer is estimating %i zoom levels, but you probably want less." % (p,)) else: self.p = depth xradius = 2**depth yradius = 2*2**depth # Make new row and column ranges self.mincol = -xradius self.maxcol = xradius self.minrow = -yradius self.maxrow = yradius self.world = worldobj self.destdir = destdir self.full_tiledir = os.path.join(destdir, tiledir) # Check now if full_tiledir doesn't exist. If not, we can trigger # --fullrender, which skips some mtime checks to speed things up if not os.path.exists(self.full_tiledir): logging.debug("%s doesn't exist, doing a full render", self.full_tiledir) self.forcerender = True
def __init__(self, worldobj, destdir, bgcolor="#1A1A1A", depth=None, tiledir=None, forcerender=False, imgformat='png', imgquality=95, optimizeimg=None, rendermode="normal", rerender_prob=0.0): """Generates a quadtree from the world given into the given dest directory worldobj is a world.WorldRenderer object that has already been processed If depth is given, it overrides the calculated value. Otherwise, the minimum depth that contains all chunks is calculated and used. """ self.forcerender = forcerender self.rerender_probability = rerender_prob self.imgformat = imgformat self.imgquality = imgquality self.optimizeimg = optimizeimg self.bgcolor = bgcolor self.rendermode = rendermode # force png renderformat if we're using an overlay mode if 'overlay' in get_render_mode_inheritance(rendermode): self.imgformat = "png" # Make the destination dir if not os.path.exists(destdir): os.makedirs(os.path.abspath(destdir)) if tiledir is None: tiledir = rendermode self.tiledir = tiledir if depth is None: # Determine quadtree depth (midpoint is always 0,0) for p in xrange(33): # Will 2^p tiles wide and high suffice? # X has twice as many chunks as tiles, then halved since this is a # radius xradius = 2**p # Y has 4 times as many chunks as tiles, then halved since this is # a radius yradius = 2 * 2**p if xradius >= worldobj.maxcol and -xradius <= worldobj.mincol and \ yradius >= worldobj.maxrow and -yradius <= worldobj.minrow: break if p < 15: self.p = p else: raise ValueError( "Your map is waaaay too big! Use the 'zoom' option in 'settings.py'. Overviewer is estimating %i zoom levels, but you probably want less." % (p, )) else: self.p = depth xradius = 2**depth yradius = 2 * 2**depth # Make new row and column ranges self.mincol = -xradius self.maxcol = xradius self.minrow = -yradius self.maxrow = yradius self.world = worldobj self.destdir = destdir self.full_tiledir = os.path.join(destdir, tiledir) # Check now if full_tiledir doesn't exist. If not, we can trigger # --fullrender, which skips some mtime checks to speed things up if not os.path.exists(self.full_tiledir): logging.debug("%s doesn't exist, doing a full render", self.full_tiledir) self.forcerender = True