Stronger support for setting a background color
Works by setting "bg_color='#rrggbb'" in settings.py. Works for both png and jpg imgformats
This commit is contained in:
@@ -8,7 +8,7 @@
|
|||||||
//center: [0,0,0],
|
//center: [0,0,0],
|
||||||
center: {spawn_coords},
|
center: {spawn_coords},
|
||||||
cacheMinutes: 0, // Change this to have browsers automatically request new images every x minutes
|
cacheMinutes: 0, // Change this to have browsers automatically request new images every x minutes
|
||||||
bg_color: '#1A1A1A',
|
bg_color: '{bg_color}', // You can set this in settings.py
|
||||||
debug: false
|
debug: false
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,8 @@ import os.path
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
class OptionsResults(object):
|
class OptionsResults(object):
|
||||||
pass
|
def get(self, *args):
|
||||||
|
return self.__dict__.get(*args)
|
||||||
|
|
||||||
class ConfigOptionParser(object):
|
class ConfigOptionParser(object):
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
|
|||||||
12
googlemap.py
12
googlemap.py
@@ -59,14 +59,15 @@ def mirror_dir(src, dst, entities=None):
|
|||||||
# if this stills throws an error, let it propagate up
|
# if this stills throws an error, let it propagate up
|
||||||
|
|
||||||
class MapGen(object):
|
class MapGen(object):
|
||||||
def __init__(self, quadtrees, skipjs=False, web_assets_hook=None):
|
def __init__(self, quadtrees, configInfo):
|
||||||
"""Generates a Google Maps interface for the given list of
|
"""Generates a Google Maps interface for the given list of
|
||||||
quadtrees. All of the quadtrees must have the same destdir,
|
quadtrees. All of the quadtrees must have the same destdir,
|
||||||
image format, and world.
|
image format, and world.
|
||||||
Note:tiledir for each quadtree should be unique. By default the tiledir is determined by the rendermode"""
|
Note:tiledir for each quadtree should be unique. By default the tiledir is determined by the rendermode"""
|
||||||
|
|
||||||
self.skipjs = skipjs
|
self.skipjs = configInfo.get('skipjs', None)
|
||||||
self.web_assets_hook = web_assets_hook
|
self.web_assets_hook = configInfo.get('web_assets_hook', None)
|
||||||
|
self.bg_color = configInfo.get('bg_color')
|
||||||
|
|
||||||
if not len(quadtrees) > 0:
|
if not len(quadtrees) > 0:
|
||||||
raise ValueError("there must be at least one quadtree to work on")
|
raise ValueError("there must be at least one quadtree to work on")
|
||||||
@@ -96,6 +97,8 @@ class MapGen(object):
|
|||||||
|
|
||||||
config = config.replace("{spawn_coords}",
|
config = config.replace("{spawn_coords}",
|
||||||
json.dumps(list(self.world.spawn)))
|
json.dumps(list(self.world.spawn)))
|
||||||
|
|
||||||
|
config = config.replace("{bg_color}", self.bg_color)
|
||||||
|
|
||||||
# create generated map type data, from given quadtrees
|
# create generated map type data, from given quadtrees
|
||||||
maptypedata = map(lambda q: {'label' : q.rendermode.capitalize(),
|
maptypedata = map(lambda q: {'label' : q.rendermode.capitalize(),
|
||||||
@@ -105,9 +108,10 @@ class MapGen(object):
|
|||||||
with open(os.path.join(self.destdir, "config.js"), 'w') as output:
|
with open(os.path.join(self.destdir, "config.js"), 'w') as output:
|
||||||
output.write(config)
|
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
|
# Write a blank image
|
||||||
for quadtree in self.quadtrees:
|
for quadtree in self.quadtrees:
|
||||||
blank = Image.new("RGBA", (1,1))
|
|
||||||
tileDir = os.path.join(self.destdir, quadtree.tiledir)
|
tileDir = os.path.join(self.destdir, quadtree.tiledir)
|
||||||
if not os.path.exists(tileDir): os.mkdir(tileDir)
|
if not os.path.exists(tileDir): os.mkdir(tileDir)
|
||||||
blank.save(os.path.join(tileDir, "blank."+self.imgformat))
|
blank.save(os.path.join(tileDir, "blank."+self.imgformat))
|
||||||
|
|||||||
@@ -97,6 +97,7 @@ def main():
|
|||||||
parser.add_option("--rendermodes", dest="rendermode", help="Specifies the render types, separated by commas. Use --list-rendermodes to list them all.", type="choice", choices=avail_rendermodes, required=True, default=avail_rendermodes[0], listify=True)
|
parser.add_option("--rendermodes", dest="rendermode", help="Specifies the render types, separated by commas. Use --list-rendermodes to list them all.", type="choice", choices=avail_rendermodes, required=True, default=avail_rendermodes[0], listify=True)
|
||||||
parser.add_option("--list-rendermodes", dest="list_rendermodes", action="store_true", help="List available render modes and exit.", commandLineOnly=True)
|
parser.add_option("--list-rendermodes", dest="list_rendermodes", action="store_true", help="List available render modes and exit.", commandLineOnly=True)
|
||||||
parser.add_option("--imgformat", dest="imgformat", help="The image output format to use. Currently supported: png(default), jpg. NOTE: png will always be used as the intermediate image format.", configFileOnly=True )
|
parser.add_option("--imgformat", dest="imgformat", help="The image output format to use. Currently supported: png(default), jpg. NOTE: png will always be used as the intermediate image format.", configFileOnly=True )
|
||||||
|
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("--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-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("-q", "--quiet", dest="quiet", action="count", default=0, help="Print less output. You can specify this option multiple times.")
|
parser.add_option("-q", "--quiet", dest="quiet", action="count", default=0, help="Print less output. You can specify this option multiple times.")
|
||||||
@@ -214,10 +215,12 @@ def main():
|
|||||||
|
|
||||||
logging.info("Rending the following tilesets: %s", ",".join(options.rendermode))
|
logging.info("Rending the following tilesets: %s", ",".join(options.rendermode))
|
||||||
|
|
||||||
|
bgcolor = (int(options.bg_color[1:3],16), int(options.bg_color[3:5],16), int(options.bg_color[5:7],16), 0)
|
||||||
|
|
||||||
# create the quadtrees
|
# create the quadtrees
|
||||||
# TODO chunklist
|
# TODO chunklist
|
||||||
q = []
|
q = []
|
||||||
qtree_args = {'depth' : options.zoom, 'imgformat' : imgformat, 'optimizeimg' : optimizeimg}
|
qtree_args = {'depth' : options.zoom, 'imgformat' : imgformat, 'optimizeimg' : optimizeimg, 'bgcolor':bgcolor}
|
||||||
for rendermode in options.rendermode:
|
for rendermode in options.rendermode:
|
||||||
if rendermode == 'normal':
|
if rendermode == 'normal':
|
||||||
qtree = quadtree.QuadtreeGen(w, destdir, rendermode=rendermode, tiledir='tiles', **qtree_args)
|
qtree = quadtree.QuadtreeGen(w, destdir, rendermode=rendermode, tiledir='tiles', **qtree_args)
|
||||||
@@ -229,7 +232,7 @@ def main():
|
|||||||
r = rendernode.RenderNode(q)
|
r = rendernode.RenderNode(q)
|
||||||
|
|
||||||
# write out the map and web assets
|
# write out the map and web assets
|
||||||
m = googlemap.MapGen(q, skipjs=options.skipjs, web_assets_hook=options.web_assets_hook)
|
m = googlemap.MapGen(q, configInfo=options)
|
||||||
m.go(options.procs)
|
m.go(options.procs)
|
||||||
|
|
||||||
# render the tiles!
|
# render the tiles!
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ def iterate_base4(d):
|
|||||||
return itertools.product(xrange(4), repeat=d)
|
return itertools.product(xrange(4), repeat=d)
|
||||||
|
|
||||||
class QuadtreeGen(object):
|
class QuadtreeGen(object):
|
||||||
def __init__(self, worldobj, destdir, depth=None, tiledir=None, imgformat=None, optimizeimg=None, rendermode="normal"):
|
def __init__(self, worldobj, destdir, bgcolor, depth=None, tiledir=None, imgformat=None, optimizeimg=None, rendermode="normal"):
|
||||||
"""Generates a quadtree from the world given into the
|
"""Generates a quadtree from the world given into the
|
||||||
given dest directory
|
given dest directory
|
||||||
|
|
||||||
@@ -61,6 +61,7 @@ class QuadtreeGen(object):
|
|||||||
assert(imgformat)
|
assert(imgformat)
|
||||||
self.imgformat = imgformat
|
self.imgformat = imgformat
|
||||||
self.optimizeimg = optimizeimg
|
self.optimizeimg = optimizeimg
|
||||||
|
self.bgcolor = bgcolor
|
||||||
|
|
||||||
self.lighting = rendermode in ("lighting", "night", "spawn")
|
self.lighting = rendermode in ("lighting", "night", "spawn")
|
||||||
self.night = rendermode in ("night", "spawn")
|
self.night = rendermode in ("night", "spawn")
|
||||||
@@ -320,7 +321,7 @@ class QuadtreeGen(object):
|
|||||||
#logging.debug("writing out innertile {0}".format(imgpath))
|
#logging.debug("writing out innertile {0}".format(imgpath))
|
||||||
|
|
||||||
# Create the actual image now
|
# Create the actual image now
|
||||||
img = Image.new("RGBA", (384, 384), (38,92,255,0))
|
img = Image.new("RGBA", (384, 384), self.bgcolor)
|
||||||
|
|
||||||
# we'll use paste (NOT alpha_over) for quadtree generation because
|
# we'll use paste (NOT alpha_over) for quadtree generation because
|
||||||
# this is just straight image stitching, not alpha blending
|
# this is just straight image stitching, not alpha blending
|
||||||
@@ -442,7 +443,7 @@ class QuadtreeGen(object):
|
|||||||
#logging.debug("writing out worldtile {0}".format(imgpath))
|
#logging.debug("writing out worldtile {0}".format(imgpath))
|
||||||
|
|
||||||
# Compile this image
|
# Compile this image
|
||||||
tileimg = Image.new("RGBA", (width, height), (38,92,255,0))
|
tileimg = Image.new("RGBA", (width, height), self.bgcolor)
|
||||||
|
|
||||||
world = self.world
|
world = self.world
|
||||||
rendermode = self.rendermode
|
rendermode = self.rendermode
|
||||||
|
|||||||
Reference in New Issue
Block a user