Added the ability to specify one portal in a scene as the "default

entrance."  The default entrance is specially highlighted in the scene
and can be read from and written to XML scene description files.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@558 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Walter Korman
2001-10-25 16:36:43 +00:00
parent 63a822862d
commit 4b58a696ca
6 changed files with 139 additions and 60 deletions
@@ -1,5 +1,5 @@
//
// $Id: XMLSceneParser.java,v 1.22 2001/10/22 18:21:41 shaper Exp $
// $Id: XMLSceneParser.java,v 1.23 2001/10/25 16:36:43 shaper Exp $
package com.threerings.miso.scene.xml;
@@ -74,6 +74,9 @@ public class XMLSceneParser extends SimpleParser
String vals[] = StringUtil.parseStringArray(data);
addPortals(_info.scene.portals, _info.scene.locations, vals);
} else if (qName.equals("entrance")) {
_info.scene.entrance = getEntrancePortal(data);
} else if (qName.equals("row")) {
addTileRow(_info, data);
@@ -244,6 +247,23 @@ public class XMLSceneParser extends SimpleParser
}
}
/**
* Returns the default entrance portal for the scene, or
* <code>null</code> if an error occurs.
*/
protected Portal getEntrancePortal (String data)
{
ArrayList locs = _info.scene.locations;
int size = locs.size();
int pidx = parseInt(data);
if (size == 0 || pidx < 0 || pidx > size - 1) {
return null;
}
return (Portal)locs.get(pidx);
}
/**
* Parse the specified XML file and return a miso scene object with
* the data contained therein.
@@ -271,9 +291,6 @@ public class XMLSceneParser extends SimpleParser
/** Temporary storage of scene info while parsing. */
protected SceneInfo _info;
// TODO: allow specifying the entrance location for a scene in the
// editor, read/write to XML scene description files.
/**
* A class to hold the information gathered while parsing.
*/
@@ -1,5 +1,5 @@
//
// $Id: XMLSceneWriter.java,v 1.17 2001/10/22 18:21:42 shaper Exp $
// $Id: XMLSceneWriter.java,v 1.18 2001/10/25 16:36:43 shaper Exp $
package com.threerings.miso.scene.xml;
@@ -62,6 +62,8 @@ public class XMLSceneWriter extends DataWriter
dataElement("portals", getPortalData(scene));
dataElement("entrance", getEntranceData(scene));
startElement("tiles");
for (int lnum = 0; lnum < MisoScene.NUM_LAYERS; lnum++) {
writeLayer(scene, lnum);
@@ -189,6 +191,23 @@ public class XMLSceneWriter extends DataWriter
return buf.toString();
}
/**
* Returns a string detailing the location index of the default
* entrance portal for the scene, or <code>"-1"</code> if no
* default portal is specified or an error occurs.
*/
protected String getEntranceData (MisoScene scene)
{
List locs = scene.getLocations();
Portal entrance = scene.getEntrance();
if (locs.size() == 0 || entrance == null) {
return "-1";
}
return String.valueOf(locs.indexOf(entrance));
}
/**
* Return a string representation of the tiles at the specified
* row and layer in the given scene. Only <code>len</code> tiles