Merge pull request #862
This commit is contained in:
@@ -400,9 +400,9 @@ dir but you forgot to put quotes around the directory, since it contains spaces.
|
||||
else:
|
||||
tex = texcache[texopts_key]
|
||||
|
||||
rset = w.get_regionset(render['dimension'])
|
||||
rset = w.get_regionset(render['dimension'][1])
|
||||
if rset == None: # indicates no such dimension was found:
|
||||
logging.error("Sorry, you requested dimension '%s' for %s, but I couldn't find it", render['dimension'], render_name)
|
||||
logging.error("Sorry, you requested dimension '%s' for %s, but I couldn't find it", render['dimension'][0], render_name)
|
||||
return 1
|
||||
|
||||
#################
|
||||
|
||||
@@ -57,10 +57,9 @@ def handlePlayers(rset, render, worldpath):
|
||||
# only handle this region set once
|
||||
if 'Players' in rset._pois:
|
||||
return
|
||||
dimension = {'overworld': 0,
|
||||
'nether': -1,
|
||||
'end': 1,
|
||||
'default': 0}[render['dimension']]
|
||||
dimension = {None: 0,
|
||||
'DIM-1': -1,
|
||||
'DIM1': 1}[rset.get_type()]
|
||||
playerdir = os.path.join(worldpath, "players")
|
||||
if os.path.isdir(playerdir):
|
||||
playerfiles = os.listdir(playerdir)
|
||||
@@ -165,9 +164,9 @@ def main():
|
||||
else:
|
||||
w = worldcache[render['world']]
|
||||
|
||||
rset = w.get_regionset(render['dimension'])
|
||||
rset = w.get_regionset(render['dimension'][1])
|
||||
if rset == None: # indicates no such dimension was found:
|
||||
logging.error("Sorry, you requested dimension '%s' for %s, but I couldn't find it", render['dimension'], render_name)
|
||||
logging.error("Sorry, you requested dimension '%s' for %s, but I couldn't find it", render['dimension'][0], render_name)
|
||||
return 1
|
||||
|
||||
for f in render['markers']:
|
||||
|
||||
@@ -182,9 +182,20 @@ def validateStr(s):
|
||||
return str(s)
|
||||
|
||||
def validateDimension(d):
|
||||
if d in ["nether", "overworld", "end", "default"]:
|
||||
return d
|
||||
raise ValidationException("%r is not a valid dimension" % d)
|
||||
# returns (original, argument to get_type)
|
||||
|
||||
# these are provided as arguments to RegionSet.get_type()
|
||||
pretty_names = {
|
||||
"nether": "DIM-1",
|
||||
"overworld": None,
|
||||
"end": "DIM1",
|
||||
"default": 0,
|
||||
}
|
||||
|
||||
try:
|
||||
return (d, pretty_names[d])
|
||||
except KeyError:
|
||||
return (d, d)
|
||||
|
||||
def validateOutputDir(d):
|
||||
_, d = checkBadEscape(d)
|
||||
|
||||
@@ -524,7 +524,7 @@ class TileSet(object):
|
||||
base = self.options.get('base'),
|
||||
bgcolor = bgcolorformat(self.options.get('bgcolor')),
|
||||
world = self.options.get('worldname_orig') +
|
||||
(" - " + self.options.get('dimension') if self.options.get('dimension') != 'default' else ''),
|
||||
(" - " + self.options.get('dimension')[0] if self.options.get('dimension')[1] != 0 else ''),
|
||||
last_rendertime = self.max_chunk_mtime,
|
||||
imgextension = self.imgextension,
|
||||
isOverlay = isOverlay,
|
||||
|
||||
@@ -121,8 +121,8 @@ class World(object):
|
||||
mcas = [x for x in files if x.endswith(".mca")]
|
||||
if mcas:
|
||||
# construct a regionset object for this
|
||||
rset = RegionSet(root)
|
||||
if not rset.is_valid(): continue
|
||||
rel = os.path.relpath(root, self.worlddir)
|
||||
rset = RegionSet(root, rel)
|
||||
if root == os.path.join(self.worlddir, "region"):
|
||||
self.regionsets.insert(0, rset)
|
||||
else:
|
||||
@@ -151,15 +151,12 @@ class World(object):
|
||||
def get_regionset(self, index):
|
||||
if type(index) == int:
|
||||
return self.regionsets[index]
|
||||
else: # assume a string constant
|
||||
if index == "default":
|
||||
return self.regionsets[0]
|
||||
else: # assume a get_type() value
|
||||
candids = [x for x in self.regionsets if x.get_type() == index]
|
||||
if len(candids) > 0:
|
||||
return candids[0]
|
||||
else:
|
||||
candids = [x for x in self.regionsets if x.get_type() == index]
|
||||
if len(candids) > 0:
|
||||
return candids[0]
|
||||
else:
|
||||
return None
|
||||
return None
|
||||
|
||||
|
||||
def get_level_dat_data(self):
|
||||
@@ -236,17 +233,28 @@ class RegionSet(object):
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, regiondir):
|
||||
def __init__(self, regiondir, rel):
|
||||
"""Initialize a new RegionSet to access the region files in the given
|
||||
directory.
|
||||
|
||||
regiondir is a path to a directory containing region files.
|
||||
|
||||
rel is the relative path of this directory, with respect to the
|
||||
world directory.
|
||||
|
||||
cachesize, if specified, is the number of chunks to keep parsed and
|
||||
in-memory.
|
||||
|
||||
"""
|
||||
self.regiondir = os.path.normpath(regiondir)
|
||||
self.rel = os.path.normpath(rel)
|
||||
|
||||
# we want to get rid of /regions, if it exists
|
||||
if self.rel.endswith(os.path.normpath("/region")):
|
||||
self.type = self.rel[0:-len(os.path.normpath("/region"))]
|
||||
if self.rel == "region":
|
||||
# this is the main world
|
||||
self.type = None
|
||||
|
||||
logging.debug("Scanning regions")
|
||||
|
||||
@@ -265,34 +273,21 @@ class RegionSet(object):
|
||||
|
||||
# Re-initialize upon unpickling
|
||||
def __getstate__(self):
|
||||
return self.regiondir
|
||||
__setstate__ = __init__
|
||||
return (self.regiondir, self.rel)
|
||||
def __setstate__(self, state):
|
||||
return self.__init__(*state)
|
||||
|
||||
def __repr__(self):
|
||||
return "<RegionSet regiondir=%r>" % self.regiondir
|
||||
|
||||
def is_valid(self):
|
||||
"""If this region set isn't one of the three known regions, then
|
||||
return False"""
|
||||
try:
|
||||
self.get_type()
|
||||
return True
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
def get_type(self):
|
||||
"""Attempts to return a string describing the dimension represented by
|
||||
this regionset. Either "nether", "end" or "overworld"
|
||||
"""Attempts to return a string describing the dimension
|
||||
represented by this regionset. Usually this is the relative
|
||||
path of the regionset within the world, minus the suffix
|
||||
/region, but for the main world it's None.
|
||||
"""
|
||||
# path will be normalized in __init__
|
||||
if self.regiondir.endswith(os.path.normpath("/DIM-1/region")):
|
||||
return "nether"
|
||||
elif self.regiondir.endswith(os.path.normpath("/DIM1/region")):
|
||||
return "end"
|
||||
elif self.regiondir.endswith(os.path.normpath("/region")):
|
||||
return "overworld"
|
||||
else:
|
||||
raise Exception("Woah, what kind of dimension is this?! %r" % self.regiondir)
|
||||
return self.type
|
||||
|
||||
def _get_regionobj(self, regionfilename):
|
||||
# Check the cache first. If it's not there, create the
|
||||
|
||||
Reference in New Issue
Block a user