Tile sets that are specified as object tile sets now always produce

object tiles.  If no dimensions are specified for an object, it
defaults to 1x1 unit tile units.  The media package supports
specification of tilesets as object tile sets via the "layer"
attribute.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@450 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Walter Korman
2001-10-12 16:36:58 +00:00
parent 15eca5d163
commit 9fc38238a6
3 changed files with 57 additions and 20 deletions
@@ -1,5 +1,5 @@
//
// $Id: TileSetImpl.java,v 1.1 2001/10/11 00:41:26 shaper Exp $
// $Id: TileSetImpl.java,v 1.2 2001/10/12 16:36:58 shaper Exp $
package com.threerings.media.tile;
@@ -37,8 +37,8 @@ public class TileSetImpl implements TileSet
/** The number of tiles in the tileset. */
public int numTiles;
/** Mapping of object tile ids to object dimensions. */
public HashIntMap objects = new HashIntMap();
/** Whether this set produces object tiles. */
public boolean isObjectSet = false;
/**
* The offset distance (x, y) in pixels from the top-left of the
@@ -123,11 +123,24 @@ public class TileSetImpl implements TileSet
*/
protected Tile createTile (int tid)
{
int size[] = (int[])objects.get(tid);
if (size != null) {
return new ObjectTile(tsid, tid, size[0], size[1]);
// construct an object tile if the tile set was specified as such
if (isObjectSet) {
// default object dimensions to (1, 1)
int wid = 1, hei = 1;
// retrieve object dimensions if known
if (_objects != null) {
int size[] = (int[])_objects.get(tid);
if (size != null) {
wid = size[0];
hei = size[1];
}
}
return new ObjectTile(tsid, tid, wid, hei);
}
// construct a basic tile
return new Tile(tsid, tid);
}
@@ -192,6 +205,18 @@ public class TileSetImpl implements TileSet
_imgTiles, tx, ty, rowWidth[ridx], rowHeight[ridx]);
}
protected void addObjectInfo (int tid, int size[])
{
if (_objects == null) {
_objects = new HashIntMap();
}
_objects.put(tid, size);
}
/** Mapping of object tile ids to object dimensions. */
protected HashIntMap _objects;
/** The image containing all tile images for this set. */
protected Image _imgTiles;
}
@@ -1,23 +1,22 @@
//
// $Id: TileSetParser.java,v 1.5 2001/08/16 23:14:20 mdb Exp $
// $Id: TileSetParser.java,v 1.6 2001/10/12 16:36:58 shaper Exp $
package com.threerings.media.tile;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/**
* The TileSetParser is a general interface to be implemented by
* classes that load tileset descriptions in a particular format from
* a file.
* The tile set parser interface is intended to be implemented by
* classes that load tileset descriptions from a file.
*/
public interface TileSetParser
{
/**
* 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 list if no
* construct {@link TileSet} objects to suit. Return a list of
* all tile set objects constructed, or a zero-length list if no
* tileset descriptions were fully parsed.
*/
public ArrayList loadTileSets (String fname) throws IOException;
public List loadTileSets (String fname) throws IOException;
}
@@ -1,11 +1,12 @@
//
// $Id: XMLTileSetParser.java,v 1.16 2001/10/11 00:41:26 shaper Exp $
// $Id: XMLTileSetParser.java,v 1.17 2001/10/12 16:36:58 shaper Exp $
package com.threerings.media.tile;
import java.awt.Point;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
import javax.xml.parsers.ParserConfigurationException;
import org.xml.sax.*;
@@ -74,9 +75,18 @@ public class XMLTileSetParser extends DefaultHandler
_tag = qName;
if (_tag.equals("tileset")) {
// construct the new tile set
_tset = createTileSet();
// note whether it contains object tiles
String str = attributes.getValue("layer");
_tset.isObjectSet = str.toLowerCase().equals(LAYER_OBJECT);
// get the tile set id
_tset.tsid = getInt(attributes.getValue("tsid"));
String str = attributes.getValue("name");
// get the tile set name
str = attributes.getValue("name");
_tset.name = (str == null) ? DEF_NAME : str;
} else if (_tag.equals("object")) {
@@ -87,7 +97,7 @@ public class XMLTileSetParser extends DefaultHandler
int hei = getInt(attributes.getValue("height"));
// add the object info to the tileset object hashtable
_tset.objects.put(tid, new int[] { wid, hei });
_tset.addObjectInfo(tid, new int[] { wid, hei });
}
}
@@ -120,7 +130,7 @@ public class XMLTileSetParser extends DefaultHandler
}
// documentation inherited
public ArrayList loadTileSets (String fname) throws IOException
public List loadTileSets (String fname) throws IOException
{
try {
InputStream tis = ConfigUtil.getStream(fname);
@@ -154,7 +164,7 @@ public class XMLTileSetParser extends DefaultHandler
protected void init ()
{
_chars = new StringBuffer();
_tset = createTileSet();
_tset = null;
}
/**
@@ -164,7 +174,7 @@ public class XMLTileSetParser extends DefaultHandler
*/
protected TileSetImpl createTileSet ()
{
return new TileSetImpl();
return new TileSetImpl();
}
/**
@@ -198,6 +208,9 @@ public class XMLTileSetParser extends DefaultHandler
/** Default tileset name. */
protected static final String DEF_NAME = "Untitled";
/** String constant denoting an object tile set. */
protected static final String LAYER_OBJECT = "object";
/** The XML element tag currently being processed. */
protected String _tag;