Expose the xmlization of ObjectInfo for use by other RuleSets and Writers

git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@443 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
Charlie Groves
2008-03-12 06:10:25 +00:00
parent f3c2097498
commit 2f411f5c2d
2 changed files with 47 additions and 36 deletions
@@ -52,11 +52,11 @@ public class SparseMisoSceneRuleSet implements NestableRuleSet
// this creates the appropriate instance when we encounter our
// prefix tag
dig.addRule(prefix, new Rule() {
public void begin (String namespace, String name,
@Override public void begin (String namespace, String name,
Attributes attributes) throws Exception {
digester.push(createMisoSceneModel());
}
public void end (String namespace, String name) throws Exception {
@Override public void end (String namespace, String name) throws Exception {
digester.pop();
}
});
@@ -70,14 +70,23 @@ public class SparseMisoSceneRuleSet implements NestableRuleSet
dig.addObjectCreate(sprefix, Section.class.getName());
dig.addRule(sprefix, new SetPropertyFieldsRule());
dig.addRule(sprefix + "/base", new SetFieldRule("baseTileIds"));
dig.addObjectCreate(sprefix + "/objects/object",
ObjectInfo.class.getName());
dig.addRule(sprefix + "/objects/object", new SetPropertyFieldsRule());
dig.addSetNext(sprefix + "/objects/object", "addObject",
ObjectInfo.class.getName());
addObjectExtractor(dig, "objects", sprefix, "addObject");
dig.addSetNext(sprefix, "setSection", Section.class.getName());
}
/**
* Adds a set of rules to <code>dig</code> to create an Object info from the element at
* base/type/object and calls <code>methodName</code> on the object on dig's stack.
*/
public static void addObjectExtractor (Digester dig, String type, String base,
String methodName)
{
String prefix = base + "/" + type + "/object";
dig.addObjectCreate(prefix, ObjectInfo.class);
dig.addRule(prefix, new SetPropertyFieldsRule());
dig.addSetNext(prefix, methodName, ObjectInfo.class.getName());
}
protected SparseMisoSceneModel createMisoSceneModel ()
{
return new SparseMisoSceneModel();
@@ -66,8 +66,8 @@ public class SparseMisoSceneWriter implements NestableWriter
writer.dataElement("defTileSet", Integer.toString(model.defTileSet));
writer.startElement("sections");
for (Iterator iter = model.getSections(); iter.hasNext(); ) {
Section sect = (Section)iter.next();
for (Iterator<Section> iter = model.getSections(); iter.hasNext(); ) {
Section sect = iter.next();
if (sect.isBlank()) {
continue;
}
@@ -95,37 +95,39 @@ public class SparseMisoSceneWriter implements NestableWriter
// write our interesting object tile information
for (int ii = 0; ii < sect.objectInfo.length; ii++) {
ObjectInfo info = sect.objectInfo[ii];
attrs = new AttributesImpl();
attrs.addAttribute("", "tileId", "", "",
String.valueOf(info.tileId));
attrs.addAttribute("", "x", "", "", String.valueOf(info.x));
attrs.addAttribute("", "y", "", "", String.valueOf(info.y));
if (!StringUtil.isBlank(info.action)) {
attrs.addAttribute("", "action", "", "", info.action);
}
if (info.priority != 0) {
attrs.addAttribute("", "priority", "", "",
String.valueOf(info.priority));
}
if (info.sx != 0 || info.sy != 0) {
attrs.addAttribute("", "sx", "", "",
String.valueOf(info.sx));
attrs.addAttribute("", "sy", "", "",
String.valueOf(info.sy));
attrs.addAttribute("", "sorient", "", "",
String.valueOf(info.sorient));
}
if (info.zations != 0) {
attrs.addAttribute("", "zations", "", "",
String.valueOf(info.zations));
}
writer.emptyElement("", "object", "", attrs);
writeInterestingObject(sect.objectInfo[ii], writer);
}
writer.endElement("objects");
writer.endElement("section");
}
writer.endElement("sections");
}
/**
* Writes <code>info</code> out to <code>writer</code>.
*/
public static void writeInterestingObject (ObjectInfo info, DataWriter writer)
throws SAXException
{
AttributesImpl attrs = new AttributesImpl();
attrs.addAttribute("", "tileId", "", "", String.valueOf(info.tileId));
attrs.addAttribute("", "x", "", "", String.valueOf(info.x));
attrs.addAttribute("", "y", "", "", String.valueOf(info.y));
if (!StringUtil.isBlank(info.action)) {
attrs.addAttribute("", "action", "", "", info.action);
}
if (info.priority != 0) {
attrs.addAttribute("", "priority", "", "", String.valueOf(info.priority));
}
if (info.sx != 0 || info.sy != 0) {
attrs.addAttribute("", "sx", "", "", String.valueOf(info.sx));
attrs.addAttribute("", "sy", "", "", String.valueOf(info.sy));
attrs.addAttribute("", "sorient", "", "", String.valueOf(info.sorient));
}
if (info.zations != 0) {
attrs.addAttribute("", "zations", "", "", String.valueOf(info.zations));
}
writer.emptyElement("", "object", "", attrs);
}
}