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:
@@ -0,0 +1,97 @@
|
||||
//
|
||||
// $Id: CharacterManager.java,v 1.1 2001/10/15 23:53:43 shaper Exp $
|
||||
|
||||
package com.threerings.miso.scene;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.samskivert.util.Config;
|
||||
import com.samskivert.util.HashIntMap;
|
||||
|
||||
import com.threerings.media.sprite.MultiFrameImage;
|
||||
import com.threerings.media.tile.TileManager;
|
||||
|
||||
import com.threerings.miso.Log;
|
||||
import com.threerings.miso.scene.xml.XMLCharacterParser;
|
||||
import com.threerings.miso.tile.TileUtil;
|
||||
import com.threerings.miso.util.MisoUtil;
|
||||
|
||||
/**
|
||||
* The character manager provides facilities for constructing sprites
|
||||
* that are used to represent characters in a scene.
|
||||
*/
|
||||
public class CharacterManager
|
||||
{
|
||||
/**
|
||||
* Construct the character manager.
|
||||
*/
|
||||
public CharacterManager (Config config, TileManager tilemgr)
|
||||
{
|
||||
_tilemgr = tilemgr;
|
||||
|
||||
// load character data descriptions
|
||||
String file = config.getValue(CHARFILE_KEY, DEFAULT_CHARFILE);
|
||||
try {
|
||||
new XMLCharacterParser().loadCharacters(file, _characters);
|
||||
} catch (IOException ioe) {
|
||||
Log.warning("Exception loading character descriptions " +
|
||||
"[ioe=" + ioe + "].");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a sprite representing the character described by the
|
||||
* given tile set id.
|
||||
*
|
||||
* @param the character tile set id.
|
||||
*/
|
||||
public AmbulatorySprite getCharacter (int tsid)
|
||||
{
|
||||
CharacterInfo info = (CharacterInfo)_characters.get(tsid);
|
||||
if (info == null) {
|
||||
// no such character
|
||||
Log.warning("Unknown character requested [tsid=" + tsid + "].");
|
||||
return null;
|
||||
}
|
||||
|
||||
MultiFrameImage[] anims = TileUtil.getAmbulatorySpriteFrames(
|
||||
_tilemgr, tsid, info.frameCount);
|
||||
|
||||
AmbulatorySprite sprite = new AmbulatorySprite(0, 0, anims);
|
||||
sprite.setFrameRate(info.frameRate);
|
||||
|
||||
return sprite;
|
||||
}
|
||||
|
||||
/** The config key for the character description file. */
|
||||
protected static final String CHARFILE_KEY =
|
||||
MisoUtil.CONFIG_KEY + ".characters";
|
||||
|
||||
/** The default character description file. */
|
||||
protected static final String DEFAULT_CHARFILE =
|
||||
"rsrc/config/miso/characters.xml";
|
||||
|
||||
/** The hashtable of character info objects. */
|
||||
protected HashIntMap _characters = new HashIntMap();
|
||||
|
||||
/** The tile manager. */
|
||||
protected TileManager _tilemgr;
|
||||
|
||||
/**
|
||||
* A class that contains character description information for a
|
||||
* single character for use when constructing the character's
|
||||
* sprite.
|
||||
*/
|
||||
public static class CharacterInfo
|
||||
{
|
||||
public int tsid;
|
||||
public int frameCount;
|
||||
public int frameRate;
|
||||
|
||||
public String toString ()
|
||||
{
|
||||
return "[tsid=" + tsid + ", frameCount=" + frameCount +
|
||||
", frameRate=" + frameRate + "]";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: CharacterSprite.java,v 1.11 2001/10/12 00:41:48 shaper Exp $
|
||||
// $Id: CharacterSprite.java,v 1.12 2001/10/15 23:53:43 shaper Exp $
|
||||
|
||||
package com.threerings.miso.scene;
|
||||
|
||||
@@ -9,9 +9,8 @@ import com.threerings.miso.Log;
|
||||
import com.threerings.miso.tile.MisoTile;
|
||||
|
||||
/**
|
||||
* An <code>AmbulatorySprite</code> is a sprite that can face in one of
|
||||
* the various compass directions and that can animate itself walking
|
||||
* along some chosen path.
|
||||
* An ambulatory sprite is a sprite that animates itself while walking
|
||||
* about in a scene.
|
||||
*/
|
||||
public class AmbulatorySprite extends Sprite implements Traverser
|
||||
{
|
||||
@@ -46,6 +45,13 @@ public class AmbulatorySprite extends Sprite implements Traverser
|
||||
setFrames(_anims[_orient]);
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public void cancelMove ()
|
||||
{
|
||||
super.cancelMove();
|
||||
halt();
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
protected void pathBeginning ()
|
||||
{
|
||||
@@ -59,7 +65,15 @@ public class AmbulatorySprite extends Sprite implements Traverser
|
||||
protected void pathCompleted ()
|
||||
{
|
||||
super.pathCompleted();
|
||||
halt();
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the sprite animation frame to reflect the cessation of
|
||||
* movement and disables any further animation.
|
||||
*/
|
||||
protected void halt ()
|
||||
{
|
||||
// come to a halt looking settled and at peace
|
||||
_frame = _frames.getFrame(_frameIdx = 0);
|
||||
invalidate();
|
||||
|
||||
Reference in New Issue
Block a user