Allow TileSetRuleSets to specify a custom tileset tag name, and use that to allow UniformTileSets as <uniformTileset> in addition to the existing SwissArmyTileSets as <tileset> in the bundle tasks.
git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@281 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
@@ -169,8 +169,7 @@ public class TileSetBundler
|
||||
for (int i = 0; i < msize; i++) {
|
||||
Mapping map = (Mapping)mappings.get(i);
|
||||
try {
|
||||
TileSetRuleSet ruleset = (TileSetRuleSet)
|
||||
Class.forName(map.ruleset).newInstance();
|
||||
TileSetRuleSet ruleset = (TileSetRuleSet)Class.forName(map.ruleset).newInstance();
|
||||
|
||||
// configure the ruleset
|
||||
ruleset.setPrefix(map.path);
|
||||
@@ -178,8 +177,7 @@ public class TileSetBundler
|
||||
_digester.addRuleSet(ruleset);
|
||||
// and add a rule to stick the parsed tilesets onto the
|
||||
// end of an array list that we'll put on the stack
|
||||
_digester.addSetNext(map.path + TileSetRuleSet.TILESET_PATH,
|
||||
"add", "java.lang.Object");
|
||||
_digester.addSetNext(ruleset.getPath(), "add", "java.lang.Object");
|
||||
|
||||
} catch (Exception e) {
|
||||
String errmsg = "Unable to create tileset rule set " +
|
||||
|
||||
@@ -66,7 +66,7 @@ public class ObjectTileSetRuleSet extends SwissArmyTileSetRuleSet
|
||||
super.addRuleInstances(digester);
|
||||
|
||||
digester.addRule(
|
||||
_prefix + TILESET_PATH + "/objectWidths",
|
||||
_path + "/objectWidths",
|
||||
new CallMethodSpecialRule() {
|
||||
public void parseAndSet (String bodyText, Object target)
|
||||
{
|
||||
@@ -76,7 +76,7 @@ public class ObjectTileSetRuleSet extends SwissArmyTileSetRuleSet
|
||||
});
|
||||
|
||||
digester.addRule(
|
||||
_prefix + TILESET_PATH + "/objectHeights",
|
||||
_path + "/objectHeights",
|
||||
new CallMethodSpecialRule() {
|
||||
public void parseAndSet (String bodyText, Object target)
|
||||
{
|
||||
@@ -86,7 +86,7 @@ public class ObjectTileSetRuleSet extends SwissArmyTileSetRuleSet
|
||||
});
|
||||
|
||||
digester.addRule(
|
||||
_prefix + TILESET_PATH + "/xOrigins", new CallMethodSpecialRule() {
|
||||
_path + "/xOrigins", new CallMethodSpecialRule() {
|
||||
public void parseAndSet (String bodyText, Object target)
|
||||
{
|
||||
int[] xorigins = StringUtil.parseIntArray(bodyText);
|
||||
@@ -95,7 +95,7 @@ public class ObjectTileSetRuleSet extends SwissArmyTileSetRuleSet
|
||||
});
|
||||
|
||||
digester.addRule(
|
||||
_prefix + TILESET_PATH + "/yOrigins", new CallMethodSpecialRule() {
|
||||
_path + "/yOrigins", new CallMethodSpecialRule() {
|
||||
public void parseAndSet (String bodyText, Object target)
|
||||
{
|
||||
int[] yorigins = StringUtil.parseIntArray(bodyText);
|
||||
@@ -104,7 +104,7 @@ public class ObjectTileSetRuleSet extends SwissArmyTileSetRuleSet
|
||||
});
|
||||
|
||||
digester.addRule(
|
||||
_prefix + TILESET_PATH + "/priorities",
|
||||
_path + "/priorities",
|
||||
new CallMethodSpecialRule() {
|
||||
public void parseAndSet (String bodyText, Object target)
|
||||
{
|
||||
@@ -114,7 +114,7 @@ public class ObjectTileSetRuleSet extends SwissArmyTileSetRuleSet
|
||||
});
|
||||
|
||||
digester.addRule(
|
||||
_prefix + TILESET_PATH + "/zations", new CallMethodSpecialRule() {
|
||||
_path + "/zations", new CallMethodSpecialRule() {
|
||||
public void parseAndSet (String bodyText, Object target)
|
||||
{
|
||||
String[] zations = StringUtil.parseStringArray(bodyText);
|
||||
@@ -123,7 +123,7 @@ public class ObjectTileSetRuleSet extends SwissArmyTileSetRuleSet
|
||||
});
|
||||
|
||||
digester.addRule(
|
||||
_prefix + TILESET_PATH + "/xspots", new CallMethodSpecialRule() {
|
||||
_path + "/xspots", new CallMethodSpecialRule() {
|
||||
public void parseAndSet (String bodyText, Object target)
|
||||
{
|
||||
short[] xspots = StringUtil.parseShortArray(bodyText);
|
||||
@@ -132,7 +132,7 @@ public class ObjectTileSetRuleSet extends SwissArmyTileSetRuleSet
|
||||
});
|
||||
|
||||
digester.addRule(
|
||||
_prefix + TILESET_PATH + "/yspots", new CallMethodSpecialRule() {
|
||||
_path + "/yspots", new CallMethodSpecialRule() {
|
||||
public void parseAndSet (String bodyText, Object target)
|
||||
{
|
||||
short[] yspots = StringUtil.parseShortArray(bodyText);
|
||||
@@ -141,7 +141,7 @@ public class ObjectTileSetRuleSet extends SwissArmyTileSetRuleSet
|
||||
});
|
||||
|
||||
digester.addRule(
|
||||
_prefix + TILESET_PATH + "/sorients", new CallMethodSpecialRule() {
|
||||
_path + "/sorients", new CallMethodSpecialRule() {
|
||||
public void parseAndSet (String bodyText, Object target)
|
||||
{
|
||||
ObjectTileSet set = (ObjectTileSet)target;
|
||||
@@ -165,7 +165,7 @@ public class ObjectTileSetRuleSet extends SwissArmyTileSetRuleSet
|
||||
});
|
||||
|
||||
digester.addRule(
|
||||
_prefix + TILESET_PATH + "/constraints",
|
||||
_path + "/constraints",
|
||||
new CallMethodSpecialRule() {
|
||||
public void parseAndSet (String bodyText, Object target)
|
||||
{
|
||||
|
||||
@@ -60,7 +60,7 @@ public class SwissArmyTileSetRuleSet extends TileSetRuleSet
|
||||
super.addRuleInstances(digester);
|
||||
|
||||
digester.addRule(
|
||||
_prefix + TILESET_PATH + "/widths", new CallMethodSpecialRule() {
|
||||
_path + "/widths", new CallMethodSpecialRule() {
|
||||
public void parseAndSet (String bodyText, Object target)
|
||||
{
|
||||
int[] widths = StringUtil.parseIntArray(bodyText);
|
||||
@@ -69,7 +69,7 @@ public class SwissArmyTileSetRuleSet extends TileSetRuleSet
|
||||
});
|
||||
|
||||
digester.addRule(
|
||||
_prefix + TILESET_PATH + "/heights", new CallMethodSpecialRule() {
|
||||
_path + "/heights", new CallMethodSpecialRule() {
|
||||
public void parseAndSet (String bodyText, Object target)
|
||||
{
|
||||
int[] heights = StringUtil.parseIntArray(bodyText);
|
||||
@@ -78,7 +78,7 @@ public class SwissArmyTileSetRuleSet extends TileSetRuleSet
|
||||
});
|
||||
|
||||
digester.addRule(
|
||||
_prefix + TILESET_PATH + "/tileCounts",
|
||||
_path + "/tileCounts",
|
||||
new CallMethodSpecialRule() {
|
||||
public void parseAndSet (String bodyText, Object target)
|
||||
{
|
||||
@@ -88,7 +88,7 @@ public class SwissArmyTileSetRuleSet extends TileSetRuleSet
|
||||
});
|
||||
|
||||
digester.addRule(
|
||||
_prefix + TILESET_PATH + "/offsetPos", new CallMethodSpecialRule() {
|
||||
_path + "/offsetPos", new CallMethodSpecialRule() {
|
||||
public void parseAndSet (String bodyText, Object target)
|
||||
{
|
||||
int[] values = StringUtil.parseIntArray(bodyText);
|
||||
@@ -103,7 +103,7 @@ public class SwissArmyTileSetRuleSet extends TileSetRuleSet
|
||||
});
|
||||
|
||||
digester.addRule(
|
||||
_prefix + TILESET_PATH + "/gapSize", new CallMethodSpecialRule() {
|
||||
_path + "/gapSize", new CallMethodSpecialRule() {
|
||||
public void parseAndSet (String bodyText, Object target)
|
||||
{
|
||||
int[] values = StringUtil.parseIntArray(bodyText);
|
||||
|
||||
@@ -45,6 +45,13 @@ public abstract class TileSetRuleSet
|
||||
* a matched tileset. */
|
||||
public static final String TILESET_PATH = "/tileset";
|
||||
|
||||
/**
|
||||
* @return The full path used to match tilesets. Consists of the prefile plus _tilesetPath.
|
||||
*/
|
||||
public String getPath(){
|
||||
return _path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instructs the tileset rule set to match tilesets with the supplied
|
||||
* prefix. For example, passing a prefix of
|
||||
@@ -65,7 +72,7 @@ public abstract class TileSetRuleSet
|
||||
*/
|
||||
public void setPrefix (String prefix)
|
||||
{
|
||||
_prefix = prefix;
|
||||
_path = prefix + _tilesetPath;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -79,21 +86,18 @@ public abstract class TileSetRuleSet
|
||||
{
|
||||
// this creates the appropriate instance when we encounter a
|
||||
// <tileset> tag
|
||||
digester.addObjectCreate(_prefix + TILESET_PATH,
|
||||
getTileSetClass().getName());
|
||||
digester.addObjectCreate(_path, getTileSetClass().getName());
|
||||
|
||||
// grab the name attribute from the <tileset> tag
|
||||
digester.addSetProperties(_prefix + TILESET_PATH);
|
||||
digester.addSetProperties(_path);
|
||||
|
||||
// grab the image path from an element
|
||||
digester.addCallMethod(
|
||||
_prefix + TILESET_PATH + "/imagePath", "setImagePath", 0);
|
||||
digester.addCallMethod(_path + "/imagePath", "setImagePath", 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* The ruleset can be provided to a {@link ValidatedSetNextRule} to
|
||||
* ensure that the tileset was fully parsed before doing something
|
||||
* with it.
|
||||
* The ruleset can be provided to a {@link ValidatedSetNextRule} to ensure that the tileset
|
||||
* was fully parsed before doing something with it.
|
||||
*/
|
||||
public boolean isValid (Object target)
|
||||
{
|
||||
@@ -123,6 +127,9 @@ public abstract class TileSetRuleSet
|
||||
*/
|
||||
protected abstract Class getTileSetClass ();
|
||||
|
||||
/** The prefix at which me match our tilesets. */
|
||||
protected String _prefix;
|
||||
/** The tileset path we append to the prefix to get the full path. */
|
||||
protected String _tilesetPath = TILESET_PATH;
|
||||
|
||||
/** The full path at which me match our tilesets. */
|
||||
protected String _path;
|
||||
}
|
||||
|
||||
@@ -42,16 +42,22 @@ import com.threerings.media.tile.UniformTileSet;
|
||||
*/
|
||||
public class UniformTileSetRuleSet extends TileSetRuleSet
|
||||
{
|
||||
public UniformTileSetRuleSet(){
|
||||
this(TILESET_PATH);
|
||||
}
|
||||
|
||||
public UniformTileSetRuleSet(String tilesetPath){
|
||||
_tilesetPath = tilesetPath;
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public void addRuleInstances (Digester digester)
|
||||
{
|
||||
super.addRuleInstances(digester);
|
||||
|
||||
digester.addCallMethod(
|
||||
_prefix + TILESET_PATH + "/width", "setWidth", 0,
|
||||
digester.addCallMethod(_path + "/width", "setWidth", 0,
|
||||
new Class[] { java.lang.Integer.TYPE });
|
||||
digester.addCallMethod(
|
||||
_prefix + TILESET_PATH + "/height", "setHeight", 0,
|
||||
digester.addCallMethod(_path + "/height", "setHeight", 0,
|
||||
new Class[] { java.lang.Integer.TYPE });
|
||||
}
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ public class XMLTileSetParser
|
||||
|
||||
// add a set next rule which will put tilesets with this prefix
|
||||
// into the array list that'll be on the top of the stack
|
||||
_digester.addRule(prefix + TileSetRuleSet.TILESET_PATH,
|
||||
_digester.addRule(ruleset.getPath(),
|
||||
new ValidatedSetNextRule("add", Object.class,
|
||||
ruleset));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user