Added character manager and character descriptions. Allow tile sets
that have no specified layer. Made the scene editor gracefully handle the case where there are no valid tile sets for use with the selected scene layer. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@461 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: MisoSceneUtil.java,v 1.3 2001/10/11 00:41:27 shaper Exp $
|
||||
// $Id: MisoSceneUtil.java,v 1.4 2001/10/15 23:53:43 shaper Exp $
|
||||
|
||||
package com.threerings.miso.scene.util;
|
||||
|
||||
@@ -101,5 +101,5 @@ public class MisoSceneUtil
|
||||
}
|
||||
|
||||
/** The default layer index for an unknown named layer. */
|
||||
protected static final int DEF_LAYER = MisoScene.LAYER_BASE;
|
||||
protected static final int DEF_LAYER = -1;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
//
|
||||
// $Id: EditableTileSetManager.java,v 1.12 2001/10/12 16:38:59 shaper Exp $
|
||||
// $Id: EditableTileSetManager.java,v 1.13 2001/10/15 23:53:43 shaper Exp $
|
||||
|
||||
package com.threerings.miso.tile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.samskivert.util.Config;
|
||||
|
||||
@@ -28,12 +28,11 @@ public class EditableTileSetManager extends TileSetManagerImpl
|
||||
|
||||
// load the tilesets from the XML description file
|
||||
String fname = config.getValue(TILESETS_KEY, (String)null);
|
||||
List tilesets = null;
|
||||
ArrayList tilesets = new ArrayList();
|
||||
try {
|
||||
tilesets = new XMLMisoTileSetParser().loadTileSets(fname);
|
||||
new XMLMisoTileSetParser().loadTileSets(fname, tilesets);
|
||||
} catch (IOException ioe) {
|
||||
Log.warning("Exception loading tileset [fname=" + fname +
|
||||
", ioe=" + ioe + "].");
|
||||
Log.warning("Exception loading tile sets [ioe=" + ioe + "].");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: TileUtil.java,v 1.6 2001/10/11 00:41:27 shaper Exp $
|
||||
// $Id: TileUtil.java,v 1.7 2001/10/15 23:53:43 shaper Exp $
|
||||
|
||||
package com.threerings.miso.tile;
|
||||
|
||||
@@ -22,7 +22,7 @@ public class TileUtil
|
||||
* frames of animation used to render the ambulatory sprite in
|
||||
* each of the directions it may face. The tileset id referenced
|
||||
* must contain <code>Sprite.NUM_DIRECTIONS</code> rows of tiles,
|
||||
* with each row containing <code>NUM_DIR_FRAMES</code> tiles.
|
||||
* with each row containing <code>frameCount</code> tiles.
|
||||
*
|
||||
* @param tilemgr the tile manager to retrieve tiles from.
|
||||
* @param tsid the tileset id containing the sprite tiles.
|
||||
@@ -30,15 +30,17 @@ public class TileUtil
|
||||
* @return the array of multi-frame sprite images.
|
||||
*/
|
||||
public static MultiFrameImage[]
|
||||
getAmbulatorySpriteFrames (TileManager tilemgr, int tsid)
|
||||
getAmbulatorySpriteFrames (TileManager tilemgr, int tsid,
|
||||
int frameCount)
|
||||
{
|
||||
MultiFrameImage[] anims = new MultiFrameImage[Sprite.NUM_DIRECTIONS];
|
||||
|
||||
try {
|
||||
for (int ii = 0; ii < Sprite.NUM_DIRECTIONS; ii++) {
|
||||
Tile[] tiles = new Tile[NUM_DIR_FRAMES];
|
||||
for (int jj = 0; jj < NUM_DIR_FRAMES; jj++) {
|
||||
int idx = (ii * NUM_DIR_FRAMES) + jj;
|
||||
Tile[] tiles = new Tile[frameCount];
|
||||
|
||||
for (int jj = 0; jj < frameCount; jj++) {
|
||||
int idx = (ii * frameCount) + jj;
|
||||
tiles[jj] = tilemgr.getTile(tsid, idx);
|
||||
}
|
||||
|
||||
@@ -77,7 +79,4 @@ public class TileUtil
|
||||
|
||||
protected Tile[] _tiles;
|
||||
}
|
||||
|
||||
/** The number of frames of animation for each direction. */
|
||||
protected static final int NUM_DIR_FRAMES = 8;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: XMLMisoTileSetParser.java,v 1.3 2001/10/12 00:43:04 shaper Exp $
|
||||
// $Id: XMLMisoTileSetParser.java,v 1.4 2001/10/15 23:53:43 shaper Exp $
|
||||
|
||||
package com.threerings.miso.tile;
|
||||
|
||||
@@ -17,8 +17,8 @@ import com.threerings.miso.scene.util.MisoSceneUtil;
|
||||
public class XMLMisoTileSetParser extends XMLTileSetParser
|
||||
{
|
||||
// documentation inherited
|
||||
public void startElement (String uri, String localName,
|
||||
String qName, Attributes attributes)
|
||||
public void startElement (
|
||||
String uri, String localName, String qName, Attributes attributes)
|
||||
{
|
||||
super.startElement(uri, localName, qName, attributes);
|
||||
|
||||
@@ -29,12 +29,13 @@ public class XMLMisoTileSetParser extends XMLTileSetParser
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
protected void finishElement (String qName, String str)
|
||||
protected void finishElement (
|
||||
String uri, String localName, String qName, String data)
|
||||
{
|
||||
super.finishElement(qName, str);
|
||||
super.finishElement(uri, localName, qName, data);
|
||||
|
||||
if (qName.equals("passable")) {
|
||||
((MisoTileSetImpl)_tset).passable = StringUtil.parseIntArray(str);
|
||||
((MisoTileSetImpl)_tset).passable = StringUtil.parseIntArray(data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,45 +1,43 @@
|
||||
//
|
||||
// $Id: XMLSceneGroupParser.java,v 1.5 2001/09/28 01:31:32 mdb Exp $
|
||||
// $Id: XMLSceneGroupParser.java,v 1.6 2001/10/15 23:53:43 shaper Exp $
|
||||
|
||||
package com.threerings.miso.scene.xml;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
||||
import org.xml.sax.*;
|
||||
import org.xml.sax.helpers.DefaultHandler;
|
||||
|
||||
import com.samskivert.util.*;
|
||||
import com.samskivert.xml.XMLUtil;
|
||||
import com.samskivert.xml.SimpleParser;
|
||||
|
||||
import com.threerings.miso.Log;
|
||||
import com.threerings.miso.scene.*;
|
||||
import com.threerings.miso.scene.util.MisoSceneUtil;
|
||||
|
||||
import com.threerings.whirled.data.Scene;
|
||||
|
||||
/**
|
||||
* Parses an XML scene group description file, loads the referenced
|
||||
* scenes into the runtime scene repository, and creates bindings
|
||||
* between the portals in the scenes.
|
||||
*
|
||||
* <p> Does not currently perform validation on the input XML stream,
|
||||
* though the parsing code assumes the XML document is well-formed.
|
||||
* between the portals in the scenes. Does not currently perform
|
||||
* validation on the input XML stream, though the parsing code assumes
|
||||
* the XML document is well-formed.
|
||||
*/
|
||||
public class XMLSceneGroupParser extends DefaultHandler
|
||||
public class XMLSceneGroupParser extends SimpleParser
|
||||
{
|
||||
public void startElement (String uri, String localName,
|
||||
String qName, Attributes attributes)
|
||||
// documentation inherited
|
||||
public void startElement (
|
||||
String uri, String localName, String qName, Attributes attributes)
|
||||
{
|
||||
_tag = qName;
|
||||
|
||||
if (_tag.equals("scene")) {
|
||||
if (qName.equals("scene")) {
|
||||
// construct a new scene info object
|
||||
_info.curscene = new SceneInfo(attributes.getValue("src"));
|
||||
|
||||
// add it to the list of scene info objects
|
||||
_info.sceneinfo.add(_info.curscene);
|
||||
|
||||
} else if (_tag.equals("portal")) {
|
||||
} else if (qName.equals("portal")) {
|
||||
// pull out the portal data
|
||||
String src = attributes.getValue("src");
|
||||
String destScene = attributes.getValue("destScene");
|
||||
@@ -53,18 +51,15 @@ public class XMLSceneGroupParser extends DefaultHandler
|
||||
}
|
||||
}
|
||||
|
||||
public void endElement (String uri, String localName, String qName)
|
||||
// documentation inherited
|
||||
public void finishElement (
|
||||
String uri, String localName, String qName, String data)
|
||||
{
|
||||
// we know we've received the entirety of the character data
|
||||
// for the elements we're tracking at this point, so proceed
|
||||
// with saving off element data for later use.
|
||||
String str = _chars.toString();
|
||||
|
||||
if (qName.equals("name")) {
|
||||
_info.curscene.name = str;
|
||||
_info.curscene.name = data;
|
||||
|
||||
} else if (qName.equals("entrance")) {
|
||||
_info.curscene.entrance = str;
|
||||
_info.curscene.entrance = data;
|
||||
|
||||
} else if (qName.equals("scene")) {
|
||||
// TODO: load scene from scene repository and set
|
||||
@@ -79,21 +74,6 @@ public class XMLSceneGroupParser extends DefaultHandler
|
||||
// warn about any remaining un-bound portals
|
||||
_info.checkUnboundPortals();
|
||||
}
|
||||
|
||||
// note that we're not within a tag to avoid considering any
|
||||
// characters during this quiescent time
|
||||
_tag = null;
|
||||
|
||||
// and clear out the character data we're gathering
|
||||
_chars = new StringBuffer();
|
||||
}
|
||||
|
||||
public void characters (char ch[], int start, int length)
|
||||
{
|
||||
// bail if we're not within a meaningful tag
|
||||
if (_tag == null) return;
|
||||
|
||||
_chars.append(ch, start, length);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -107,40 +87,11 @@ public class XMLSceneGroupParser extends DefaultHandler
|
||||
*/
|
||||
public List loadSceneGroup (String fname) throws IOException
|
||||
{
|
||||
_fname = fname;
|
||||
|
||||
try {
|
||||
// get the file input stream
|
||||
FileInputStream fis = new FileInputStream(fname);
|
||||
BufferedInputStream bis = new BufferedInputStream(fis);
|
||||
|
||||
// prepare temporary data storage for parsing
|
||||
_chars = new StringBuffer();
|
||||
_info = new SceneGroupInfo();
|
||||
|
||||
// read the XML input stream and construct all scene objects
|
||||
XMLUtil.parse(this, bis);
|
||||
|
||||
// return the final list of scene objects
|
||||
return _info.getScenes();
|
||||
|
||||
} catch (ParserConfigurationException pce) {
|
||||
throw new IOException(pce.toString());
|
||||
|
||||
} catch (SAXException saxe) {
|
||||
throw new IOException(saxe.toString());
|
||||
}
|
||||
_info = new SceneGroupInfo();
|
||||
parseFile(fname);
|
||||
return _info.getScenes();
|
||||
}
|
||||
|
||||
/** The file currently being processed. */
|
||||
protected String _fname;
|
||||
|
||||
/** The XML element tag currently being processed. */
|
||||
protected String _tag;
|
||||
|
||||
/** Temporary storage of scene group values and data. */
|
||||
protected StringBuffer _chars;
|
||||
|
||||
/** The scene group info gathered while parsing. */
|
||||
protected SceneGroupInfo _info;
|
||||
|
||||
|
||||
@@ -1,18 +1,16 @@
|
||||
//
|
||||
// $Id: XMLSceneParser.java,v 1.19 2001/10/13 01:08:59 shaper Exp $
|
||||
// $Id: XMLSceneParser.java,v 1.20 2001/10/15 23:53:43 shaper Exp $
|
||||
|
||||
package com.threerings.miso.scene.xml;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
||||
import org.xml.sax.*;
|
||||
import org.xml.sax.helpers.DefaultHandler;
|
||||
|
||||
import com.samskivert.util.*;
|
||||
import com.samskivert.xml.XMLUtil;
|
||||
import com.samskivert.xml.SimpleParser;
|
||||
|
||||
import com.threerings.media.tile.*;
|
||||
|
||||
@@ -27,7 +25,7 @@ import com.threerings.miso.tile.MisoTile;
|
||||
*
|
||||
* @see XMLSceneWriter
|
||||
*/
|
||||
public class XMLSceneParser extends DefaultHandler
|
||||
public class XMLSceneParser extends SimpleParser
|
||||
{
|
||||
public XMLSceneParser (IsoSceneViewModel model, TileManager tilemgr)
|
||||
{
|
||||
@@ -35,32 +33,28 @@ public class XMLSceneParser extends DefaultHandler
|
||||
_tilemgr = tilemgr;
|
||||
}
|
||||
|
||||
public void startElement (String uri, String localName,
|
||||
String qName, Attributes attributes)
|
||||
// documentation inherited
|
||||
public void startElement (
|
||||
String uri, String localName, String qName, Attributes attributes)
|
||||
{
|
||||
_tag = qName;
|
||||
if (_tag.equals("layer")) {
|
||||
_info.lnum = getInt(attributes.getValue("lnum"));
|
||||
if (qName.equals("layer")) {
|
||||
_info.lnum = parseInt(attributes.getValue("lnum"));
|
||||
|
||||
} else if (_tag.equals("row")) {
|
||||
_info.rownum = getInt(attributes.getValue("rownum"));
|
||||
_info.colstart = getInt(attributes.getValue("colstart"));
|
||||
} else if (qName.equals("row")) {
|
||||
_info.rownum = parseInt(attributes.getValue("rownum"));
|
||||
_info.colstart = parseInt(attributes.getValue("colstart"));
|
||||
}
|
||||
}
|
||||
|
||||
public void endElement (String uri, String localName, String qName)
|
||||
// documentation inherited
|
||||
public void finishElement (
|
||||
String uri, String localName, String qName, String data)
|
||||
{
|
||||
// we know we've received the entirety of the character data
|
||||
// for the elements we're tracking at this point, so proceed
|
||||
// with saving off element values for use when we construct
|
||||
// the scene object.
|
||||
String str = _chars.toString().trim();
|
||||
|
||||
if (qName.equals("name")) {
|
||||
_info.scene.name = str;
|
||||
_info.scene.name = data;
|
||||
|
||||
} else if (qName.equals("version")) {
|
||||
int version = getInt(str);
|
||||
int version = parseInt(data);
|
||||
if (version < 0 || version > XMLSceneVersion.VERSION) {
|
||||
Log.warning(
|
||||
"Unrecognized scene file format version, will attempt " +
|
||||
@@ -70,40 +64,23 @@ public class XMLSceneParser extends DefaultHandler
|
||||
}
|
||||
|
||||
} else if (qName.equals("locations")) {
|
||||
int vals[] = StringUtil.parseIntArray(str);
|
||||
int vals[] = StringUtil.parseIntArray(data);
|
||||
addLocations(_info.scene.locations, vals);
|
||||
|
||||
} else if (qName.equals("cluster")) {
|
||||
int vals[] = StringUtil.parseIntArray(str);
|
||||
int vals[] = StringUtil.parseIntArray(data);
|
||||
_info.scene.clusters.add(toCluster(_info.scene.locations, vals));
|
||||
|
||||
} else if (qName.equals("portals")) {
|
||||
String vals[] = StringUtil.parseStringArray(str);
|
||||
String vals[] = StringUtil.parseStringArray(data);
|
||||
addPortals(_info.scene.portals, _info.scene.locations, vals);
|
||||
|
||||
} else if (qName.equals("row")) {
|
||||
addTileRow(_info, str);
|
||||
addTileRow(_info, data);
|
||||
|
||||
} else if (qName.equals("scene")) {
|
||||
// nothing for now
|
||||
}
|
||||
|
||||
// note that we're not within a tag to avoid considering any
|
||||
// characters during this quiescent time
|
||||
_tag = null;
|
||||
|
||||
// and clear out the character data we're gathering
|
||||
_chars = new StringBuffer();
|
||||
}
|
||||
|
||||
public void characters (char ch[], int start, int length)
|
||||
{
|
||||
// bail if we're not within a meaningful tag
|
||||
if (_tag == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
_chars.append(ch, start, length);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -257,7 +234,7 @@ public class XMLSceneParser extends DefaultHandler
|
||||
|
||||
// read in all of the portals
|
||||
for (int ii = 0; ii < vals.length; ii += 2) {
|
||||
int locidx = getInt(vals[ii]);
|
||||
int locidx = parseInt(vals[ii]);
|
||||
|
||||
// create the portal and add to the list
|
||||
Portal portal = new Portal((Location)locs.get(locidx), vals[ii+1]);
|
||||
@@ -268,26 +245,6 @@ public class XMLSceneParser extends DefaultHandler
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the given string as an integer and return the integer
|
||||
* value, or -1 if the string is malformed.
|
||||
*/
|
||||
protected int getInt (String str)
|
||||
{
|
||||
try {
|
||||
return (str == null) ? -1 : Integer.parseInt(str);
|
||||
} catch (NumberFormatException nfe) {
|
||||
Log.warning("Malformed integer value [str=" + str + "].");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
protected void init ()
|
||||
{
|
||||
_chars = new StringBuffer();
|
||||
_info = new SceneInfo();
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the specified XML file and return a miso scene object with
|
||||
* the data contained therein.
|
||||
@@ -298,48 +255,20 @@ public class XMLSceneParser extends DefaultHandler
|
||||
*/
|
||||
public EditableMisoScene loadScene (String fname) throws IOException
|
||||
{
|
||||
_fname = fname;
|
||||
|
||||
try {
|
||||
// get the file input stream
|
||||
FileInputStream fis = new FileInputStream(fname);
|
||||
BufferedInputStream bis = new BufferedInputStream(fis);
|
||||
|
||||
// prepare temporary data storage for parsing
|
||||
init();
|
||||
|
||||
// read the XML input stream and construct the scene object
|
||||
XMLUtil.parse(this, bis);
|
||||
|
||||
// place shadow tiles for any objects in the scene
|
||||
_info.scene.prepareAllObjectTiles();
|
||||
|
||||
// return the final scene object
|
||||
return _info.scene;
|
||||
|
||||
} catch (ParserConfigurationException pce) {
|
||||
throw new IOException(pce.toString());
|
||||
|
||||
} catch (SAXException saxe) {
|
||||
throw new IOException(saxe.toString());
|
||||
}
|
||||
_info = new SceneInfo();
|
||||
parseFile(fname);
|
||||
// place shadow tiles for any objects in the scene
|
||||
_info.scene.prepareAllObjectTiles();
|
||||
// return the final scene object
|
||||
return _info.scene;
|
||||
}
|
||||
|
||||
/** The file currently being processed. */
|
||||
protected String _fname;
|
||||
|
||||
/** The XML element tag currently being processed. */
|
||||
protected String _tag;
|
||||
|
||||
/** The iso scene view data model. */
|
||||
protected IsoSceneViewModel _model;
|
||||
|
||||
/** The tile manager object for use in constructing scenes. */
|
||||
protected TileManager _tilemgr;
|
||||
|
||||
/** Temporary storage of character data while parsing. */
|
||||
protected StringBuffer _chars;
|
||||
|
||||
/** Temporary storage of scene info while parsing. */
|
||||
protected SceneInfo _info;
|
||||
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
//
|
||||
// $Id: MisoContext.java,v 1.4 2001/08/16 23:14:21 mdb Exp $
|
||||
// $Id: MisoContext.java,v 1.5 2001/10/15 23:53:43 shaper Exp $
|
||||
|
||||
package com.threerings.miso.util;
|
||||
|
||||
import com.samskivert.util.Context;
|
||||
|
||||
import com.threerings.media.tile.TileManager;
|
||||
|
||||
public interface MisoContext extends Context
|
||||
{
|
||||
/**
|
||||
* Return a reference to the TileManager. This reference is valid
|
||||
* for the lifetime of the application.
|
||||
* Returns a reference to the tile manager. This reference is
|
||||
* valid for the lifetime of the application.
|
||||
*/
|
||||
public TileManager getTileManager ();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user