Bundles! Got all the tileset bundle stuff working and wrote some tests to
inrease my confidence in the use of the word "working". git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@635 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: TileSet.java,v 1.20 2001/11/18 04:09:21 mdb Exp $
|
// $Id: TileSet.java,v 1.21 2001/11/21 02:42:15 mdb Exp $
|
||||||
|
|
||||||
package com.threerings.media.tile;
|
package com.threerings.media.tile;
|
||||||
|
|
||||||
@@ -68,6 +68,14 @@ public abstract class TileSet
|
|||||||
_tilesetImg = null;
|
_tilesetImg = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the path to the composite image used by this tileset.
|
||||||
|
*/
|
||||||
|
public String getImagePath ()
|
||||||
|
{
|
||||||
|
return _imagePath;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the number of tiles in the tileset.
|
* Returns the number of tiles in the tileset.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: TileSetIDBroker.java,v 1.1 2001/11/18 04:09:21 mdb Exp $
|
// $Id: TileSetIDBroker.java,v 1.2 2001/11/21 02:42:15 mdb Exp $
|
||||||
|
|
||||||
package com.threerings.media.tile;
|
package com.threerings.media.tile;
|
||||||
|
|
||||||
@@ -29,4 +29,13 @@ public interface TileSetIDBroker
|
|||||||
*/
|
*/
|
||||||
public int getTileSetID (String tileSetName)
|
public int getTileSetID (String tileSetName)
|
||||||
throws PersistenceException;
|
throws PersistenceException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When the user of a tilset id broker is done obtaining tileset ids,
|
||||||
|
* it must call this method to give the tileset id broker an
|
||||||
|
* opportunity to flush any newly created tileset ids back to its
|
||||||
|
* persistent store.
|
||||||
|
*/
|
||||||
|
public void commit ()
|
||||||
|
throws PersistenceException;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: BundledTileSetRepository.java,v 1.1 2001/11/20 03:47:38 mdb Exp $
|
// $Id: BundledTileSetRepository.java,v 1.2 2001/11/21 02:42:15 mdb Exp $
|
||||||
|
|
||||||
package com.threerings.media.tile.bundle;
|
package com.threerings.media.tile.bundle;
|
||||||
|
|
||||||
@@ -59,13 +59,10 @@ public class BundledTileSetRepository
|
|||||||
InputStream tbin = rbundles[i].getResource(METADATA_PATH);
|
InputStream tbin = rbundles[i].getResource(METADATA_PATH);
|
||||||
ObjectInputStream oin = new ObjectInputStream(
|
ObjectInputStream oin = new ObjectInputStream(
|
||||||
new BufferedInputStream(tbin));
|
new BufferedInputStream(tbin));
|
||||||
TileSetBundle[] tsb = (TileSetBundle[])oin.readObject();
|
TileSetBundle tsb = (TileSetBundle)oin.readObject();
|
||||||
|
// initialize the bundle and add it to the list
|
||||||
// add these to the big fat list and initialize them
|
tsb.init(rbundles[i]);
|
||||||
for (int t = 0; t < tsb.length; t++) {
|
tbundles.add(tsb);
|
||||||
tsb[t].init(rbundles[i]);
|
|
||||||
tbundles.add(tsb[t]);
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.warning("Unable to load tileset bundles from resource " +
|
Log.warning("Unable to load tileset bundles from resource " +
|
||||||
|
|||||||
@@ -0,0 +1,301 @@
|
|||||||
|
//
|
||||||
|
// $Id: TileSetBundler.java,v 1.1 2001/11/21 02:42:15 mdb Exp $
|
||||||
|
|
||||||
|
package com.threerings.media.tools.tile.bundle;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.ObjectOutputStream;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
import java.util.jar.JarEntry;
|
||||||
|
import java.util.jar.JarOutputStream;
|
||||||
|
import java.util.jar.Manifest;
|
||||||
|
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
import org.apache.commons.digester.Digester;
|
||||||
|
import org.apache.commons.digester.Rule;
|
||||||
|
import org.apache.commons.digester.RuleSetBase;
|
||||||
|
|
||||||
|
import org.apache.commons.util.StreamUtils;
|
||||||
|
|
||||||
|
import com.samskivert.io.NestableIOException;
|
||||||
|
import com.samskivert.io.PersistenceException;
|
||||||
|
|
||||||
|
import com.threerings.media.Log;
|
||||||
|
import com.threerings.media.tile.TileSet;
|
||||||
|
import com.threerings.media.tile.TileSetIDBroker;
|
||||||
|
import com.threerings.media.tile.bundle.BundledTileSetRepository;
|
||||||
|
import com.threerings.media.tile.bundle.TileSetBundle;
|
||||||
|
import com.threerings.media.tools.tile.xml.TileSetRuleSet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The tileset bundler is used to create tileset bundles from a set of XML
|
||||||
|
* tileset descriptions in a bundle description file. The bundles contain
|
||||||
|
* a serialized representation of the tileset objects along with the
|
||||||
|
* actual image files referenced by those tilesets.
|
||||||
|
*
|
||||||
|
* <p> The organization of the bundle description file is customizable
|
||||||
|
* based on the an XML configuration file provided to the tileset bundler
|
||||||
|
* when constructed. The bundler configuration maps XML paths to tileset
|
||||||
|
* parsers. An example configuration follows:
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* <bundler-config>
|
||||||
|
* <mapping>
|
||||||
|
* <path>bundle.tilesets.uniform</path>
|
||||||
|
* <ruleset>
|
||||||
|
* com.threerings.media.tools.tile.xml.UniformTileSetRuleSet
|
||||||
|
* </ruleset>
|
||||||
|
* </mapping>
|
||||||
|
* <mapping>
|
||||||
|
* <path>bundle.tilesets.object</path>
|
||||||
|
* <ruleset>
|
||||||
|
* com.threerings.media.tools.tile.xml.ObjectTileSetRuleSet
|
||||||
|
* </ruleset>
|
||||||
|
* </mapping>
|
||||||
|
* </bundler-config>
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* This configuration would be used to parse a bundle description that
|
||||||
|
* looked something like the following:
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* <bundle>
|
||||||
|
* <tilesets>
|
||||||
|
* <uniform>
|
||||||
|
* <tileset>
|
||||||
|
* <!-- ... -->
|
||||||
|
* </tileset>
|
||||||
|
* </uniform>
|
||||||
|
* <object>
|
||||||
|
* <tileset>
|
||||||
|
* <!-- ... -->
|
||||||
|
* </tileset>
|
||||||
|
* </object>
|
||||||
|
* </tilesets>
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* The class specified in the <code>ruleset</code> element must derive
|
||||||
|
* from {@link TileSetRuleSet}. The images that will be included in the
|
||||||
|
* bundle must be in the same directory as the bundle description file and
|
||||||
|
* the tileset descriptions must reference the images without a preceding
|
||||||
|
* path.
|
||||||
|
*/
|
||||||
|
public class TileSetBundler
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Constructs a tileset bundler with the specified path to a bundler
|
||||||
|
* configuration file. The configuration file will be loaded and used
|
||||||
|
* to configure this tileset bundler.
|
||||||
|
*/
|
||||||
|
public TileSetBundler (String configPath)
|
||||||
|
throws IOException
|
||||||
|
{
|
||||||
|
// we parse our configuration with a digester
|
||||||
|
Digester digester = new Digester();
|
||||||
|
|
||||||
|
// push our mappings array onto the stack
|
||||||
|
ArrayList mappings = new ArrayList();
|
||||||
|
digester.push(mappings);
|
||||||
|
|
||||||
|
// create a mapping object for each mapping entry and append it to
|
||||||
|
// our mapping list
|
||||||
|
digester.addObjectCreate("bundler-config/mapping",
|
||||||
|
Mapping.class.getName());
|
||||||
|
digester.addSetNext("bundler-config/mapping",
|
||||||
|
"add", "java.lang.Object");
|
||||||
|
|
||||||
|
// configure each mapping object with the path and ruleset
|
||||||
|
digester.addCallMethod("bundler-config/mapping", "init", 2);
|
||||||
|
digester.addCallParam("bundler-config/mapping/path", 0);
|
||||||
|
digester.addCallParam("bundler-config/mapping/ruleset", 1);
|
||||||
|
|
||||||
|
// now go like the wind
|
||||||
|
FileInputStream fin = new FileInputStream(configPath);
|
||||||
|
try {
|
||||||
|
digester.parse(fin);
|
||||||
|
} catch (SAXException saxe) {
|
||||||
|
String errmsg = "Failure parsing bundler config file.";
|
||||||
|
throw new NestableIOException(errmsg, saxe);
|
||||||
|
}
|
||||||
|
fin.close();
|
||||||
|
|
||||||
|
// create our digester
|
||||||
|
_digester = new Digester();
|
||||||
|
|
||||||
|
// use the mappings we parsed to configure our actual digester
|
||||||
|
int msize = mappings.size();
|
||||||
|
for (int i = 0; i < msize; i++) {
|
||||||
|
Mapping map = (Mapping)mappings.get(i);
|
||||||
|
try {
|
||||||
|
TileSetRuleSet ruleset = (TileSetRuleSet)
|
||||||
|
Class.forName(map.ruleset).newInstance();
|
||||||
|
|
||||||
|
// configure the ruleset
|
||||||
|
ruleset.setPrefix(map.path);
|
||||||
|
// add it to the digester
|
||||||
|
_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");
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
String errmsg = "Unable to create tileset rule set " +
|
||||||
|
"instance [mapping=" + map + "].";
|
||||||
|
throw new NestableIOException(errmsg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a tileset bundle at the location specified by the
|
||||||
|
* <code>targetPath</code> parameter, based on the description
|
||||||
|
* provided via the <code>bundleDesc</code> parameter.
|
||||||
|
*
|
||||||
|
* @param idBroker the tileset id broker that will be used to map
|
||||||
|
* tileset names to tileset ids.
|
||||||
|
* @param bundleDef a file object pointing to the bundle description
|
||||||
|
* file.
|
||||||
|
* @param targetPath the path of the tileset bundle file that will be
|
||||||
|
* created.
|
||||||
|
*
|
||||||
|
* @exception IOException thrown if an error occurs reading, writing
|
||||||
|
* or processing anything.
|
||||||
|
*/
|
||||||
|
public void createBundle (
|
||||||
|
TileSetIDBroker idBroker, File bundleDesc, String targetPath)
|
||||||
|
throws IOException
|
||||||
|
{
|
||||||
|
// stick an array list on the top of the stack into which we will
|
||||||
|
// collect parsed tilesets
|
||||||
|
ArrayList sets = new ArrayList();
|
||||||
|
_digester.push(sets);
|
||||||
|
|
||||||
|
// parse the tilesets
|
||||||
|
FileInputStream fin = new FileInputStream(bundleDesc);
|
||||||
|
try {
|
||||||
|
_digester.parse(fin);
|
||||||
|
} catch (SAXException saxe) {
|
||||||
|
String errmsg = "Failure parsing bundle description file.";
|
||||||
|
throw new NestableIOException(errmsg, saxe);
|
||||||
|
} finally {
|
||||||
|
fin.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
// create a tileset bundle to hold our tilesets
|
||||||
|
TileSetBundle bundle = new TileSetBundle();
|
||||||
|
|
||||||
|
// add all of the parsed tilesets to the tileset bundle
|
||||||
|
try {
|
||||||
|
for (int i = 0; i < sets.size(); i++) {
|
||||||
|
TileSet set = (TileSet)sets.get(i);
|
||||||
|
String name = set.getName();
|
||||||
|
|
||||||
|
// let's be robust
|
||||||
|
if (name == null) {
|
||||||
|
Log.warning("Tileset was parsed, but received no name " +
|
||||||
|
"[set=" + set + "]. Skipping.");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// assign a tilset id to the tileset and bundle it
|
||||||
|
try {
|
||||||
|
int tileSetId = idBroker.getTileSetID(name);
|
||||||
|
bundle.addTileSet(tileSetId, set);
|
||||||
|
} catch (PersistenceException pe) {
|
||||||
|
String errmsg = "Failure obtaining a tileset id for " +
|
||||||
|
"tileset [set=" + set + "].";
|
||||||
|
throw new NestableIOException(errmsg, pe);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// clear out our array list in preparation for another go
|
||||||
|
sets.clear();
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
// before we go, we have to commit our brokered tileset ids
|
||||||
|
// back to the broker's persistent store
|
||||||
|
try {
|
||||||
|
idBroker.commit();
|
||||||
|
} catch (PersistenceException pe) {
|
||||||
|
Log.warning("Failure committing brokered tileset ids " +
|
||||||
|
"back to broker's persistent store " +
|
||||||
|
"[error=" + pe + "].");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// now we have to create the actual bundle file
|
||||||
|
File target = new File(targetPath);
|
||||||
|
FileOutputStream fout = new FileOutputStream(target);
|
||||||
|
Manifest manifest = new Manifest();
|
||||||
|
JarOutputStream jar = new JarOutputStream(fout, manifest);
|
||||||
|
|
||||||
|
try {
|
||||||
|
// first write a serialized representation of the tileset
|
||||||
|
// bundle object to the bundle jar file
|
||||||
|
JarEntry entry = new JarEntry(
|
||||||
|
BundledTileSetRepository.METADATA_PATH);
|
||||||
|
jar.putNextEntry(entry);
|
||||||
|
ObjectOutputStream oout = new ObjectOutputStream(jar);
|
||||||
|
oout.writeObject(bundle);
|
||||||
|
oout.flush();
|
||||||
|
|
||||||
|
// now write all of the image files to the bundle
|
||||||
|
Iterator setiter = bundle.enumerateTileSets();
|
||||||
|
while (setiter.hasNext()) {
|
||||||
|
TileSet set = (TileSet)setiter.next();
|
||||||
|
String imagePath = set.getImagePath();
|
||||||
|
|
||||||
|
// sanity checks
|
||||||
|
if (imagePath == null) {
|
||||||
|
Log.warning("Tileset contains no image path " +
|
||||||
|
"[set=" + set + "]. It ain't gonna work.");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// open the image and pipe it into the jar file
|
||||||
|
File imgfile = new File(bundleDesc.getParent(), imagePath);
|
||||||
|
FileInputStream imgin = new FileInputStream(imgfile);
|
||||||
|
jar.putNextEntry(new JarEntry(imagePath));
|
||||||
|
StreamUtils.pipe(imgin, jar);
|
||||||
|
}
|
||||||
|
|
||||||
|
// finally close up the jar file and call ourself done
|
||||||
|
jar.close();
|
||||||
|
|
||||||
|
} catch (IOException ioe) {
|
||||||
|
// remove the incomplete jar file and rethrow the exception
|
||||||
|
fout.close();
|
||||||
|
target.delete();
|
||||||
|
throw ioe;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Used to parse our configuration. */
|
||||||
|
public static class Mapping
|
||||||
|
{
|
||||||
|
public String path;
|
||||||
|
public String ruleset;
|
||||||
|
|
||||||
|
public void init (String path, String ruleset)
|
||||||
|
{
|
||||||
|
this.path = path;
|
||||||
|
this.ruleset = ruleset;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString ()
|
||||||
|
{
|
||||||
|
return "[path=" + path + ", ruleset=" + ruleset + "]";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The digester we use to parse bundle descriptions. */
|
||||||
|
protected Digester _digester;
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: SwissArmyTileSetRuleSet.java,v 1.3 2001/11/20 04:15:44 mdb Exp $
|
// $Id: SwissArmyTileSetRuleSet.java,v 1.4 2001/11/21 02:42:15 mdb Exp $
|
||||||
|
|
||||||
package com.threerings.media.tools.tile.xml;
|
package com.threerings.media.tools.tile.xml;
|
||||||
|
|
||||||
@@ -36,23 +36,13 @@ import com.threerings.media.tile.SwissArmyTileSet;
|
|||||||
*/
|
*/
|
||||||
public class SwissArmyTileSetRuleSet extends TileSetRuleSet
|
public class SwissArmyTileSetRuleSet extends TileSetRuleSet
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* Constructs a uniform tileset rule set that will match tilesets with
|
|
||||||
* the specified prefix. See the documentation for {@link
|
|
||||||
* TileSetRuleSet#TileSetRuleSet} for more info on matching.
|
|
||||||
*/
|
|
||||||
public SwissArmyTileSetRuleSet (String prefix)
|
|
||||||
{
|
|
||||||
super(prefix);
|
|
||||||
}
|
|
||||||
|
|
||||||
// documentation inherited
|
// documentation inherited
|
||||||
public void addRuleInstances (Digester digester)
|
public void addRuleInstances (Digester digester)
|
||||||
{
|
{
|
||||||
super.addRuleInstances(digester);
|
super.addRuleInstances(digester);
|
||||||
|
|
||||||
digester.addRule(
|
digester.addRule(
|
||||||
_prefix + "/tileset/widths",
|
_prefix + TILESET_PATH + "/widths",
|
||||||
new CallMethodSpecialRule(digester) {
|
new CallMethodSpecialRule(digester) {
|
||||||
public void parseAndSet (String bodyText, Object target)
|
public void parseAndSet (String bodyText, Object target)
|
||||||
{
|
{
|
||||||
@@ -62,7 +52,7 @@ public class SwissArmyTileSetRuleSet extends TileSetRuleSet
|
|||||||
});
|
});
|
||||||
|
|
||||||
digester.addRule(
|
digester.addRule(
|
||||||
_prefix + "/tileset/heights",
|
_prefix + TILESET_PATH + "/heights",
|
||||||
new CallMethodSpecialRule(digester) {
|
new CallMethodSpecialRule(digester) {
|
||||||
public void parseAndSet (String bodyText, Object target)
|
public void parseAndSet (String bodyText, Object target)
|
||||||
{
|
{
|
||||||
@@ -72,7 +62,7 @@ public class SwissArmyTileSetRuleSet extends TileSetRuleSet
|
|||||||
});
|
});
|
||||||
|
|
||||||
digester.addRule(
|
digester.addRule(
|
||||||
_prefix + "/tileset/tileCounts",
|
_prefix + TILESET_PATH + "/tileCounts",
|
||||||
new CallMethodSpecialRule(digester) {
|
new CallMethodSpecialRule(digester) {
|
||||||
public void parseAndSet (String bodyText, Object target)
|
public void parseAndSet (String bodyText, Object target)
|
||||||
{
|
{
|
||||||
@@ -83,10 +73,9 @@ public class SwissArmyTileSetRuleSet extends TileSetRuleSet
|
|||||||
}
|
}
|
||||||
|
|
||||||
// documentation inherited
|
// documentation inherited
|
||||||
protected TileSet createTileSet (Attributes attributes)
|
protected Class getTileSetClass ()
|
||||||
{
|
{
|
||||||
// we use uniform tilesets
|
return SwissArmyTileSet.class;
|
||||||
return new SwissArmyTileSet();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: TileSetRuleSet.java,v 1.3 2001/11/20 04:15:44 mdb Exp $
|
// $Id: TileSetRuleSet.java,v 1.4 2001/11/21 02:42:15 mdb Exp $
|
||||||
|
|
||||||
package com.threerings.media.tools.tile.xml;
|
package com.threerings.media.tools.tile.xml;
|
||||||
|
|
||||||
@@ -18,9 +18,15 @@ import com.threerings.media.tile.TileSet;
|
|||||||
*/
|
*/
|
||||||
public abstract class TileSetRuleSet extends RuleSetBase
|
public abstract class TileSetRuleSet extends RuleSetBase
|
||||||
{
|
{
|
||||||
|
/** The component of the digester path that is appended by the tileset
|
||||||
|
* rule set to match a tileset. This is appended to whatever prefix is
|
||||||
|
* provided to the tileset rule set to obtain the complete XML path to
|
||||||
|
* a matched tileset. */
|
||||||
|
public static final String TILESET_PATH = "/tileset";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a tileset rule set which will match tilesets with the
|
* Instructs the tileset rule set to match tilesets with the supplied
|
||||||
* supplied prefix. For example, passing a prefix of
|
* prefix. For example, passing a prefix of
|
||||||
* <code>tilesets.objectsets</code> will match tilesets in the
|
* <code>tilesets.objectsets</code> will match tilesets in the
|
||||||
* following XML file:
|
* following XML file:
|
||||||
*
|
*
|
||||||
@@ -33,21 +39,14 @@ public abstract class TileSetRuleSet extends RuleSetBase
|
|||||||
* </objectsets>
|
* </objectsets>
|
||||||
* </tilesets>
|
* </tilesets>
|
||||||
* </pre>
|
* </pre>
|
||||||
|
*
|
||||||
|
* This must be called before adding the ruleset to a digester.
|
||||||
*/
|
*/
|
||||||
public TileSetRuleSet (String prefix)
|
public void setPrefix (String prefix)
|
||||||
{
|
{
|
||||||
_prefix = prefix;
|
_prefix = prefix;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Called by the {@link XMLTileSetParser} to initialize this tileset
|
|
||||||
* rule set with the necessary back references to operate properly.
|
|
||||||
*/
|
|
||||||
protected void init (XMLTileSetParser parser)
|
|
||||||
{
|
|
||||||
_parser = parser;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds the necessary rules to the digester to parse our tilesets.
|
* Adds the necessary rules to the digester to parse our tilesets.
|
||||||
* Derived classes should override this method, being sure to call the
|
* Derived classes should override this method, being sure to call the
|
||||||
@@ -59,62 +58,23 @@ public abstract class TileSetRuleSet extends RuleSetBase
|
|||||||
{
|
{
|
||||||
// this creates the appropriate instance when we encounter a
|
// this creates the appropriate instance when we encounter a
|
||||||
// <tileset> tag
|
// <tileset> tag
|
||||||
digester.addRule(_prefix + "/tileset",
|
digester.addObjectCreate(_prefix + TILESET_PATH,
|
||||||
new TileSetCreateRule(digester));
|
getTileSetClass().getName());
|
||||||
|
|
||||||
// grab the name attribute from the <tileset> tag
|
// grab the name attribute from the <tileset> tag
|
||||||
digester.addSetProperties(_prefix + "/tileset");
|
digester.addSetProperties(_prefix + TILESET_PATH);
|
||||||
|
|
||||||
// grab the image path from an element
|
// grab the image path from an element
|
||||||
digester.addCallMethod(
|
digester.addCallMethod(
|
||||||
_prefix + "/tileset/imagePath", "setImagePath", 0);
|
_prefix + TILESET_PATH + "/imagePath", "setImagePath", 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When a <tileset> element is encountered, this method is
|
* A tileset rule set will create tilesets of a particular class,
|
||||||
* called to create a new instance of {@link TileSet}. Though the
|
* which must be provided by the derived class via this method.
|
||||||
* attributes are supplied (in case an attribute is needed to
|
|
||||||
* determine which derived instance of {@link TileSet} to create),
|
|
||||||
* this method should not configure the created tileset object. It
|
|
||||||
* should instead rely on the set properties rule that will be
|
|
||||||
* executed after this object is created or to custom set property
|
|
||||||
* rules registered in {@link #addRuleInstances}.
|
|
||||||
*/
|
*/
|
||||||
protected abstract TileSet createTileSet (Attributes attributes);
|
protected abstract Class getTileSetClass ();
|
||||||
|
|
||||||
/**
|
|
||||||
* Used to process a <tileset> element.
|
|
||||||
*/
|
|
||||||
protected class TileSetCreateRule extends Rule
|
|
||||||
{
|
|
||||||
public TileSetCreateRule (Digester digester)
|
|
||||||
{
|
|
||||||
super(digester);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void begin (Attributes attributes)
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
// pass the torch to the XML parser to create the tileset
|
|
||||||
TileSet set = createTileSet(attributes);
|
|
||||||
// then push it onto the stack
|
|
||||||
digester.push(set);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void end ()
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
// pop the tileset off of the stack
|
|
||||||
TileSet set = (TileSet)digester.pop();
|
|
||||||
// and stick it into our tileset map
|
|
||||||
_parser._tilesets.put(set.getName(), set);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The prefix at which me match our tilesets. */
|
/** The prefix at which me match our tilesets. */
|
||||||
protected String _prefix;
|
protected String _prefix;
|
||||||
|
|
||||||
/** A reference to the XMLTileSetParser on whose behalf we are
|
|
||||||
* parsing. */
|
|
||||||
protected XMLTileSetParser _parser;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: UniformTileSetRuleSet.java,v 1.3 2001/11/20 04:15:44 mdb Exp $
|
// $Id: UniformTileSetRuleSet.java,v 1.4 2001/11/21 02:42:15 mdb Exp $
|
||||||
|
|
||||||
package com.threerings.media.tools.tile.xml;
|
package com.threerings.media.tools.tile.xml;
|
||||||
|
|
||||||
@@ -27,36 +27,25 @@ import com.threerings.media.tile.UniformTileSet;
|
|||||||
*/
|
*/
|
||||||
public class UniformTileSetRuleSet extends TileSetRuleSet
|
public class UniformTileSetRuleSet extends TileSetRuleSet
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* Constructs a uniform tileset rule set that will match tilesets with
|
|
||||||
* the specified prefix. See the documentation for {@link
|
|
||||||
* TileSetRuleSet#TileSetRuleSet} for more info on matching.
|
|
||||||
*/
|
|
||||||
public UniformTileSetRuleSet (String prefix)
|
|
||||||
{
|
|
||||||
super(prefix);
|
|
||||||
}
|
|
||||||
|
|
||||||
// documentation inherited
|
// documentation inherited
|
||||||
public void addRuleInstances (Digester digester)
|
public void addRuleInstances (Digester digester)
|
||||||
{
|
{
|
||||||
super.addRuleInstances(digester);
|
super.addRuleInstances(digester);
|
||||||
|
|
||||||
digester.addCallMethod(
|
digester.addCallMethod(
|
||||||
_prefix + "/tileset/width", "setWidth", 0,
|
_prefix + TILESET_PATH + "/width", "setWidth", 0,
|
||||||
new Class[] { java.lang.Integer.TYPE });
|
new Class[] { java.lang.Integer.TYPE });
|
||||||
digester.addCallMethod(
|
digester.addCallMethod(
|
||||||
_prefix + "/tileset/height", "setHeight", 0,
|
_prefix + TILESET_PATH + "/height", "setHeight", 0,
|
||||||
new Class[] { java.lang.Integer.TYPE });
|
new Class[] { java.lang.Integer.TYPE });
|
||||||
digester.addCallMethod(
|
digester.addCallMethod(
|
||||||
_prefix + "/tileset/tileCount", "setTileCount", 0,
|
_prefix + TILESET_PATH + "/tileCount", "setTileCount", 0,
|
||||||
new Class[] { java.lang.Integer.TYPE });
|
new Class[] { java.lang.Integer.TYPE });
|
||||||
}
|
}
|
||||||
|
|
||||||
// documentation inherited
|
// documentation inherited
|
||||||
protected TileSet createTileSet (Attributes attributes)
|
protected Class getTileSetClass ()
|
||||||
{
|
{
|
||||||
// we use uniform tilesets
|
return UniformTileSet.class;
|
||||||
return new UniformTileSet();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: XMLTileSetParser.java,v 1.2 2001/11/20 04:15:44 mdb Exp $
|
// $Id: XMLTileSetParser.java,v 1.3 2001/11/21 02:42:15 mdb Exp $
|
||||||
|
|
||||||
package com.threerings.media.tools.tile.xml;
|
package com.threerings.media.tools.tile.xml;
|
||||||
|
|
||||||
@@ -7,6 +7,7 @@ import java.io.IOException;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
@@ -17,12 +18,13 @@ import org.apache.commons.digester.Rule;
|
|||||||
import com.samskivert.util.ConfigUtil;
|
import com.samskivert.util.ConfigUtil;
|
||||||
|
|
||||||
import com.threerings.media.Log;
|
import com.threerings.media.Log;
|
||||||
|
import com.threerings.media.tile.TileSet;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse an XML tileset description file and construct tileset objects
|
* Parse an XML tileset description file and construct tileset objects for
|
||||||
* for each valid description. Does not currently perform validation
|
* each valid description. Does not currently perform validation on the
|
||||||
* on the input XML stream, though the parsing code assumes the XML
|
* input XML stream, though the parsing code assumes the XML document is
|
||||||
* document is well-formed.
|
* well-formed.
|
||||||
*/
|
*/
|
||||||
public class XMLTileSetParser
|
public class XMLTileSetParser
|
||||||
{
|
{
|
||||||
@@ -33,38 +35,45 @@ public class XMLTileSetParser
|
|||||||
{
|
{
|
||||||
// create our digester
|
// create our digester
|
||||||
_digester = new Digester();
|
_digester = new Digester();
|
||||||
// _digester.setDebug(10);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a ruleset to be used when parsing tiles. This should be an
|
* Adds a ruleset to be used when parsing tiles. This should be an
|
||||||
* instance of a class derived from {@link TileSetRuleSet} which was
|
* instance of a class derived from {@link TileSetRuleSet}. The prefix
|
||||||
* constructed to match a particular kind of tile at a particular
|
* will be used to configure the ruleset so that it matches elements
|
||||||
* point in the XML hierarchy. For example:
|
* at a particular point in the XML hierarchy. For example:
|
||||||
*
|
*
|
||||||
* <pre>
|
* <pre>
|
||||||
* _parser.addRuleSet(new UniformTileSetRuleSet("tilesets"));
|
* _parser.addRuleSet("tilesets", new UniformTileSetRuleSet());
|
||||||
* </pre>
|
* </pre>
|
||||||
*/
|
*/
|
||||||
public void addRuleSet (TileSetRuleSet ruleset)
|
public void addRuleSet (String prefix, TileSetRuleSet ruleset)
|
||||||
{
|
{
|
||||||
// provide a reference to ourselves to the ruleset
|
// configure the ruleset with the appropriate prefix
|
||||||
ruleset.init(this);
|
ruleset.setPrefix(prefix);
|
||||||
|
|
||||||
// and have it set itself up with the digester
|
// and have it set itself up with the digester
|
||||||
_digester.addRuleSet(ruleset);
|
_digester.addRuleSet(ruleset);
|
||||||
|
|
||||||
|
// 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.addSetNext(prefix + TileSetRuleSet.TILESET_PATH,
|
||||||
|
"add", "java.lang.Object");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads all of the tilesets specified in the supplied XML tileset
|
* Loads all of the tilesets specified in the supplied XML tileset
|
||||||
* description file and places them into the supplied hashmap indexed
|
* description file and places them into the supplied hashmap indexed
|
||||||
* by tileset name.
|
* by tileset name. This method is not reentrant, so don't go calling
|
||||||
|
* it from multiple threads.
|
||||||
*/
|
*/
|
||||||
public void loadTileSets (String path, HashMap tilesets)
|
public void loadTileSets (String path, HashMap tilesets)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
// save off the tileset hashtable
|
// stick an array list on the top of the stack for collecting
|
||||||
_tilesets = tilesets;
|
// parsed tilesets
|
||||||
|
ArrayList setlist = new ArrayList();
|
||||||
|
_digester.push(setlist);
|
||||||
|
|
||||||
// get an input stream for this XML file
|
// get an input stream for this XML file
|
||||||
InputStream is = ConfigUtil.getStream(path);
|
InputStream is = ConfigUtil.getStream(path);
|
||||||
@@ -84,14 +93,24 @@ public class XMLTileSetParser
|
|||||||
"[error=" + saxe + "].");
|
"[error=" + saxe + "].");
|
||||||
Log.logStackTrace(saxe);
|
Log.logStackTrace(saxe);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// stick the tilesets from the list into the hashtable
|
||||||
|
for (int i = 0; i < setlist.size(); i++) {
|
||||||
|
TileSet set = (TileSet)setlist.get(i);
|
||||||
|
if (set.getName() == null) {
|
||||||
|
Log.warning("Tileset did not receive name during " +
|
||||||
|
"parsing process [set=" + set + "].");
|
||||||
|
} else {
|
||||||
|
tilesets.put(set.getName(), set);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// and clear out the list for next time
|
||||||
|
setlist.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Our XML digester. */
|
/** Our XML digester. */
|
||||||
protected Digester _digester;
|
protected Digester _digester;
|
||||||
|
|
||||||
/** The tilesets constructed thus far. */
|
|
||||||
protected HashMap _tilesets;
|
|
||||||
|
|
||||||
/** Default tileset name. */
|
/** Default tileset name. */
|
||||||
protected static final String DEF_NAME = "Untitled";
|
protected static final String DEF_NAME = "Untitled";
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: BaseTileSetRuleSet.java,v 1.3 2001/11/20 04:15:44 mdb Exp $
|
// $Id: BaseTileSetRuleSet.java,v 1.4 2001/11/21 02:42:15 mdb Exp $
|
||||||
|
|
||||||
package com.threerings.miso.tools.tile.xml;
|
package com.threerings.miso.tools.tile.xml;
|
||||||
|
|
||||||
@@ -28,16 +28,6 @@ import com.threerings.miso.tile.MisoTileSet;
|
|||||||
*/
|
*/
|
||||||
public class MisoTileSetRuleSet extends SwissArmyTileSetRuleSet
|
public class MisoTileSetRuleSet extends SwissArmyTileSetRuleSet
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* Constructs a uniform tileset rule set that will match tilesets with
|
|
||||||
* the specified prefix. See the documentation for {@link
|
|
||||||
* TileSetRuleSet#TileSetRuleSet} for more info on matching.
|
|
||||||
*/
|
|
||||||
public MisoTileSetRuleSet (String prefix)
|
|
||||||
{
|
|
||||||
super(prefix);
|
|
||||||
}
|
|
||||||
|
|
||||||
// documentation inherited
|
// documentation inherited
|
||||||
public void addRuleInstances (Digester digester)
|
public void addRuleInstances (Digester digester)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
#
|
||||||
|
# $Id: manager.properties,v 1.1 2001/11/21 02:42:16 mdb Exp $
|
||||||
|
#
|
||||||
|
# Test resource manager configuration
|
||||||
|
|
||||||
|
# used to test the BundledTileSetRepository
|
||||||
|
resource.set.bundle_test = rsrc/media/tools/tile/bundle.jar
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 155 KiB |
@@ -0,0 +1,39 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
|
||||||
|
<!-- test tileset bundle -->
|
||||||
|
<bundle>
|
||||||
|
<uniform>
|
||||||
|
<tileset name="Node Icons">
|
||||||
|
<imagePath>node-icons.png</imagePath>
|
||||||
|
<width>16</width>
|
||||||
|
<height>16</height>
|
||||||
|
<tileCount>8</tileCount>
|
||||||
|
</tileset>
|
||||||
|
</uniform>
|
||||||
|
|
||||||
|
<swissarmy>
|
||||||
|
<tileset name="Fringe">
|
||||||
|
<imagePath>fringe.png</imagePath>
|
||||||
|
<heights>48, 48, 48, 48, 48</heights>
|
||||||
|
<widths>64, 64, 64, 64, 64</widths>
|
||||||
|
<tileCounts>8, 8, 8, 8, 8</tileCounts>
|
||||||
|
</tileset>
|
||||||
|
</swissarmy>
|
||||||
|
|
||||||
|
<object>
|
||||||
|
<tileset name="Building">
|
||||||
|
<imagePath>building.png</imagePath>
|
||||||
|
<heights>293</heights>
|
||||||
|
<widths>224</widths>
|
||||||
|
<tileCounts>4</tileCounts>
|
||||||
|
<offsetPos>2, 2</offsetPos>
|
||||||
|
<gapDist>4, 0</gapDist>
|
||||||
|
<objects>
|
||||||
|
<object tid="0" width="4" height="3"/>
|
||||||
|
<object tid="1" width="3" height="4"/>
|
||||||
|
<object tid="2" width="4" height="3"/>
|
||||||
|
<object tid="3" width="3" height="4"/>
|
||||||
|
</objects>
|
||||||
|
</tileset>
|
||||||
|
</object>
|
||||||
|
</bundle>
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
|
||||||
|
<!-- test configuration for the tileset bundler -->
|
||||||
|
<bundler-config>
|
||||||
|
<mapping>
|
||||||
|
<path>bundle/uniform</path>
|
||||||
|
<ruleset>com.threerings.media.tools.tile.xml.UniformTileSetRuleSet</ruleset>
|
||||||
|
</mapping>
|
||||||
|
<mapping>
|
||||||
|
<path>bundle/swissarmy</path>
|
||||||
|
<ruleset>
|
||||||
|
com.threerings.media.tools.tile.xml.SwissArmyTileSetRuleSet
|
||||||
|
</ruleset>
|
||||||
|
</mapping>
|
||||||
|
<!--
|
||||||
|
<mapping>
|
||||||
|
<path>bundle/object</path>
|
||||||
|
<ruleset>com.threerings.media.tools.tile.xml.ObjectTileSetRuleSet</ruleset>
|
||||||
|
</mapping>
|
||||||
|
-->
|
||||||
|
</bundler-config>
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 14 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 369 B |
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: TestApp.java,v 1.5 2001/11/18 04:09:20 mdb Exp $
|
// $Id: TestApp.java,v 1.6 2001/11/21 02:42:16 mdb Exp $
|
||||||
|
|
||||||
package com.threerings.cast.tools.builder;
|
package com.threerings.cast.tools.builder;
|
||||||
|
|
||||||
@@ -29,7 +29,7 @@ public class TestApp
|
|||||||
// create the handles on our various services
|
// create the handles on our various services
|
||||||
_config = MisoUtil.createConfig();
|
_config = MisoUtil.createConfig();
|
||||||
|
|
||||||
ResourceManager rsrcmgr = new ResourceManager("rsrc");
|
ResourceManager rsrcmgr = new ResourceManager(null, "rsrc");
|
||||||
|
|
||||||
// TBD: sort out component repository
|
// TBD: sort out component repository
|
||||||
ComponentRepository crepo = null;
|
ComponentRepository crepo = null;
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
//
|
||||||
|
// $Id: BundledTileSetRepositoryTest.java,v 1.1 2001/11/21 02:42:16 mdb Exp $
|
||||||
|
|
||||||
|
package com.threerings.media.tile.bundle;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
|
import com.threerings.resource.ResourceManager;
|
||||||
|
|
||||||
|
public class BundledTileSetRepositoryTest
|
||||||
|
{
|
||||||
|
public static void main (String[] args)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
ResourceManager rmgr = new ResourceManager(null, "rsrc");
|
||||||
|
BundledTileSetRepository repo =
|
||||||
|
new BundledTileSetRepository(rmgr, "bundle_test");
|
||||||
|
Iterator sets = repo.enumerateTileSets();
|
||||||
|
while (sets.hasNext()) {
|
||||||
|
System.out.println(sets.next());
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
//
|
||||||
|
// $Id: BuildTestTileSetBundle.java,v 1.1 2001/11/21 02:42:16 mdb Exp $
|
||||||
|
|
||||||
|
package com.threerings.media.tools.tile.bundle;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import junit.framework.Test;
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
import com.samskivert.io.PersistenceException;
|
||||||
|
import com.samskivert.test.TestUtil;
|
||||||
|
|
||||||
|
import com.threerings.media.tile.TileSetIDBroker;
|
||||||
|
|
||||||
|
public class TileSetBundlerTest
|
||||||
|
{
|
||||||
|
public static void main (String[] args)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
TileSetIDBroker broker = new DummyTileSetIDBroker();
|
||||||
|
|
||||||
|
// sort out some paths
|
||||||
|
String configPath = TestUtil.getResourcePath(CONFIG_PATH);
|
||||||
|
String descPath = TestUtil.getResourcePath(BUNDLE_DESC_PATH);
|
||||||
|
String targetPath = TestUtil.getResourcePath(TARGET_PATH);
|
||||||
|
|
||||||
|
// create our bundler and get going
|
||||||
|
TileSetBundler bundler = new TileSetBundler(configPath);
|
||||||
|
File descFile = new File(descPath);
|
||||||
|
bundler.createBundle(broker, descFile, targetPath);
|
||||||
|
|
||||||
|
} catch (IOException ioe) {
|
||||||
|
ioe.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Dummy tileset id broker that makes up tileset ids (which are
|
||||||
|
* consistent in the course of execution of the application, but not
|
||||||
|
* between invocations). */
|
||||||
|
protected static class DummyTileSetIDBroker
|
||||||
|
extends HashMap
|
||||||
|
implements TileSetIDBroker
|
||||||
|
{
|
||||||
|
public int getTileSetID (String tileSetName)
|
||||||
|
throws PersistenceException
|
||||||
|
{
|
||||||
|
Integer id = (Integer)get(tileSetName);
|
||||||
|
if (id == null) {
|
||||||
|
id = new Integer(++_nextId);
|
||||||
|
put(tileSetName, id);
|
||||||
|
}
|
||||||
|
return id.intValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void commit ()
|
||||||
|
throws PersistenceException
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
protected int _nextId;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static final String CONFIG_PATH =
|
||||||
|
"media/tools/tile/bundle/bundler-config.xml";
|
||||||
|
|
||||||
|
protected static final String BUNDLE_DESC_PATH =
|
||||||
|
"media/tools/tile/bundle/bundle.xml";
|
||||||
|
|
||||||
|
protected static final String TARGET_PATH =
|
||||||
|
"media/tools/tile/bundle.jar";
|
||||||
|
}
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
//
|
||||||
|
// $Id: XMLTileSetParserTest.java,v 1.1 2001/11/21 02:42:16 mdb Exp $
|
||||||
|
|
||||||
|
package com.threerings.media.tools.tile.xml;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import junit.framework.Test;
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
public class XMLTileSetParserTest extends TestCase
|
||||||
|
{
|
||||||
|
public XMLTileSetParserTest ()
|
||||||
|
{
|
||||||
|
super(XMLTileSetParserTest.class.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void runTest ()
|
||||||
|
{
|
||||||
|
HashMap sets = new HashMap();
|
||||||
|
|
||||||
|
XMLTileSetParser parser = new XMLTileSetParser();
|
||||||
|
// add some rulesets
|
||||||
|
parser.addRuleSet("tilesets/uniform", new UniformTileSetRuleSet());
|
||||||
|
parser.addRuleSet("tilesets/swissarmy", new SwissArmyTileSetRuleSet());
|
||||||
|
// parser.addRuleSet("tilesets/object", new ObjectTileSetRuleSet());
|
||||||
|
|
||||||
|
// load up the tilesets
|
||||||
|
try {
|
||||||
|
parser.loadTileSets(TILESET_PATH, sets);
|
||||||
|
|
||||||
|
// print them out
|
||||||
|
Iterator iter = sets.values().iterator();
|
||||||
|
while (iter.hasNext()) {
|
||||||
|
System.out.println(iter.next());
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (IOException ioe) {
|
||||||
|
ioe.printStackTrace();
|
||||||
|
fail("loadTileSets() failed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Test suite ()
|
||||||
|
{
|
||||||
|
return new XMLTileSetParserTest();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main (String[] args)
|
||||||
|
{
|
||||||
|
XMLTileSetParserTest test = new XMLTileSetParserTest();
|
||||||
|
test.runTest();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static final String TILESET_PATH =
|
||||||
|
"rsrc/media/tools/tile/xml/tilesets.xml";
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: ViewerApp.java,v 1.15 2001/11/18 04:09:20 mdb Exp $
|
// $Id: ViewerApp.java,v 1.16 2001/11/21 02:42:16 mdb Exp $
|
||||||
|
|
||||||
package com.threerings.miso.viewer;
|
package com.threerings.miso.viewer;
|
||||||
|
|
||||||
@@ -29,7 +29,7 @@ public class ViewerApp
|
|||||||
{
|
{
|
||||||
// we don't need to configure anything
|
// we don't need to configure anything
|
||||||
_config = new Config();
|
_config = new Config();
|
||||||
_rsrcmgr = new ResourceManager("rsrc");
|
_rsrcmgr = new ResourceManager(null, "rsrc");
|
||||||
_tilemgr = new TileManager(_rsrcmgr);
|
_tilemgr = new TileManager(_rsrcmgr);
|
||||||
|
|
||||||
// create the context object
|
// create the context object
|
||||||
|
|||||||
Reference in New Issue
Block a user