added a public isLevel method that can be called on a subclass of MCLevel that has one of the appropriate methods.

For example, MCInfdevOldLevel.isLevel("World4") will return True if World4 can be loaded using MCInfdevOldLevel("World4")
This commit is contained in:
David Vierra 2010-10-23 17:25:38 -10:00
parent 1869415a4e
commit ead880dcc3

View File

@ -321,10 +321,35 @@ class MCLevel(object):
Width = None
players = ["Player"]
@classmethod
def getWorldBounds(self):
return BoundingBox( (0,0,0), self.getSize() )
def isLevel(cls, filename):
"""Tries to find out whether the given filename can be loaded
by this class. Returns True or False.
Subclasses should implement _isLevel, _isDataLevel, or _isTagLevel.
"""
if hasattr(cls, "_isLevel"):
return cls._isLevel(filename);
with file(filename) as f:
data = f.read();
if hasattr(cls, "_isDataLevel"):
return cls._isDataLevel(data);
if hasattr(cls, "_isTagLevel"):
try:
root_tag = nbt.load(filename, data)
except:
return False;
return cls._isTagLevel(root_tag);
return False
def getSize(self):
return (self.Width, self.Height, self.Length)
size = property(getSize, None, None, "Returns the level's dimensions as a tuple (X,Y,Z)")