configurable settings.py, web_assets, textures paths
This commit is contained in:
@@ -22,6 +22,9 @@ class ConfigOptionParser(object):
|
||||
self.customArgs = ["required", "commandLineOnly", "default", "listify", "listdelim", "choices"]
|
||||
|
||||
self.requiredArgs = []
|
||||
|
||||
# add the *very* special config-file path option
|
||||
self.add_option("--config-file", dest="config_file", help="Specifies a configuration file to load, by name. This file's format is discussed in the README.", metavar="PATH", type="string", commandLineOnly=True)
|
||||
|
||||
def display_config(self):
|
||||
logging.info("Using the following settings:")
|
||||
@@ -68,8 +71,14 @@ class ConfigOptionParser(object):
|
||||
# if this has a default, use that to seed the globals dict
|
||||
if a.get("default", None): g[n] = a['default']
|
||||
g['args'] = args
|
||||
|
||||
|
||||
try:
|
||||
if options.config_file:
|
||||
self.configFile = options.config_file
|
||||
elif os.path.exists(self.configFile):
|
||||
# warn about automatic loading
|
||||
logging.warning("Automatic settings.py loading is DEPRECATED, and may be removed in the future. Please use --config-file instead.")
|
||||
|
||||
if os.path.exists(self.configFile):
|
||||
execfile(self.configFile, g, l)
|
||||
except NameError, ex:
|
||||
|
||||
34
googlemap.py
34
googlemap.py
@@ -68,6 +68,7 @@ class MapGen(object):
|
||||
|
||||
self.skipjs = configInfo.get('skipjs', None)
|
||||
self.web_assets_hook = configInfo.get('web_assets_hook', None)
|
||||
self.web_assets_path = configInfo.get('web_assets_path', None)
|
||||
self.bg_color = configInfo.get('bg_color')
|
||||
|
||||
if not len(quadtrees) > 0:
|
||||
@@ -81,14 +82,28 @@ class MapGen(object):
|
||||
raise ValueError("all the given quadtrees must have the same destdir and world")
|
||||
|
||||
self.quadtrees = quadtrees
|
||||
|
||||
|
||||
def go(self, procs):
|
||||
"""Writes out config.js, marker.js, and region.js
|
||||
Copies web assets into the destdir"""
|
||||
zoomlevel = self.p
|
||||
configpath = os.path.join(util.get_program_path(), "overviewerConfig.js")
|
||||
|
||||
config = open(configpath, 'r').read()
|
||||
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(
|
||||
@@ -111,18 +126,7 @@ class MapGen(object):
|
||||
with open(os.path.join(self.destdir, "overviewerConfig.js"), 'w') as output:
|
||||
output.write(config)
|
||||
|
||||
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)
|
||||
|
||||
# Add time in index.html
|
||||
# Add time and version in index.html
|
||||
indexpath = os.path.join(self.destdir, "index.html")
|
||||
|
||||
index = open(indexpath, 'r').read()
|
||||
|
||||
@@ -101,6 +101,8 @@ def main():
|
||||
parser.add_option("--bg_color", dest="bg_color", help="Configures the background color for the GoogleMap output. Specify in #RRGGBB format", configFileOnly=True, type="string", default="#1A1A1A")
|
||||
parser.add_option("--optimize-img", dest="optimizeimg", help="If using png, perform image file size optimizations on the output. Specify 1 for pngcrush, 2 for pngcrush+optipng+advdef. This may double (or more) render times, but will produce up to 30% smaller images. NOTE: requires corresponding programs in $PATH or %PATH%", configFileOnly=True)
|
||||
parser.add_option("--web-assets-hook", dest="web_assets_hook", help="If provided, run this function after the web assets have been copied, but before actual tile rendering begins. It should accept a QuadtreeGen object as its only argument.", action="store", metavar="SCRIPT", type="function", configFileOnly=True)
|
||||
parser.add_option("--web-assets-path", dest="web_assets_path", help="Specifies a non-standard web_assets directory to use. Files here will overwrite the default web assets.", metavar="PATH", type="string", configFileOnly=True)
|
||||
parser.add_option("--textures-path", dest="textures_path", help="Specifies a non-standard textures path, from which terrain.png and other textures are loaded.", metavar="PATH", type="string", configFileOnly=True)
|
||||
parser.add_option("-q", "--quiet", dest="quiet", action="count", default=0, help="Print less output. You can specify this option multiple times.")
|
||||
parser.add_option("-v", "--verbose", dest="verbose", action="count", default=0, help="Print more output. You can specify this option multiple times.")
|
||||
parser.add_option("--skip-js", dest="skipjs", action="store_true", help="Don't output marker.js or regions.js")
|
||||
@@ -242,7 +244,7 @@ def main():
|
||||
qtree.go(options.procs)
|
||||
|
||||
# create the distributed render
|
||||
r = rendernode.RenderNode(q)
|
||||
r = rendernode.RenderNode(q, options)
|
||||
|
||||
# write out the map and web assets
|
||||
m = googlemap.MapGen(q, configInfo=options)
|
||||
|
||||
@@ -65,7 +65,7 @@ def pool_initializer(rendernode):
|
||||
|
||||
# make sure textures are generated for this process
|
||||
# and initialize c_overviewer
|
||||
textures.generate()
|
||||
textures.generate(path=rendernode.options.get('textures_path', None))
|
||||
c_overviewer.init_chunk_render()
|
||||
|
||||
# load biome data in each process, if needed
|
||||
@@ -94,12 +94,13 @@ def roundrobin(iterables):
|
||||
|
||||
|
||||
class RenderNode(object):
|
||||
def __init__(self, quadtrees):
|
||||
def __init__(self, quadtrees, options):
|
||||
"""Distributes the rendering of a list of quadtrees."""
|
||||
|
||||
if not len(quadtrees) > 0:
|
||||
raise ValueError("there must be at least one quadtree to work on")
|
||||
|
||||
self.options = options
|
||||
self.quadtrees = quadtrees
|
||||
#bind an index value to the quadtree so we can find it again
|
||||
#and figure out which worlds are where
|
||||
|
||||
29
textures.py
29
textures.py
@@ -26,11 +26,14 @@ from PIL import Image, ImageEnhance, ImageOps, ImageDraw
|
||||
import util
|
||||
import composite
|
||||
|
||||
_find_file_local_path = None
|
||||
def _find_file(filename, mode="rb"):
|
||||
"""Searches for the given file and returns an open handle to it.
|
||||
This searches the following locations in this order:
|
||||
|
||||
* the textures_path given in the config file (if present)
|
||||
* The program dir (same dir as this file)
|
||||
* The program dir / textures
|
||||
* On Darwin, in /Applications/Minecraft
|
||||
* Inside minecraft.jar, which is looked for at these locations
|
||||
|
||||
@@ -38,14 +41,21 @@ def _find_file(filename, mode="rb"):
|
||||
* On Darwin, at $HOME/Library/Application Support/minecraft/bin/minecraft.jar
|
||||
* at $HOME/.minecraft/bin/minecraft.jar
|
||||
|
||||
* The current working directory
|
||||
* The program dir / textures
|
||||
|
||||
"""
|
||||
|
||||
if _find_file_local_path:
|
||||
path = os.path.join(_find_file_local_path, filename)
|
||||
if os.path.exists(path):
|
||||
return open(path, mode)
|
||||
|
||||
programdir = util.get_program_path()
|
||||
path = os.path.join(programdir, filename)
|
||||
if os.path.exists(path):
|
||||
return open(path, mode)
|
||||
|
||||
path = os.path.join(programdir, "textures", filename)
|
||||
if os.path.exists(path):
|
||||
return open(path, mode)
|
||||
|
||||
if sys.platform == "darwin":
|
||||
path = os.path.join("/Applications/Minecraft", filename)
|
||||
@@ -73,14 +83,6 @@ def _find_file(filename, mode="rb"):
|
||||
except (KeyError, IOError):
|
||||
pass
|
||||
|
||||
path = filename
|
||||
if os.path.exists(path):
|
||||
return open(path, mode)
|
||||
|
||||
path = os.path.join(programdir, "textures", filename)
|
||||
if os.path.exists(path):
|
||||
return open(path, mode)
|
||||
|
||||
raise IOError("Could not find the file {0}. Is Minecraft installed? If so, I couldn't find the minecraft.jar file.".format(filename))
|
||||
|
||||
def _load_image(filename):
|
||||
@@ -1661,7 +1663,10 @@ biome_grass_texture = None
|
||||
biome_leaf_texture = None
|
||||
specialblockmap = None
|
||||
|
||||
def generate():
|
||||
def generate(path=None):
|
||||
global _find_file_local_path
|
||||
_find_file_local_path = path
|
||||
|
||||
# This maps terainids to 16x16 images
|
||||
global terrain_images
|
||||
terrain_images = _split_terrain(_get_terrain_image())
|
||||
|
||||
Reference in New Issue
Block a user