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:
@@ -22,8 +22,6 @@
|
||||
package com.threerings.cast.bundle.tools;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
@@ -35,38 +33,37 @@ import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectOutputStream;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
|
||||
import java.util.jar.JarOutputStream;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarOutputStream;
|
||||
import java.util.zip.Deflater;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import org.apache.commons.digester.Digester;
|
||||
import org.apache.tools.ant.BuildException;
|
||||
import org.apache.tools.ant.DirectoryScanner;
|
||||
import org.apache.tools.ant.Task;
|
||||
import org.apache.tools.ant.types.FileSet;
|
||||
|
||||
import com.samskivert.io.PersistenceException;
|
||||
import com.samskivert.util.ComparableArrayList;
|
||||
import com.samskivert.util.FileUtil;
|
||||
import com.samskivert.util.HashIntMap;
|
||||
import com.samskivert.util.Tuple;
|
||||
|
||||
import org.apache.tools.ant.BuildException;
|
||||
import org.apache.tools.ant.DirectoryScanner;
|
||||
import org.apache.tools.ant.Task;
|
||||
import org.apache.tools.ant.types.FileSet;
|
||||
|
||||
import com.threerings.cast.ComponentIDBroker;
|
||||
import com.threerings.cast.StandardActions;
|
||||
import com.threerings.cast.bundle.BundleUtil;
|
||||
import com.threerings.cast.tools.xml.ActionRuleSet;
|
||||
import com.threerings.media.tile.ImageProvider;
|
||||
import com.threerings.media.tile.SimpleCachingImageProvider;
|
||||
import com.threerings.media.tile.TileSet;
|
||||
import com.threerings.media.tile.TrimmedTileSet;
|
||||
import com.threerings.media.tile.tools.xml.SwissArmyTileSetRuleSet;
|
||||
|
||||
import com.threerings.cast.ComponentIDBroker;
|
||||
import com.threerings.cast.StandardActions;
|
||||
import com.threerings.cast.bundle.BundleUtil;
|
||||
import com.threerings.cast.tools.xml.ActionRuleSet;
|
||||
import com.threerings.media.tile.tools.xml.TileSetRuleSet;
|
||||
import com.threerings.media.tile.tools.xml.UniformTileSetRuleSet;
|
||||
|
||||
/**
|
||||
* Ant task for creating component bundles. This task must be configured
|
||||
@@ -400,6 +397,16 @@ public class ComponentBundlerTask extends Task
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures <code>ruleSet</code> and hooks it into <code>digester</code>.
|
||||
*/
|
||||
protected static void addTileSetRuleSet (Digester digester, TileSetRuleSet ruleSet)
|
||||
{
|
||||
ruleSet.setPrefix("actions" + ActionRuleSet.ACTION_PATH);
|
||||
digester.addRuleSet(ruleSet);
|
||||
digester.addSetNext(ruleSet.getPath(), "addTileSet", TileSet.class.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the action tileset definitions and puts them into a hash
|
||||
* map, keyed on action name.
|
||||
@@ -407,14 +414,10 @@ public class ComponentBundlerTask extends Task
|
||||
protected HashMap parseActionTileSets ()
|
||||
{
|
||||
Digester digester = new Digester();
|
||||
SwissArmyTileSetRuleSet srules = new SwissArmyTileSetRuleSet();
|
||||
String aprefix = "actions" + ActionRuleSet.ACTION_PATH;
|
||||
srules.setPrefix(aprefix);
|
||||
|
||||
digester.addRuleSet(srules);
|
||||
digester.addSetProperties(aprefix);
|
||||
digester.addSetNext(aprefix + SwissArmyTileSetRuleSet.TILESET_PATH,
|
||||
"addTileSet", TileSet.class.getName());
|
||||
digester.addSetProperties("actions" + ActionRuleSet.ACTION_PATH);
|
||||
addTileSetRuleSet(digester, new SwissArmyTileSetRuleSet());
|
||||
addTileSetRuleSet(digester, new UniformTileSetRuleSet("/uniformTileset"));
|
||||
|
||||
|
||||
HashMap actsets = new ActionMap();
|
||||
digester.push(actsets);
|
||||
|
||||
@@ -28,30 +28,26 @@ import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectOutputStream;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import java.util.jar.JarOutputStream;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarOutputStream;
|
||||
import java.util.zip.Deflater;
|
||||
|
||||
import org.apache.commons.digester.Digester;
|
||||
import org.apache.tools.ant.BuildException;
|
||||
import org.apache.tools.ant.Task;
|
||||
|
||||
import org.apache.commons.digester.Digester;
|
||||
|
||||
import com.samskivert.util.Tuple;
|
||||
|
||||
import com.threerings.media.tile.TileSet;
|
||||
import com.threerings.media.tile.tools.xml.SwissArmyTileSetRuleSet;
|
||||
|
||||
import com.threerings.cast.ActionSequence;
|
||||
import com.threerings.cast.ComponentClass;
|
||||
import com.threerings.cast.bundle.BundleUtil;
|
||||
|
||||
import com.threerings.cast.tools.xml.ActionRuleSet;
|
||||
import com.threerings.cast.tools.xml.ClassRuleSet;
|
||||
import com.threerings.media.tile.TileSet;
|
||||
import com.threerings.media.tile.tools.xml.SwissArmyTileSetRuleSet;
|
||||
import com.threerings.media.tile.tools.xml.TileSetRuleSet;
|
||||
import com.threerings.media.tile.tools.xml.UniformTileSetRuleSet;
|
||||
|
||||
/**
|
||||
* Ant task for creating metadata bundles, which contain action sequence
|
||||
@@ -150,6 +146,16 @@ public class MetadataBundlerTask extends Task
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures <code>ruleSet</code> and hooks it into <code>digester</code>.
|
||||
*/
|
||||
protected static void addTileSetRuleSet (Digester digester, TileSetRuleSet ruleSet)
|
||||
{
|
||||
ruleSet.setPrefix("actions" + ActionRuleSet.ACTION_PATH);
|
||||
digester.addRuleSet(ruleSet);
|
||||
digester.addSetNext(ruleSet.getPath(), "add", Object.class.getName());
|
||||
}
|
||||
|
||||
protected Tuple parseActions ()
|
||||
throws BuildException
|
||||
{
|
||||
@@ -158,18 +164,13 @@ public class MetadataBundlerTask extends Task
|
||||
ActionRuleSet arules = new ActionRuleSet();
|
||||
arules.setPrefix("actions");
|
||||
digester.addRuleSet(arules);
|
||||
digester.addSetNext("actions" + ActionRuleSet.ACTION_PATH,
|
||||
"add", Object.class.getName());
|
||||
digester.addSetNext("actions" + ActionRuleSet.ACTION_PATH, "add", Object.class.getName());
|
||||
ArrayList actlist = parseList(digester, _actionDef);
|
||||
|
||||
// now go through a second time reading the tileset info
|
||||
digester = new Digester();
|
||||
SwissArmyTileSetRuleSet srules = new SwissArmyTileSetRuleSet();
|
||||
srules.setPrefix("actions" + ActionRuleSet.ACTION_PATH);
|
||||
digester.addRuleSet(srules);
|
||||
digester.addSetNext("actions" + ActionRuleSet.ACTION_PATH +
|
||||
SwissArmyTileSetRuleSet.TILESET_PATH, "add",
|
||||
Object.class.getName());
|
||||
addTileSetRuleSet(digester, new SwissArmyTileSetRuleSet());
|
||||
addTileSetRuleSet(digester, new UniformTileSetRuleSet("/uniformTileset"));
|
||||
ArrayList setlist = parseList(digester, _actionDef);
|
||||
|
||||
// sanity check
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
@@ -45,10 +45,8 @@ public class BaseTileSetRuleSet extends SwissArmyTileSetRuleSet
|
||||
{
|
||||
super.addRuleInstances(digester);
|
||||
|
||||
digester.addRule(
|
||||
_prefix + TILESET_PATH + "/passable", new CallMethodSpecialRule() {
|
||||
public void parseAndSet (String bodyText, Object target)
|
||||
{
|
||||
digester.addRule(_path + "/passable", new CallMethodSpecialRule() {
|
||||
public void parseAndSet (String bodyText, Object target) {
|
||||
int[] values = StringUtil.parseIntArray(bodyText);
|
||||
boolean[] passable = new boolean[values.length];
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
|
||||
Reference in New Issue
Block a user