Initial work on support for objects whose images span multiple tiles.
Made TileSet an interface. Throw exceptions for unknown tile or tile set requests. General clean-up and documentation. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@427 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
//
|
||||
// $Id: BaseTileSet.java,v 1.1 2001/10/08 21:04:25 shaper Exp $
|
||||
// $Id: BaseTileSet.java,v 1.2 2001/10/11 00:41:27 shaper Exp $
|
||||
|
||||
package com.threerings.miso.tile;
|
||||
|
||||
import com.threerings.media.tile.*;
|
||||
|
||||
import com.threerings.miso.scene.MisoScene;
|
||||
|
||||
/**
|
||||
* The miso tile set class extends the base tile set class to add
|
||||
* support for tile passability. Passability is used to determine
|
||||
@@ -12,28 +14,33 @@ import com.threerings.media.tile.*;
|
||||
* traverse a particular tile in a {@link
|
||||
* com.threerings.miso.scene.MisoScene}.
|
||||
*/
|
||||
public class MisoTileSet extends TileSet
|
||||
public class MisoTileSet extends TileSetImpl
|
||||
{
|
||||
public MisoTileSet ()
|
||||
{
|
||||
_model = new MisoTileSetModel();
|
||||
}
|
||||
/** The miso scene layer the tiles are intended for. */
|
||||
public int layer;
|
||||
|
||||
/** Whether each tile is passable. */
|
||||
public int passable[];
|
||||
|
||||
public Tile createTile (int tid)
|
||||
{
|
||||
MisoTile tile = new MisoTile(_model.tsid, tid);
|
||||
// only create miso tiles for the base layer
|
||||
if (layer != MisoScene.LAYER_BASE) {
|
||||
return super.createTile(tid);
|
||||
}
|
||||
|
||||
// set the tile's passability, defaulting to passable if this
|
||||
// tileset has no passability specified
|
||||
int passable[] = ((MisoTileSetModel)_model).passable;
|
||||
tile.passable = (passable == null || (passable[tid] == 1));
|
||||
|
||||
return tile;
|
||||
return new MisoTile(tsid, tid);
|
||||
}
|
||||
|
||||
protected static class MisoTileSetModel extends TileSetModel
|
||||
protected void populateTile (Tile tile)
|
||||
{
|
||||
/** Whether each tile is passable. */
|
||||
public int passable[];
|
||||
super.populateTile(tile);
|
||||
|
||||
if (tile instanceof MisoTile) {
|
||||
// set the tile's passability, defaulting to passable if this
|
||||
// tileset has no passability specified
|
||||
((MisoTile)tile).passable =
|
||||
(passable == null || (passable[tile.tid] == 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: TileUtil.java,v 1.5 2001/09/13 19:10:26 mdb Exp $
|
||||
// $Id: TileUtil.java,v 1.6 2001/10/11 00:41:27 shaper Exp $
|
||||
|
||||
package com.threerings.miso.tile;
|
||||
|
||||
@@ -9,6 +9,7 @@ import com.threerings.media.sprite.MultiFrameImage;
|
||||
import com.threerings.media.sprite.Sprite;
|
||||
import com.threerings.media.tile.*;
|
||||
|
||||
import com.threerings.miso.Log;
|
||||
import com.threerings.miso.scene.AmbulatorySprite;
|
||||
|
||||
/**
|
||||
@@ -28,19 +29,27 @@ public class TileUtil
|
||||
*
|
||||
* @return the array of multi-frame sprite images.
|
||||
*/
|
||||
public static MultiFrameImage[] getAmbulatorySpriteFrames (
|
||||
TileManager tilemgr, int tsid)
|
||||
public static MultiFrameImage[]
|
||||
getAmbulatorySpriteFrames (TileManager tilemgr, int tsid)
|
||||
{
|
||||
MultiFrameImage[] anims = new MultiFrameImage[Sprite.NUM_DIRECTIONS];
|
||||
|
||||
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;
|
||||
tiles[jj] = tilemgr.getTile(tsid, idx);
|
||||
}
|
||||
anims[ii] = new MultiTileImage(tiles);
|
||||
}
|
||||
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;
|
||||
tiles[jj] = tilemgr.getTile(tsid, idx);
|
||||
}
|
||||
|
||||
anims[ii] = new MultiTileImage(tiles);
|
||||
}
|
||||
|
||||
} catch (TileException te) {
|
||||
Log.warning("Exception retrieving ambulatory sprite tiles " +
|
||||
"[te=" + te + "].");
|
||||
return null;
|
||||
}
|
||||
|
||||
return anims;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
//
|
||||
// $Id: XMLMisoTileSetParser.java,v 1.1 2001/10/08 21:04:25 shaper Exp $
|
||||
// $Id: XMLMisoTileSetParser.java,v 1.2 2001/10/11 00:41:27 shaper Exp $
|
||||
|
||||
package com.threerings.miso.tile;
|
||||
|
||||
import com.samskivert.util.StringUtil;
|
||||
import org.xml.sax.*;
|
||||
|
||||
import com.samskivert.util.StringUtil;
|
||||
import com.threerings.media.tile.*;
|
||||
import com.threerings.miso.scene.util.MisoSceneUtil;
|
||||
|
||||
/**
|
||||
* Extends the base XML tile set parser to construct {@link
|
||||
@@ -14,17 +16,30 @@ import com.threerings.media.tile.*;
|
||||
*/
|
||||
public class XMLMisoTileSetParser extends XMLTileSetParser
|
||||
{
|
||||
// documentation inherited
|
||||
public void startElement (String uri, String localName,
|
||||
String qName, Attributes attributes)
|
||||
{
|
||||
super.startElement(uri, localName, qName, attributes);
|
||||
|
||||
if (qName.equals("tileset")) {
|
||||
String val = attributes.getValue("layer");
|
||||
((MisoTileSet)_tset).layer = MisoSceneUtil.getLayerIndex(val);
|
||||
}
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
protected void finishElement (String qName, String str)
|
||||
{
|
||||
super.finishElement(qName, str);
|
||||
|
||||
if (qName.equals("passable")) {
|
||||
((MisoTileSet.MisoTileSetModel)_model).passable =
|
||||
StringUtil.parseIntArray(str);
|
||||
((MisoTileSet)_tset).passable = StringUtil.parseIntArray(str);
|
||||
}
|
||||
}
|
||||
|
||||
protected TileSet createTileSet ()
|
||||
// documentation inherited
|
||||
protected TileSetImpl createTileSet ()
|
||||
{
|
||||
return new MisoTileSet();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user