Initial work on reading and writing scenes to XML files.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@113 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: TileManager.java,v 1.10 2001/07/23 18:52:51 shaper Exp $
|
||||
// $Id: TileManager.java,v 1.11 2001/07/23 22:31:48 shaper Exp $
|
||||
|
||||
package com.threerings.miso.tile;
|
||||
|
||||
@@ -20,9 +20,9 @@ public class TileManager
|
||||
/**
|
||||
* Initialize the tile manager with the given TileSetManager object.
|
||||
*/
|
||||
public TileManager (TileSetManager tsmgr)
|
||||
public TileManager (TileSetManager tilesetmgr)
|
||||
{
|
||||
_tsmgr = tsmgr;
|
||||
_tilesetmgr = tilesetmgr;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -43,7 +43,7 @@ public class TileManager
|
||||
|
||||
// retrieve the tile image from the tileset
|
||||
tile = new Tile(tsid, tid);
|
||||
if ((tile.img = _tsmgr.getTileImage(tsid, tid)) == null) {
|
||||
if ((tile.img = _tilesetmgr.getTileImage(tsid, tid)) == null) {
|
||||
Log.warning("Null tile image [tsid="+tsid+", tid="+tid+"].");
|
||||
}
|
||||
tile.height = (short)((BufferedImage)tile.img).getHeight();
|
||||
@@ -60,12 +60,12 @@ public class TileManager
|
||||
*/
|
||||
public TileSetManager getTileSetManager ()
|
||||
{
|
||||
return _tsmgr;
|
||||
return _tilesetmgr;
|
||||
}
|
||||
|
||||
/** Cache of tiles that have been requested thus far. */
|
||||
protected IntMap _tiles = new IntMap();
|
||||
|
||||
/** Our tileset manager. */
|
||||
protected TileSetManager _tsmgr;
|
||||
/** The tileset manager. */
|
||||
protected TileSetManager _tilesetmgr;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: TileSetManager.java,v 1.8 2001/07/23 18:52:51 shaper Exp $
|
||||
// $Id: TileSetManager.java,v 1.9 2001/07/23 22:31:48 shaper Exp $
|
||||
|
||||
package com.threerings.miso.tile;
|
||||
|
||||
@@ -8,30 +8,54 @@ import com.threerings.media.ImageManager;
|
||||
import java.awt.Image;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* The TileSetManager provides tileset management functionality
|
||||
* intended for use by the TileManager. It provides facilities for
|
||||
* obtaining information about individual tilesets, retrieving an list
|
||||
* of all tilesets available, and retrieving the image associated with
|
||||
* a particular tile in a set.
|
||||
*/
|
||||
public interface TileSetManager
|
||||
{
|
||||
/**
|
||||
* Return the total number of tiles in the specified tileset.
|
||||
* Return the total number of tiles in the specified tileset or -1
|
||||
* if the tileset is not found.
|
||||
*
|
||||
* @param tsid the tileset identifier.
|
||||
* @return the number of tiles.
|
||||
*/
|
||||
public int getNumTilesInSet (int tsid);
|
||||
|
||||
/**
|
||||
* Return a list of all tilesets available for use.
|
||||
* Return an ArrayList containing all TileSet objects available.
|
||||
*
|
||||
* @return the list of tilesets.
|
||||
*/
|
||||
public ArrayList getAllTileSets ();
|
||||
|
||||
/**
|
||||
* Return the tileset object corresponding to the specified tileset id.
|
||||
* Return the tileset object corresponding to the specified
|
||||
* tileset id, or null if the tileset is not found.
|
||||
*
|
||||
* @param tsid the tileset identifier.
|
||||
* @return the tileset object.
|
||||
*/
|
||||
public TileSet getTileSet (int tsid);
|
||||
|
||||
/**
|
||||
* Return the image corresponding to the specified tileset and tile id.
|
||||
*
|
||||
* @param tsid the tileset identifier.
|
||||
* @param tid the tile identifier.
|
||||
*
|
||||
* @return the tile image.
|
||||
*/
|
||||
public Image getTileImage (int tsid, int tid);
|
||||
|
||||
/**
|
||||
* Return the total number of tilesets.
|
||||
* Return the total number of tilesets available for use.
|
||||
*
|
||||
* @return the number of tilesets.
|
||||
*/
|
||||
public int getNumTileSets ();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: TileSetManagerImpl.java,v 1.7 2001/07/23 18:52:51 shaper Exp $
|
||||
// $Id: TileSetManagerImpl.java,v 1.8 2001/07/23 22:31:48 shaper Exp $
|
||||
|
||||
package com.threerings.miso.tile;
|
||||
|
||||
@@ -43,9 +43,6 @@ public abstract class TileSetManagerImpl implements TileSetManager
|
||||
|
||||
public ArrayList getAllTileSets ()
|
||||
{
|
||||
int size = _tilesets.size();
|
||||
if (size == 0) return null;
|
||||
|
||||
ArrayList list = new ArrayList();
|
||||
CollectionUtil.addAll(list, _tilesets.elements());
|
||||
return list;
|
||||
|
||||
@@ -1,24 +1,23 @@
|
||||
//
|
||||
// $Id: TileSetParser.java,v 1.3 2001/07/23 18:52:51 shaper Exp $
|
||||
// $Id: TileSetParser.java,v 1.4 2001/07/23 22:31:48 shaper Exp $
|
||||
|
||||
package com.threerings.miso.tile;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* An interface to be implemented by classes that wish to provide a
|
||||
* general interface to load tileset description information from an
|
||||
* input stream.
|
||||
* The TileSetParser is a general interface to be implemented by
|
||||
* classes that load tileset descriptions in a particular format from
|
||||
* a file.
|
||||
*/
|
||||
public interface TileSetParser
|
||||
{
|
||||
/**
|
||||
* Read tileset description data from the given input stream and
|
||||
* Read tileset description data from the specified file and
|
||||
* construct TileSet objects to suit. Return an ArrayList of all
|
||||
* TileSet objects constructed, or a zero-length array if no
|
||||
* TileSet objects constructed, or a zero-length list if no
|
||||
* tileset descriptions were fully parsed.
|
||||
*/
|
||||
public ArrayList loadTileSets (InputStream tis) throws IOException;
|
||||
public ArrayList loadTileSets (String fname) throws IOException;
|
||||
}
|
||||
|
||||
@@ -1,20 +1,19 @@
|
||||
//
|
||||
// $Id: XMLTileSetParser.java,v 1.5 2001/07/23 18:52:51 shaper Exp $
|
||||
// $Id: XMLTileSetParser.java,v 1.6 2001/07/23 22:31:48 shaper Exp $
|
||||
|
||||
package com.threerings.miso.tile;
|
||||
|
||||
import com.threerings.miso.Log;
|
||||
|
||||
import com.samskivert.util.StringUtil;
|
||||
import com.samskivert.xml.XMLUtil;
|
||||
|
||||
import org.xml.sax.*;
|
||||
import org.xml.sax.helpers.DefaultHandler;
|
||||
|
||||
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.threerings.miso.Log;
|
||||
|
||||
/**
|
||||
* Parse an XML tileset description file and construct tileset objects
|
||||
* for each valid description. Does not currently perform validation
|
||||
@@ -75,13 +74,22 @@ public class XMLTileSetParser extends DefaultHandler
|
||||
}
|
||||
}
|
||||
|
||||
public ArrayList loadTileSets (InputStream tis) throws IOException
|
||||
public ArrayList loadTileSets (String fname) throws IOException
|
||||
{
|
||||
try {
|
||||
XMLUtil.parse(this, tis);
|
||||
return _tilesets;
|
||||
try {
|
||||
InputStream tis = ConfigUtil.getStream(fname);
|
||||
if (tis == null) {
|
||||
Log.warning("Couldn't find file [fname=" + fname + "].");
|
||||
return _tilesets;
|
||||
}
|
||||
|
||||
} catch (ParserConfigurationException pce) {
|
||||
// read all tileset descriptions from the XML input stream
|
||||
XMLTileSetParser parser = new XMLTileSetParser();
|
||||
XMLUtil.parse(this, tis);
|
||||
|
||||
return _tilesets;
|
||||
|
||||
} catch (ParserConfigurationException pce) {
|
||||
throw new IOException(pce.toString());
|
||||
|
||||
} catch (SAXException saxe) {
|
||||
|
||||
Reference in New Issue
Block a user