Read constraints for object tiles.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3598 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Andrzej Kapolka
2005-06-15 18:54:24 +00:00
parent 97b1085388
commit 89b51beee2
3 changed files with 99 additions and 3 deletions
@@ -1,5 +1,5 @@
//
// $Id: ObjectTile.java,v 1.18 2004/08/27 02:12:41 mdb Exp $
// $Id$
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
@@ -24,6 +24,7 @@ package com.threerings.media.tile;
import java.awt.Dimension;
import java.awt.Point;
import com.samskivert.util.ListUtil;
import com.samskivert.util.StringUtil;
import com.threerings.util.DirectionUtil;
@@ -165,6 +166,24 @@ public class ObjectTile extends Tile
return _sorient;
}
/**
* Returns the list of constraints associated with this object, or
* <code>null</code> if the object has no constraints.
*/
public String[] getConstraints ()
{
return _constraints;
}
/**
* Checks whether this object has the given constraint.
*/
public boolean hasConstraint (String constraint)
{
return (_constraints == null) ? false :
ListUtil.contains(_constraints, constraint);
}
// documentation inherited
public void toString (StringBuffer buf)
{
@@ -177,6 +196,10 @@ public class ObjectTile extends Tile
buf.append(", sorient=");
buf.append(DirectionUtil.toShortString(_sorient));
}
if (_constraints != null) {
buf.append(", constraints=").append(StringUtil.toString(
_constraints));
}
}
/** The object footprint width in unit tile units. */
@@ -195,4 +218,7 @@ public class ObjectTile extends Tile
/** The orientation of the "spot" associated with this object. */
protected byte _sorient;
/** The list of constraints associated with this object. */
protected String[] _constraints;
}
@@ -1,5 +1,5 @@
//
// $Id: ObjectTileSet.java,v 1.19 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
@@ -21,6 +21,7 @@
package com.threerings.media.tile;
import com.samskivert.util.ListUtil;
import com.samskivert.util.StringUtil;
import com.threerings.media.image.Colorization;
@@ -35,6 +36,28 @@ import com.threerings.media.image.Colorization;
public class ObjectTileSet extends SwissArmyTileSet
implements RecolorableTileSet
{
/** A constraint indicating that the object must be attached to another
* object in the indicated direction. */
public static final String ATTACH_N = "ATTACH_N", ATTACH_E = "ATTACH_E",
ATTACH_S = "ATTACH_S", ATTACH_W = "ATTACH_W";
/** A constraint indicating that the object must have empty space in the
* indicated direction. */
public static final String SPACE_N = "SPACE_N", SPACE_E = "SPACE_E",
SPACE_S = "SPACE_S", SPACE_W = "SPACE_W";
/** A constraint indicating that the object is a surface (e.g., table). */
public static final String SURFACE = "SURFACE";
/** A constraint indicating that the object must be placed on a surface. */
public static final String ON_SURFACE = "ON_SURFACE";
/** A constraint indicating that the object is a wall. */
public static final String WALL = "WALL";
/** A constraint indicating that the object must be placed on a wall. */
public static final String ON_WALL = "ON_WALL";
/**
* Sets the widths (in unit tile count) of the objects in this
* tileset. This must be accompanied by a call to {@link
@@ -113,6 +136,14 @@ public class ObjectTileSet extends SwissArmyTileSet
_sorients = sorients;
}
/**
* Sets the lists of constraints associated with our object tiles.
*/
public void setConstraints (String[][] constraints)
{
_constraints = constraints;
}
/**
* Returns the x coordinate of the spot associated with the specified
* tile index.
@@ -140,6 +171,24 @@ public class ObjectTileSet extends SwissArmyTileSet
return (_sorients == null) ? 0 : _sorients[tileIdx];
}
/**
* Returns the list of constraints associated with the specified tile
* index, or <code>null</code> if the index has no constraints.
*/
public String[] getConstraints (int tileIdx)
{
return (_constraints == null) ? null : _constraints[tileIdx];
}
/**
* Checks whether the tile at the specified index has the given constraint.
*/
public boolean hasConstraint (int tileIdx, String constraint)
{
return (_constraints == null) ? false :
ListUtil.contains(_constraints[tileIdx], constraint);
}
// documentation inherited from interface RecolorableTileSet
public String[] getColorizations ()
{
@@ -159,6 +208,7 @@ public class ObjectTileSet extends SwissArmyTileSet
buf.append(", xspots=").append(StringUtil.toString(_xspots));
buf.append(", yspots=").append(StringUtil.toString(_yspots));
buf.append(", sorients=").append(StringUtil.toString(_sorients));
buf.append(", constraints=").append(StringUtil.toString(_constraints));
}
// documentation inherited
@@ -228,6 +278,9 @@ public class ObjectTileSet extends SwissArmyTileSet
/** The orientation of the "spots" associated with our tiles. */
protected byte[] _sorients;
/** Lists of constraints associated with our tiles. */
protected String[][] _constraints;
/** Increase this value when object's serialized state is impacted by
* a class change (modification of fields, inheritance). */
private static final long serialVersionUID = 1;
@@ -1,5 +1,5 @@
//
// $Id: ObjectTileSetRuleSet.java,v 1.12 2004/08/27 02:12:44 mdb Exp $
// $Id$
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
@@ -53,6 +53,8 @@ import com.threerings.util.DirectionUtil;
* &lt;objectHeights&gt;3, 4, 3, 4&lt;/objectHeights&gt;
* &lt;!-- the default render priorities for these object tiles --&gt;
* &lt;priorities&gt;0, 0, -1, 0&lt;/priorities&gt;
* &lt;!-- the constraints for these object tiles --&gt;
* &lt;constraints&gt;ATTACH_N, ATTACH_E, ATTACH_S, ATTACH_W&lt;/constraints&gt;
* &lt;/tileset&gt;
* </pre>
*/
@@ -161,6 +163,21 @@ public class ObjectTileSetRuleSet extends SwissArmyTileSetRuleSet
set.setSpotOrients(sorients);
}
});
digester.addRule(
_prefix + TILESET_PATH + "/constraints",
new CallMethodSpecialRule() {
public void parseAndSet (String bodyText, Object target)
{
String[] constrs = StringUtil.parseStringArray(
bodyText);
String[][] constraints = new String[constrs.length][];
for (int ii = 0; ii < constrs.length; ii++) {
constraints[ii] = constrs[ii].split("\\s*|\\s*");
}
((ObjectTileSet)target).setConstraints(constraints);
}
});
}
// documentation inherited