Added constraint fields to TrimmedObjectTileSet, fixed constraint parsing, added basic constraint handler class, added image manager to StageServer to fix NPE in tile retrieval.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3607 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Andrzej Kapolka
2005-06-20 21:18:55 +00:00
parent d7fd2f5f67
commit bd017c0237
6 changed files with 522 additions and 8 deletions
@@ -184,6 +184,14 @@ public class ObjectTile extends Tile
ListUtil.contains(_constraints, constraint);
}
/**
* Configures this object's constraints.
*/
public void setConstraints (String[] constraints)
{
_constraints = constraints;
}
// documentation inherited
public void toString (StringBuffer buf)
{
@@ -249,6 +249,9 @@ public class ObjectTileSet extends SwissArmyTileSet
otile.setSpot(_xspots[tileIndex], _yspots[tileIndex],
_sorients[tileIndex]);
}
if (_constraints != null) {
otile.setConstraints(_constraints[tileIndex]);
}
}
/** The width (in tile units) of our object tiles. */
@@ -283,5 +286,5 @@ public class ObjectTileSet extends SwissArmyTileSet
/** Increase this value when object's serialized state is impacted by
* a class change (modification of fields, inheritance). */
private static final long serialVersionUID = 1;
private static final long serialVersionUID = 2;
}
@@ -1,5 +1,5 @@
//
// $Id: TrimmedObjectTileSet.java,v 1.16 2004/08/30 22:09:29 ray Exp $
// $Id$
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
@@ -26,6 +26,7 @@ import java.io.IOException;
import java.io.OutputStream;
import java.io.Serializable;
import com.samskivert.util.ListUtil;
import com.samskivert.util.StringUtil;
import com.threerings.media.image.Colorization;
@@ -75,6 +76,24 @@ public class TrimmedObjectTileSet extends TileSet
return (_bits == null) ? -1 : _bits[tileIdx].sorient;
}
/**
* Returns the constraints associated with the specified tile index, or
* <code>null</code> if the object has no associated constraints.
*/
public String[] getConstraints (int tileIdx)
{
return (_bits == null) ? null : _bits[tileIdx].constraints;
}
/**
* Checks whether the tile at the specified index has the given constraint.
*/
public boolean hasConstraint (int tileIdx, String constraint)
{
return (_bits == null || _bits[tileIdx].constraints == null) ? false :
ListUtil.contains(_bits[tileIdx].constraints, constraint);
}
// documentation inherited from interface RecolorableTileSet
public String[] getColorizations ()
{
@@ -136,6 +155,7 @@ public class TrimmedObjectTileSet extends TileSet
if (bits.sorient != -1) {
otile.setSpot(bits.xspot, bits.yspot, bits.sorient);
}
otile.setConstraints(bits.constraints);
}
}
@@ -174,7 +194,8 @@ public class TrimmedObjectTileSet extends TileSet
// create our bits if needed
if (source._priorities != null ||
source._xspots != null) {
source._xspots != null ||
source._constraints != null) {
tset._bits = new Bits[tcount];
}
@@ -205,6 +226,9 @@ public class TrimmedObjectTileSet extends TileSet
tset._bits[ii].yspot = source._yspots[ii];
tset._bits[ii].sorient = source._sorients[ii];
}
if (source._constraints != null) {
tset._bits[ii].constraints = source._constraints[ii];
}
}
// create the trimmed tileset image
@@ -243,6 +267,9 @@ public class TrimmedObjectTileSet extends TileSet
/** The orientation of the "spot" associated with this object. */
public byte sorient = -1;
/** The constraints associated with this object. */
public String[] constraints;
/** Generates a string representation of this instance. */
public String toString ()
{
@@ -251,7 +278,7 @@ public class TrimmedObjectTileSet extends TileSet
/** Increase this value when object's serialized state is impacted
* by a class change (modification of fields, inheritance). */
private static final long serialVersionUID = 1;
private static final long serialVersionUID = 2;
}
/** Contains the width and height of each object tile and the offset
@@ -173,7 +173,7 @@ public class ObjectTileSetRuleSet extends SwissArmyTileSetRuleSet
bodyText);
String[][] constraints = new String[constrs.length][];
for (int ii = 0; ii < constrs.length; ii++) {
constraints[ii] = constrs[ii].split("\\s*|\\s*");
constraints[ii] = constrs[ii].split("\\s*\\|\\s*");
}
((ObjectTileSet)target).setConstraints(constraints);
}