0

Initial commit of the AssetManager

Mostly a blind copy/past from world.py and googlemap.py.  Not runnable

Rewrite Tracking Issue: #565
This commit is contained in:
Andrew Chin
2011-12-19 19:48:27 -05:00
parent 581ee0906a
commit d332554ec2
3 changed files with 179 additions and 144 deletions

View File

@@ -101,112 +101,16 @@ class MapGen(object):
"""Writes out overviewerConfig.js and does copying of the other static web assets
"""
zoomlevel = self.p
### TODO remove this method? It has been moved into assetmanager.py
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
pass
def finalize(self):
"""Write out persistent data file and marker listings file
"""
# since we will only discover PointsOfInterest in chunks that need to be
# [re]rendered, POIs like signs in unchanged chunks will not be listed
# in self.world.POI. To make sure we don't remove these from markers.js
# we need to merge self.world.POI with the persistant data in world.PersistentData
### TODO remove this method? It has been moved into assetmanager.py
pass
self.world.POI += filter(lambda x: x['type'] != 'spawn', self.world.persistentData['POI'])
if self.nosigns:
markers = filter(lambda x: x['type'] != 'sign', self.world.POI)
else:
markers = self.world.POI
# save persistent data
self.world.persistentData['POI'] = self.world.POI
self.world.persistentData['north_direction'] = self.world.north_direction
with open(self.world.pickleFile,"wb") as f:
cPickle.dump(self.world.persistentData,f)
# the rest of the function is javascript stuff
if self.skipjs:
return
# write out the default marker table
with codecs.open(os.path.join(self.destdir, "markers.js"), 'w', encoding='UTF-8') as output:
output.write("// This is a generated file. Please do not edit it!\n")
output.write("overviewer.collections.markerDatas.push(\n")
output.write("// --start marker json dump--\n")
json.dump(markers, output, indent=1)
output.write("\n// --end marker json dump--\n")
output.write(");\n")