More work on character components.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@579 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: XMLComponentParser.java,v 1.1 2001/10/26 01:17:21 shaper Exp $
|
||||
// $Id: XMLComponentParser.java,v 1.2 2001/10/30 16:16:01 shaper Exp $
|
||||
|
||||
package com.threerings.cast;
|
||||
|
||||
@@ -10,8 +10,16 @@ import org.xml.sax.*;
|
||||
|
||||
import com.samskivert.util.HashIntMap;
|
||||
import com.samskivert.util.StringUtil;
|
||||
import com.samskivert.util.Tuple;
|
||||
import com.samskivert.xml.SimpleParser;
|
||||
|
||||
/**
|
||||
* Parses an XML character component description file and populates
|
||||
* hashtables with component type, component class, and specific
|
||||
* component information. Does not currently perform validation on
|
||||
* the input XML stream, though the parsing code assumes the XML
|
||||
* document is well-formed.
|
||||
*/
|
||||
public class XMLComponentParser extends SimpleParser
|
||||
{
|
||||
// documentation inherited
|
||||
@@ -28,31 +36,52 @@ public class XMLComponentParser extends SimpleParser
|
||||
ct.fps = parseInt(attributes.getValue("fps"));
|
||||
parsePoint(attributes.getValue("origin"), ct.origin);
|
||||
|
||||
Log.info("Parsed component type [ct=" + ct + "].");
|
||||
|
||||
// save the component type
|
||||
_types.put(ct.ctid, ct);
|
||||
|
||||
} else if (qName.equals("class")) {
|
||||
// save off the component class info
|
||||
ComponentClass cclass = new ComponentClass();
|
||||
cclass.clid = parseInt(attributes.getValue("clid"));
|
||||
cclass.name = attributes.getValue("name");
|
||||
cclass.render = parseInt(attributes.getValue("render"));
|
||||
_classes.put(cclass.clid, cclass);
|
||||
|
||||
} else if (qName.equals("component")) {
|
||||
// save off the component info
|
||||
// retrieve the component attributes
|
||||
int cid = parseInt(attributes.getValue("cid"));
|
||||
int ctid = parseInt(attributes.getValue("ctid"));
|
||||
_components.put(cid, new Integer(ctid));
|
||||
int clid = parseInt(attributes.getValue("clid"));
|
||||
|
||||
// output a warning if the component references valid
|
||||
// attributes
|
||||
if (_types.get(ctid) == null) {
|
||||
Log.warning("Component references non-existent type " +
|
||||
"[cid=" + cid + ", ctid=" + ctid + "].");
|
||||
}
|
||||
if (_classes.get(clid) == null) {
|
||||
Log.warning("Component references non-existent class " +
|
||||
"[cid=" + cid + ", clid=" + clid + "].");
|
||||
}
|
||||
|
||||
// save off the component information
|
||||
_components.put(cid, new Tuple(
|
||||
new Integer(ctid), new Integer(clid)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the component descriptions in the given file into {@link
|
||||
* ComponentType} and {@link CharacterComponent} objects in the
|
||||
* given hashtables, respectively, keyed on the type and component
|
||||
* unique id, also respectively.
|
||||
* Loads the component descriptions in the given file into the
|
||||
* given component data hashtables.
|
||||
*/
|
||||
public void loadComponents (
|
||||
String file, HashIntMap types, HashIntMap components)
|
||||
String file, HashIntMap types, HashIntMap classes,
|
||||
HashIntMap components)
|
||||
throws IOException
|
||||
{
|
||||
// save off hashtables for reference while parsing
|
||||
_types = types;
|
||||
_classes = classes;
|
||||
_components = components;
|
||||
|
||||
parseFile(file);
|
||||
@@ -77,4 +106,7 @@ public class XMLComponentParser extends SimpleParser
|
||||
|
||||
/** The hashtable of character components gathered while parsing. */
|
||||
protected HashIntMap _components;
|
||||
|
||||
/** The hashtable of component classes gathered while parsing. */
|
||||
protected HashIntMap _classes;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user