More work on character components. Revamped tile sets to allow them
to be constructed and used directly. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@581 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,9 +1,73 @@
|
||||
//
|
||||
// $Id: BaseTileSet.java,v 1.3 2001/10/12 00:43:04 shaper Exp $
|
||||
// $Id: BaseTileSet.java,v 1.4 2001/11/01 01:40:42 shaper Exp $
|
||||
|
||||
package com.threerings.miso.tile;
|
||||
|
||||
public interface MisoTileSet
|
||||
import java.awt.Point;
|
||||
|
||||
import com.samskivert.util.HashIntMap;
|
||||
|
||||
import com.threerings.media.ImageManager;
|
||||
import com.threerings.media.tile.*;
|
||||
|
||||
import com.threerings.miso.scene.MisoScene;
|
||||
|
||||
/**
|
||||
* The miso tile set extends the base tile set to add support for tile
|
||||
* passability. Passability is used to determine whether {@link
|
||||
* com.threerings.miso.scene.Traverser} objects can traverse a
|
||||
* particular tile in a {@link com.threerings.miso.scene.MisoScene}.
|
||||
*/
|
||||
public class MisoTileSet extends TileSet
|
||||
{
|
||||
public int getLayerIndex ();
|
||||
public MisoTileSet (
|
||||
ImageManager imgmgr, int tsid, String name, String imgFile,
|
||||
int tileCount[], int rowWidth[], int rowHeight[],
|
||||
int numTiles, Point offsetPos, Point gapDist,
|
||||
boolean isObjectSet, HashIntMap objects,
|
||||
int layer, int passable[])
|
||||
{
|
||||
super(imgmgr, tsid, name, imgFile, tileCount, rowWidth,
|
||||
rowHeight, numTiles, offsetPos, gapDist,
|
||||
isObjectSet, objects);
|
||||
|
||||
_layer = layer;
|
||||
_passable = passable;
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public Tile createTile (int tid)
|
||||
{
|
||||
// only create miso tiles for the base layer
|
||||
if (_layer != MisoScene.LAYER_BASE) {
|
||||
return super.createTile(tid);
|
||||
}
|
||||
|
||||
return new MisoTile(_tsid, tid);
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
protected void populateTile (Tile tile)
|
||||
{
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public int getLayerIndex ()
|
||||
{
|
||||
return _layer;
|
||||
}
|
||||
|
||||
/** The miso scene layer the tiles are intended for. */
|
||||
protected int _layer;
|
||||
|
||||
/** Whether each tile is passable. */
|
||||
protected int _passable[];
|
||||
}
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
//
|
||||
// $Id: CompiledTileSetManager.java,v 1.8 2001/08/16 23:17:46 mdb Exp $
|
||||
|
||||
package com.threerings.miso.tile;
|
||||
|
||||
import com.threerings.media.tile.TileSetManagerImpl;
|
||||
|
||||
public class CompiledTileSetManager extends TileSetManagerImpl
|
||||
{
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
//
|
||||
// $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.ArrayList;
|
||||
|
||||
import com.samskivert.util.Config;
|
||||
|
||||
import com.threerings.media.ImageManager;
|
||||
import com.threerings.media.tile.*;
|
||||
|
||||
import com.threerings.miso.Log;
|
||||
import com.threerings.miso.util.MisoUtil;
|
||||
|
||||
/**
|
||||
* Extends general tileset manager functionality to allow reading
|
||||
* tileset information from XML files. The XML file format allows for
|
||||
* improved version-control, and makes tilesets easier to view, edit,
|
||||
* and re-use than might otherwise be the case.
|
||||
*/
|
||||
public class EditableTileSetManager extends TileSetManagerImpl
|
||||
{
|
||||
public void init (Config config, ImageManager imgmgr)
|
||||
{
|
||||
super.init(config, imgmgr);
|
||||
|
||||
// load the tilesets from the XML description file
|
||||
String fname = config.getValue(TILESETS_KEY, (String)null);
|
||||
ArrayList tilesets = new ArrayList();
|
||||
try {
|
||||
new XMLMisoTileSetParser().loadTileSets(fname, tilesets);
|
||||
} catch (IOException ioe) {
|
||||
Log.warning("Exception loading tile sets [ioe=" + ioe + "].");
|
||||
return;
|
||||
}
|
||||
|
||||
// bail if we didn't find any tilesets
|
||||
int size = tilesets.size();
|
||||
if (size == 0) {
|
||||
Log.warning("No tilesets found [fname=" + fname + "].");
|
||||
return;
|
||||
}
|
||||
|
||||
// copy new tilesets into the main tileset hashtable
|
||||
for (int ii = 0; ii < size; ii++) {
|
||||
TileSet tset = (TileSet)tilesets.get(ii);
|
||||
_tilesets.put(tset.getId(), tset);
|
||||
Log.info("Adding tileset to cache [tset=" + tset + "].");
|
||||
}
|
||||
}
|
||||
|
||||
/** The config key for the tileset description file. */
|
||||
protected static final String TILESETS_KEY =
|
||||
MisoUtil.CONFIG_KEY + ".tilesets";
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
//
|
||||
// $Id: MisoTileSetImpl.java,v 1.1 2001/10/12 00:43:04 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
|
||||
* whether {@link com.threerings.miso.scene.Traverser} objects can
|
||||
* traverse a particular tile in a {@link
|
||||
* com.threerings.miso.scene.MisoScene}.
|
||||
*/
|
||||
public class MisoTileSetImpl
|
||||
extends TileSetImpl
|
||||
implements MisoTileSet
|
||||
{
|
||||
/** The miso scene layer the tiles are intended for. */
|
||||
public int layer;
|
||||
|
||||
/** Whether each tile is passable. */
|
||||
public int passable[];
|
||||
|
||||
// documentation inherited
|
||||
public Tile createTile (int tid)
|
||||
{
|
||||
// only create miso tiles for the base layer
|
||||
if (layer != MisoScene.LAYER_BASE) {
|
||||
return super.createTile(tid);
|
||||
}
|
||||
|
||||
return new MisoTile(tsid, tid);
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
protected void populateTile (Tile tile)
|
||||
{
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public int getLayerIndex ()
|
||||
{
|
||||
return layer;
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,15 @@
|
||||
//
|
||||
// $Id: XMLMisoTileSetParser.java,v 1.4 2001/10/15 23:53:43 shaper Exp $
|
||||
// $Id: XMLMisoTileSetParser.java,v 1.5 2001/11/01 01:40:42 shaper Exp $
|
||||
|
||||
package com.threerings.miso.tile;
|
||||
|
||||
import org.xml.sax.*;
|
||||
|
||||
import com.samskivert.util.StringUtil;
|
||||
|
||||
import com.threerings.media.ImageManager;
|
||||
import com.threerings.media.tile.*;
|
||||
|
||||
import com.threerings.miso.scene.util.MisoSceneUtil;
|
||||
|
||||
/**
|
||||
@@ -16,6 +19,12 @@ import com.threerings.miso.scene.util.MisoSceneUtil;
|
||||
*/
|
||||
public class XMLMisoTileSetParser extends XMLTileSetParser
|
||||
{
|
||||
// documentation inherited
|
||||
public XMLMisoTileSetParser (ImageManager imgmgr)
|
||||
{
|
||||
super(imgmgr);
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public void startElement (
|
||||
String uri, String localName, String qName, Attributes attributes)
|
||||
@@ -24,7 +33,7 @@ public class XMLMisoTileSetParser extends XMLTileSetParser
|
||||
|
||||
if (qName.equals("tileset")) {
|
||||
String val = attributes.getValue("layer");
|
||||
((MisoTileSetImpl)_tset).layer = MisoSceneUtil.getLayerIndex(val);
|
||||
_layer = MisoSceneUtil.getLayerIndex(val);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,13 +44,23 @@ public class XMLMisoTileSetParser extends XMLTileSetParser
|
||||
super.finishElement(uri, localName, qName, data);
|
||||
|
||||
if (qName.equals("passable")) {
|
||||
((MisoTileSetImpl)_tset).passable = StringUtil.parseIntArray(data);
|
||||
}
|
||||
_passable = StringUtil.parseIntArray(data);
|
||||
} else if (qName.equals("tileset")) {
|
||||
_passable = null;
|
||||
_layer = -1;
|
||||
}
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
protected TileSetImpl createTileSet ()
|
||||
protected TileSet createTileSet ()
|
||||
{
|
||||
return new MisoTileSetImpl();
|
||||
return new MisoTileSet(
|
||||
_imgmgr, _info.tsid, _info.name, _info.imgFile, _info.tileCount,
|
||||
_info.rowWidth, _info.rowHeight, _info.numTiles, _info.offsetPos,
|
||||
_info.gapDist, _info.isObjectSet, _info.objects,
|
||||
_layer, _passable);
|
||||
}
|
||||
|
||||
protected int _passable[];
|
||||
protected int _layer = -1;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
//
|
||||
// $Id: XMLTileSetRepository.java,v 1.1 2001/11/01 01:40:42 shaper Exp $
|
||||
|
||||
package com.threerings.miso.tile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
import com.samskivert.util.Config;
|
||||
import com.samskivert.util.HashIntMap;
|
||||
|
||||
import com.threerings.media.ImageManager;
|
||||
import com.threerings.media.tile.*;
|
||||
|
||||
import com.threerings.miso.Log;
|
||||
import com.threerings.miso.util.MisoUtil;
|
||||
|
||||
/**
|
||||
* Extends general tile set repository functionality to read tile set
|
||||
* descriptions from an XML file.
|
||||
*/
|
||||
public class XMLFileTileSetRepository implements TileSetRepository
|
||||
{
|
||||
// documentation inherited
|
||||
public void init (Config config, ImageManager imgmgr)
|
||||
{
|
||||
// get the tile set description file path
|
||||
String fname = config.getValue(TILESETS_KEY, DEFAULT_TILESETS);
|
||||
|
||||
// load the tilesets from the XML description file
|
||||
try {
|
||||
XMLMisoTileSetParser p = new XMLMisoTileSetParser(imgmgr);
|
||||
p.loadTileSets(fname, _tilesets);
|
||||
} catch (IOException ioe) {
|
||||
Log.warning("Exception loading tile sets [ioe=" + ioe + "].");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public TileSet getTileSet (int tsid)
|
||||
throws NoSuchTileSetException
|
||||
{
|
||||
TileSet tset = (TileSet)_tilesets.get(tsid);
|
||||
if (tset == null) {
|
||||
throw new NoSuchTileSetException(tsid);
|
||||
}
|
||||
|
||||
return tset;
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public Iterator enumerateTileSets ()
|
||||
{
|
||||
return Collections.unmodifiableMap(_tilesets).values().iterator();
|
||||
}
|
||||
|
||||
/** The config key for the tileset description file. */
|
||||
protected static final String TILESETS_KEY =
|
||||
MisoUtil.CONFIG_KEY + ".tilesets";
|
||||
|
||||
/** The default tileset description file. */
|
||||
protected static final String DEFAULT_TILESETS =
|
||||
"rsrc/config/miso/tilesets.xml";
|
||||
|
||||
/** The available tilesets keyed by tileset id. */
|
||||
protected HashIntMap _tilesets = new HashIntMap();
|
||||
}
|
||||
Reference in New Issue
Block a user