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:
@@ -52,11 +52,11 @@ public class SparseMisoSceneRuleSet implements NestableRuleSet
|
|||||||
// this creates the appropriate instance when we encounter our
|
// this creates the appropriate instance when we encounter our
|
||||||
// prefix tag
|
// prefix tag
|
||||||
dig.addRule(prefix, new Rule() {
|
dig.addRule(prefix, new Rule() {
|
||||||
public void begin (String namespace, String name,
|
@Override public void begin (String namespace, String name,
|
||||||
Attributes attributes) throws Exception {
|
Attributes attributes) throws Exception {
|
||||||
digester.push(createMisoSceneModel());
|
digester.push(createMisoSceneModel());
|
||||||
}
|
}
|
||||||
public void end (String namespace, String name) throws Exception {
|
@Override public void end (String namespace, String name) throws Exception {
|
||||||
digester.pop();
|
digester.pop();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -70,14 +70,23 @@ public class SparseMisoSceneRuleSet implements NestableRuleSet
|
|||||||
dig.addObjectCreate(sprefix, Section.class.getName());
|
dig.addObjectCreate(sprefix, Section.class.getName());
|
||||||
dig.addRule(sprefix, new SetPropertyFieldsRule());
|
dig.addRule(sprefix, new SetPropertyFieldsRule());
|
||||||
dig.addRule(sprefix + "/base", new SetFieldRule("baseTileIds"));
|
dig.addRule(sprefix + "/base", new SetFieldRule("baseTileIds"));
|
||||||
dig.addObjectCreate(sprefix + "/objects/object",
|
addObjectExtractor(dig, "objects", sprefix, "addObject");
|
||||||
ObjectInfo.class.getName());
|
|
||||||
dig.addRule(sprefix + "/objects/object", new SetPropertyFieldsRule());
|
|
||||||
dig.addSetNext(sprefix + "/objects/object", "addObject",
|
|
||||||
ObjectInfo.class.getName());
|
|
||||||
dig.addSetNext(sprefix, "setSection", Section.class.getName());
|
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 ()
|
protected SparseMisoSceneModel createMisoSceneModel ()
|
||||||
{
|
{
|
||||||
return new SparseMisoSceneModel();
|
return new SparseMisoSceneModel();
|
||||||
|
|||||||
@@ -66,8 +66,8 @@ public class SparseMisoSceneWriter implements NestableWriter
|
|||||||
writer.dataElement("defTileSet", Integer.toString(model.defTileSet));
|
writer.dataElement("defTileSet", Integer.toString(model.defTileSet));
|
||||||
|
|
||||||
writer.startElement("sections");
|
writer.startElement("sections");
|
||||||
for (Iterator iter = model.getSections(); iter.hasNext(); ) {
|
for (Iterator<Section> iter = model.getSections(); iter.hasNext(); ) {
|
||||||
Section sect = (Section)iter.next();
|
Section sect = iter.next();
|
||||||
if (sect.isBlank()) {
|
if (sect.isBlank()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -95,37 +95,39 @@ public class SparseMisoSceneWriter implements NestableWriter
|
|||||||
|
|
||||||
// write our interesting object tile information
|
// write our interesting object tile information
|
||||||
for (int ii = 0; ii < sect.objectInfo.length; ii++) {
|
for (int ii = 0; ii < sect.objectInfo.length; ii++) {
|
||||||
ObjectInfo info = sect.objectInfo[ii];
|
writeInterestingObject(sect.objectInfo[ii], writer);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
writer.endElement("objects");
|
writer.endElement("objects");
|
||||||
writer.endElement("section");
|
writer.endElement("section");
|
||||||
}
|
}
|
||||||
writer.endElement("sections");
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user