|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object wyvern.kernel.properties.PList wyvern.kernel.maps.MapLoader
This class can read a GameMap implementation from an XML file.
Field Summary | |
protected boolean |
editor_
Set in loadMap from the 'editor' parameter. |
protected java.lang.String |
filename_
|
protected GameMap |
map_
|
protected int |
monsterCount_
Keep track of how many monsters or generators we've loaded. |
protected int |
objectCount_
|
protected static org.python.util.PythonInterpreter |
python_
|
protected boolean |
throwExceptions_
|
Fields inherited from class wyvern.kernel.properties.PList |
readOnly_ |
Fields inherited from interface wyvern.lib.PropertyList |
PROPERTY_PACKAGE |
Constructor Summary | |
MapLoader()
|
Method Summary | |
protected GameMap |
createMap(org.w3c.dom.Element root)
Creates and begins initialization of the map, from the file. |
boolean |
inMapEditor()
Returns true if we've been told we're loading the map inside the Map Editor. |
protected GameObject |
instantiateArchetype(Archetype arch)
Takes an Archetype that we parsed, turns it into a GameObject inheriting from the archetype, and copies certain properties from the Archetype to the object. |
protected GameMap |
instantiateMap(java.lang.String classname,
Dimension size)
Instantiates the map class, if possible. |
GameMap |
instantiatePyMap(java.lang.String filename,
Dimension size)
Instantiates a map with a python class in the header. |
protected Terrain |
instantiateTerrain(Archetype arch)
Instantiates a Terrain object, possibly returning a flyweight version from the global Terrain cache. |
GameMap |
loadMap(java.lang.String filename)
Reads a map from a Wyvern XML map file. |
protected GameMap |
loadPythonMap(java.lang.String filename)
Loads a map defined in a python file. |
protected void |
parseLocalArchetype(org.w3c.dom.Element node)
Parses and initializes a map-local archetype definition. |
protected Dimension |
parseMapSize(org.w3c.dom.Element header)
Gets width & height attributes, if any, as integers. |
protected GameObject |
parseObject(org.w3c.dom.Element node)
Parses an object definition, either inline or as an archetype reference, and returns an initialized object. |
protected java.lang.Object |
readLocation(java.lang.String line)
Reads a location descriptor - a point, rectangle or perhaps eventually some other shape or list of points. |
protected void |
readObject(GameMap map,
org.w3c.dom.Element node,
java.lang.String loc)
Reads a single object definition from the map. |
protected void |
readObjects(GameMap map,
org.w3c.dom.Element root)
Reads the object definitions and builds the map. |
protected void |
setDefaultTerrain(GameMap map)
Transfers the "terrain" property into instance data. |
void |
setMapEditor(boolean editor)
Sets whether the map is being loaded within the Map Editor |
protected void |
setMapPath(GameMap map,
java.lang.String filename)
Sets the path for the map. |
protected void |
setObject(GameObject m,
GameMap map,
int x,
int y)
Places an object in the map. |
void |
throwExceptions(boolean exceptions)
Turns exception-throwing on or off. |
boolean |
throwingExceptions()
Returns true if this GameMapLoader is configured to throw exceptions when it encounters errors loading a map. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
protected boolean editor_
protected java.lang.String filename_
protected GameMap map_
protected int objectCount_
protected boolean throwExceptions_
protected int monsterCount_
protected static org.python.util.PythonInterpreter python_
Constructor Detail |
public MapLoader()
Method Detail |
public void throwExceptions(boolean exceptions)
GameMapLoader
Note: if the map header in the .map file has an "errors-ok" boolean property, it will continue without throwing any exceptions if it fails to load a particular archetype in the map. "errors-ok" maps will only throw exceptions if the map was fundamentally not loadable, e.g. if the map class couldn't be loaded, or the map's XML is corrupted.
throwExceptions
in interface GameMapLoader
public boolean throwingExceptions()
GameMapLoader
throwingExceptions
in interface GameMapLoader
public void setMapEditor(boolean editor)
GameMapLoader
setMapEditor
in interface GameMapLoader
editor
- true if being loaded into Map Editor, false if
being loaded into an actual game session. If true, sets the
transient property "@mapedit" on the loaded maps.public boolean inMapEditor()
GameMapLoader
inMapEditor
in interface GameMapLoader
public GameMap loadMap(java.lang.String filename) throws java.lang.Exception
GameMapLoader
loadMap
in interface GameMapLoader
filename
- the full path to the file. If it ends with
".py", it'll be instantiated as a python map.
java.lang.Exception
protected GameMap loadPythonMap(java.lang.String filename) throws java.lang.Exception
filename
- the full path to the python file
java.lang.Exception
protected void setMapPath(GameMap map, java.lang.String filename)
map
- the mapfilename
- the absolute path to the file.protected GameMap createMap(org.w3c.dom.Element root) throws java.lang.Exception
root
- the "map" element of the XML mapfile
java.lang.Exception
protected GameMap instantiateMap(java.lang.String classname, Dimension size) throws java.lang.Exception
classname
- the GameMap implementation classsize
- the width & height (must be non-null)
java.lang.Exception
public GameMap instantiatePyMap(java.lang.String filename, Dimension size) throws java.lang.Exception
size
- the map dimensionsfilename
- the relative path to the mapfile, such
as "wiz/rhialto/maps/python_map.py"
java.lang.Exception
protected Dimension parseMapSize(org.w3c.dom.Element header) throws java.lang.Exception
java.lang.Exception
protected void setDefaultTerrain(GameMap map) throws java.lang.Exception
java.lang.Exception
protected void readObjects(GameMap map, org.w3c.dom.Element root) throws java.lang.Exception
map
- the map to buildroot
- the protected void readObject(GameMap map, org.w3c.dom.Element node, java.lang.String loc) throws java.lang.Exception
This method also places the object in the map.
map
- the GameMap to add the object tonode
- the DOM Element containing the object to addloc
- the location at which to put the object, e.g.
"2 14" or "3 3 10 10".
java.lang.Exception
protected java.lang.Object readLocation(java.lang.String line) throws java.lang.Exception
line
- the line containing the location descriptor
java.lang.NumberFormatException
- (or other exception) if the
line is malformed
java.lang.Exception
protected GameObject parseObject(org.w3c.dom.Element node) throws java.lang.Exception
node
- the DOM Element containing the object to add
java.lang.Exception
protected GameObject instantiateArchetype(Archetype arch) throws java.lang.Exception
arch
- the Archetype to instantiate
java.lang.Exception
protected Terrain instantiateTerrain(Archetype arch) throws java.lang.Exception
arch
- an archetype of class Terrain
java.lang.Exception
protected void setObject(GameObject m, GameMap map, int x, int y) throws java.lang.Exception
map
- the map to put it inm
- the object to place. If it's a Monster, and we're
starting monsters, it starts it.x
- the x location to place it aty
- the y location to place it at
java.lang.Exception
protected void parseLocalArchetype(org.w3c.dom.Element node) throws java.lang.Exception
node
- the DOM element representing the local archetype
java.lang.Exception
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |