0

Merge branch 'upstream' into biomesoverlay

This commit is contained in:
Thomas Lake
2012-08-30 10:16:37 +01:00
6 changed files with 70 additions and 16 deletions

View File

@@ -308,6 +308,25 @@ the form ``key = value``. Two items take a different form:, ``worlds`` and
observer = JSObserver(outputdir, 10)
.. _customwebassets:
``customwebassets = "<path to custom web assets>"``
This option allows you to speciy a directory containing custom web assets
to be copied to the output directory. Any files in the custom web assets
directory overwrite the default files.
If you are providing a custom index.html, the following strings will be replaced:
* ``{title}``
Will be replaced by 'Minecraft Overviewer'
* ``{time}``
Will be replaced by the current date and time when the world is rendered
e.g. 'Sun, 12 Aug 2012 15:25:40 BST'
* ``{version}``
Will be replaced by the version of Overviewer used
e.g. '0.9.276 (5ff9c50)'
.. _renderdict:

View File

@@ -219,6 +219,11 @@ is typically correct.
specify ``-v -q`` to get only INFO logs and higher (no DEBUG) but with the
more verbose logging format.
.. cmdoption:: --update-web-assets
Update web assets, including custom assets, without starting a render.
This won't update overviewerConfig.js, but will recreate overviewer.js
.. _installing-textures:
Installing the Textures

View File

@@ -83,6 +83,8 @@ def main():
help="Prints the location and hash of terrain.png, useful for debugging terrain.png problems")
parser.add_option("-V", "--version", dest="version",
help="Displays version information and then exits", action="store_true")
parser.add_option("--update-web-assets", dest='update_web_assets', action="store_true",
help="Update web assets. Will *not* render tiles or update overviewerConfig.js")
# Log level options:
parser.add_option("-q", "--quiet", dest="quiet", action="count", default=0,
@@ -334,6 +336,18 @@ dir but you forgot to put quotes around the directory, since it contains spaces.
logging.exception("Could not create the output directory.")
return 1
########################################################################
# Now we start the actual processing, now that all the configuration has
# been gathered and validated
# create our asset manager... ASSMAN
assetMrg = assetmanager.AssetManager(destdir, config.get('customwebassets', None))
# If we've been asked to update web assets, do that and then exit
if options.update_web_assets:
assetMrg.output_noconfig()
logging.info("Web assets have been updated")
return 0
# The changelist support.
changelists = {}
for render in config['renders'].itervalues():
@@ -347,13 +361,6 @@ dir but you forgot to put quotes around the directory, since it contains spaces.
out = changelists[path]
render['changelist'] = out.fileno()
########################################################################
# Now we start the actual processing, now that all the configuration has
# been gathered and validated
# create our asset manager... ASSMAN
assetMrg = assetmanager.AssetManager(destdir)
tilesets = []
# saves us from creating the same World object over and over again

View File

@@ -33,13 +33,14 @@ same time, controls the generated javascript files in the output directory.
There should only be one instances of these per execution.
"""
def __init__(self, outputdir):
def __init__(self, outputdir, custom_assets_dir=None):
"""\
Initializes the AssetManager with the top-level output directory.
It can read/parse and write/dump the overviewerConfig.js file into this top-level
directory.
"""
self.outputdir = outputdir
self.custom_assets_dir = custom_assets_dir
self.renders = dict()
# look for overviewerConfig in self.outputdir
@@ -134,6 +135,17 @@ directory.
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()
def output_noconfig(self):
# copy web assets into destdir:
global_assets = os.path.join(util.get_program_path(), "overviewer_core", "data", "web_assets")
@@ -141,7 +153,12 @@ directory.
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 self.custom_assets_dir:
# Could have done something fancy here rather than just overwriting
# the global files, but apparently this what we used to do pre-rewrite.
mirror_dir(self.custom_assets_dir, 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");
@@ -162,12 +179,6 @@ directory.
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")

View File

@@ -84,7 +84,7 @@ renders = Setting(required=True, default=util.OrderedDict(),
"showspawn": Setting(required=False, validator=validateBool, default=True),
"base": Setting(required=False, validator=validateStr, default=""),
"poititle": Setting(required=False, validator=validateStr, default="Signs"),
"customwebassets": Setting(required=False, validator=validateWebAssetsPath, default=None),
# Remove this eventually (once people update their configs)
"worldname": Setting(required=False, default=None,
validator=error("The option 'worldname' is now called 'world'. Please update your config files")),

View File

@@ -214,6 +214,18 @@ def validateDefaultZoom(z):
else:
raise ValidationException("The default zoom is set below 1")
def validateWebAssetsPath(p):
try:
validatePath(p)
except ValidationException as e:
raise ValidationException("Bad custom web assets path: %s" % e.message)
def validatePath(p):
_, path = checkBadEscape(p)
abs_path = expand_path(path)
if not os.path.exists(abs_path):
raise ValidationException("'%s' does not exist. Path initially given as '%s'" % (abs_path,p))
def make_dictValidator(keyvalidator, valuevalidator):
"""Compose and return a dict validator -- a validator that validates each
key and value in a dictionary.