More work on editor support for location creation and editing.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@209 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Walter Korman
2001-08-10 00:47:34 +00:00
parent 593d17aeb5
commit 9df1deef66
8 changed files with 373 additions and 44 deletions
@@ -1,5 +1,5 @@
//
// $Id: XMLSceneParser.java,v 1.6 2001/08/09 21:17:06 shaper Exp $
// $Id: XMLSceneParser.java,v 1.7 2001/08/10 00:47:34 shaper Exp $
package com.threerings.miso.scene.xml;
@@ -70,6 +70,10 @@ public class XMLSceneParser extends DefaultHandler
int vals[] = StringUtil.parseIntArray(_chars.toString());
_scLocations = toLocationsList(vals);
} else if (qName.equals("spot")) {
int vals[] = StringUtil.parseIntArray(_chars.toString());
_scSpots.add(toSpot(_scLocations, vals));
} else if (qName.equals("exits")) {
String vals[] = StringUtil.parseStringArray(_chars.toString());
_scExits = toExitList(_scLocations, vals);
@@ -84,7 +88,7 @@ public class XMLSceneParser extends DefaultHandler
} else if (qName.equals("scene")) {
// construct the scene object on tag close
_scene = new Scene(
_tilemgr, _scName, _scLocations, _scExits, _scTiles);
_tilemgr, _scName, _scLocations, _scSpots, _scExits, _scTiles);
Log.info("Constructed parsed scene [scene=" + _scene + "].");
}
@@ -163,11 +167,30 @@ public class XMLSceneParser extends DefaultHandler
}
}
/**
* Given an array of integer values, return a <code>Spot</code>
* object containing the location objects identified by location
* index number in the integer array.
*
* @param locs the locations list.
* @param vals the integer values.
*
* @return the spot object.
*/
protected Spot toSpot (ArrayList locs, int[] vals)
{
Spot spot = new Spot();
for (int ii = 0; ii < vals.length; ii++) {
spot.add((Location)locs.get(vals[ii]));
}
return spot;
}
/**
* Given an array of integer values, return a list of the
* <code>Location</code> objects represented therein, constructed
* from each successive quartet of values as (spotid, x, y,
* orientation) in the integer array.
* from each successive triplet of values as (x, y, orientation)
* in the integer array.
*
* @param vals the integer values.
*
@@ -176,13 +199,13 @@ public class XMLSceneParser extends DefaultHandler
protected ArrayList toLocationsList (int[] vals)
{
// make sure we have a seemingly-appropriate number of points
if ((vals.length % 4) != 0) return null;
if ((vals.length % 3) != 0) return null;
// read in all of the locations and add to the list
ArrayList list = new ArrayList();
for (int ii = 0; ii < vals.length; ii += 4) {
for (int ii = 0; ii < vals.length; ii += 3) {
Location loc = new Location(
vals[ii], vals[ii+1], vals[ii+2], vals[ii+3]);
vals[ii], vals[ii+1], vals[ii+2]);
list.add(loc);
}
@@ -245,6 +268,7 @@ public class XMLSceneParser extends DefaultHandler
_scTiles = new Tile[width][height][Scene.NUM_LAYERS];
_scLocations = null;
_scExits = null;
_scSpots = new ArrayList();
}
/**
@@ -296,8 +320,7 @@ public class XMLSceneParser extends DefaultHandler
// temporary storage of scene object values and data
protected StringBuffer _chars;
protected String _scName;
protected ArrayList _scLocations;
protected ArrayList _scExits;
protected ArrayList _scLocations, _scExits, _scSpots;
protected Tile[][][] _scTiles;
protected int _scLnum, _scRownum, _scColstart;
}
@@ -1,5 +1,5 @@
//
// $Id: XMLSceneWriter.java,v 1.4 2001/08/09 21:17:06 shaper Exp $
// $Id: XMLSceneWriter.java,v 1.5 2001/08/10 00:47:34 shaper Exp $
package com.threerings.miso.scene.xml;
@@ -52,6 +52,11 @@ public class XMLSceneWriter extends DataWriter
dataElement("name", scene.getName());
dataElement("version", "" + Scene.VERSION);
dataElement("locations", getLocationData(scene));
startElement("spots");
writeSpots(scene);
endElement("spots");
dataElement("exits", getExitData(scene));
startElement("tiles");
@@ -70,6 +75,36 @@ public class XMLSceneWriter extends DataWriter
}
}
/**
* Output XML detailing the spot objects. Spots are described by
* a list of location object indexes that are contained within the
* spot.
*
* @param scene the scene object.
*/
protected void writeSpots (Scene scene) throws SAXException
{
ArrayList spots = scene.getSpotGroup().getSpots();
ArrayList locs = scene.getLocations();
int size = spots.size();
for (int ii = 0; ii < size; ii++) {
StringBuffer buf = new StringBuffer();
Spot spot = (Spot)spots.get(ii);
ArrayList spotlocs = spot.getLocations();
int spotsize = spotlocs.size();
for (int jj = 0; jj < spotsize; jj++) {
buf.append(locs.indexOf(spotlocs.get(jj))).append(",");
if (jj < spotsize - 1) buf.append(",");
}
dataElement("spot", buf.toString());
}
}
/**
* Output XML detailing the tiles at the specified layer in the
* given scene. The first layer is outputted in its entirety,
@@ -137,7 +172,6 @@ public class XMLSceneWriter extends DataWriter
int size = locs.size();
for (int ii = 0; ii < size; ii++) {
Location loc = (Location)locs.get(ii);
buf.append(loc.spotid).append(",");
buf.append(loc.x).append(",");
buf.append(loc.y).append(",");
buf.append(loc.orient);