Behold, Nenya, Ring of Water and repository for our media and animation related
goodies, both Java 2D and LWJGL/JME 3D. git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@1 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
//
|
||||
// $Id: SimpleMisoSceneParser.java 3749 2005-11-09 04:00:16Z mdb $
|
||||
//
|
||||
// Narya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
|
||||
// http://www.threerings.net/code/narya/
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Lesser General Public License as published
|
||||
// by the Free Software Foundation; either version 2.1 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package com.threerings.miso.tools.xml;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.FileInputStream;
|
||||
|
||||
import org.xml.sax.SAXException;
|
||||
import org.apache.commons.digester.Digester;
|
||||
|
||||
import com.samskivert.util.StringUtil;
|
||||
|
||||
import com.threerings.miso.data.SimpleMisoSceneModel;
|
||||
|
||||
/**
|
||||
* A simple class for parsing simple miso scene models.
|
||||
*/
|
||||
public class SimpleMisoSceneParser
|
||||
{
|
||||
/**
|
||||
* Constructs a scene parser that parses scenes with the specified XML
|
||||
* path prefix.
|
||||
*/
|
||||
public SimpleMisoSceneParser (String prefix)
|
||||
{
|
||||
// create and configure our digester
|
||||
_digester = new Digester();
|
||||
|
||||
// create our scene rule set
|
||||
SimpleMisoSceneRuleSet set = new SimpleMisoSceneRuleSet();
|
||||
|
||||
// configure our top-level path prefix
|
||||
if (StringUtil.isBlank(prefix)) {
|
||||
_prefix = set.getOuterElement();
|
||||
} else {
|
||||
_prefix = prefix + "/" + set.getOuterElement();
|
||||
}
|
||||
|
||||
// add the scene rules
|
||||
set.addRuleInstances(_prefix, _digester);
|
||||
|
||||
// add a rule to grab the finished scene model
|
||||
_digester.addSetNext(
|
||||
_prefix, "setScene", SimpleMisoSceneModel.class.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the XML file at the specified path into a scene model
|
||||
* instance.
|
||||
*/
|
||||
public SimpleMisoSceneModel parseScene (String path)
|
||||
throws IOException, SAXException
|
||||
{
|
||||
_model = null;
|
||||
_digester.push(this);
|
||||
_digester.parse(new FileInputStream(path));
|
||||
return _model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the parser once the scene is parsed.
|
||||
*/
|
||||
public void setScene (SimpleMisoSceneModel model)
|
||||
{
|
||||
_model = model;
|
||||
}
|
||||
|
||||
protected String _prefix;
|
||||
protected Digester _digester;
|
||||
protected SimpleMisoSceneModel _model;
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
//
|
||||
// $Id: SimpleMisoSceneRuleSet.java 4191 2006-06-13 22:42:20Z ray $
|
||||
//
|
||||
// Narya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
|
||||
// http://www.threerings.net/code/narya/
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Lesser General Public License as published
|
||||
// by the Free Software Foundation; either version 2.1 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package com.threerings.miso.tools.xml;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import org.xml.sax.Attributes;
|
||||
|
||||
import org.apache.commons.digester.Digester;
|
||||
import org.apache.commons.digester.Rule;
|
||||
|
||||
import com.samskivert.xml.CallMethodSpecialRule;
|
||||
import com.samskivert.xml.SetFieldRule;
|
||||
import com.samskivert.xml.SetPropertyFieldsRule;
|
||||
|
||||
import com.threerings.tools.xml.NestableRuleSet;
|
||||
|
||||
import com.threerings.miso.data.ObjectInfo;
|
||||
import com.threerings.miso.data.SimpleMisoSceneModel;
|
||||
|
||||
/**
|
||||
* Used to parse a {@link SimpleMisoSceneModel} from XML.
|
||||
*/
|
||||
public class SimpleMisoSceneRuleSet implements NestableRuleSet
|
||||
{
|
||||
// documentation inherited from interface
|
||||
public String getOuterElement ()
|
||||
{
|
||||
return SimpleMisoSceneWriter.OUTER_ELEMENT;
|
||||
}
|
||||
|
||||
// documentation inherited from interface
|
||||
public void addRuleInstances (String prefix, Digester dig)
|
||||
{
|
||||
// this creates the appropriate instance when we encounter our
|
||||
// prefix tag
|
||||
dig.addRule(prefix, new Rule() {
|
||||
public void begin (String namespace, String name,
|
||||
Attributes attributes) throws Exception {
|
||||
digester.push(createMisoSceneModel());
|
||||
}
|
||||
public void end (String namespace, String name) throws Exception {
|
||||
digester.pop();
|
||||
}
|
||||
});
|
||||
|
||||
// set up rules to parse and set our fields
|
||||
dig.addRule(prefix + "/width", new SetFieldRule("width"));
|
||||
dig.addRule(prefix + "/height", new SetFieldRule("height"));
|
||||
dig.addRule(prefix + "/viewwidth", new SetFieldRule("vwidth"));
|
||||
dig.addRule(prefix + "/viewheight", new SetFieldRule("vheight"));
|
||||
dig.addRule(prefix + "/base", new SetFieldRule("baseTileIds"));
|
||||
|
||||
dig.addObjectCreate(prefix + "/objects", ArrayList.class.getName());
|
||||
dig.addObjectCreate(prefix + "/objects/object",
|
||||
ObjectInfo.class.getName());
|
||||
dig.addSetNext(prefix + "/objects/object", "add",
|
||||
Object.class.getName());
|
||||
|
||||
dig.addRule(prefix + "/objects/object", new SetPropertyFieldsRule());
|
||||
|
||||
dig.addRule(prefix + "/objects", new CallMethodSpecialRule() {
|
||||
public void parseAndSet (String bodyText, Object target)
|
||||
throws Exception
|
||||
{
|
||||
ArrayList ilist = (ArrayList)target;
|
||||
ArrayList ulist = new ArrayList();
|
||||
SimpleMisoSceneModel model = (SimpleMisoSceneModel)
|
||||
digester.peek(1);
|
||||
|
||||
// filter interesting and uninteresting into two lists
|
||||
for (int ii = 0; ii < ilist.size(); ii++) {
|
||||
ObjectInfo info = (ObjectInfo)ilist.get(ii);
|
||||
if (!info.isInteresting()) {
|
||||
ilist.remove(ii--);
|
||||
ulist.add(info);
|
||||
}
|
||||
}
|
||||
|
||||
// now populate the model
|
||||
SimpleMisoSceneModel.populateObjects(model, ilist, ulist);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected SimpleMisoSceneModel createMisoSceneModel ()
|
||||
{
|
||||
return new SimpleMisoSceneModel(0, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
//
|
||||
// $Id: SimpleMisoSceneWriter.java 3749 2005-11-09 04:00:16Z mdb $
|
||||
//
|
||||
// Narya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
|
||||
// http://www.threerings.net/code/narya/
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Lesser General Public License as published
|
||||
// by the Free Software Foundation; either version 2.1 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package com.threerings.miso.tools.xml;
|
||||
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.helpers.AttributesImpl;
|
||||
|
||||
import com.megginson.sax.DataWriter;
|
||||
import com.samskivert.util.StringUtil;
|
||||
import com.threerings.tools.xml.NestableWriter;
|
||||
|
||||
import com.threerings.miso.data.ObjectInfo;
|
||||
import com.threerings.miso.data.SimpleMisoSceneModel;
|
||||
|
||||
/**
|
||||
* Generates an XML representation of a {@link SimpleMisoSceneModel}.
|
||||
*/
|
||||
public class SimpleMisoSceneWriter implements NestableWriter
|
||||
{
|
||||
/** The element used to enclose scene models written with this
|
||||
* writer. */
|
||||
public static final String OUTER_ELEMENT = "miso";
|
||||
|
||||
// documentation inherited from interface
|
||||
public void write (Object object, DataWriter writer)
|
||||
throws SAXException
|
||||
{
|
||||
SimpleMisoSceneModel model = (SimpleMisoSceneModel)object;
|
||||
writer.startElement(OUTER_ELEMENT);
|
||||
writeSceneData(model, writer);
|
||||
writer.endElement(OUTER_ELEMENT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes just the scene data which is handy for derived classes which
|
||||
* may wish to add their own scene data to the scene output.
|
||||
*/
|
||||
protected void writeSceneData (SimpleMisoSceneModel model,
|
||||
DataWriter writer)
|
||||
throws SAXException
|
||||
{
|
||||
writer.dataElement("width", Integer.toString(model.width));
|
||||
writer.dataElement("height", Integer.toString(model.height));
|
||||
writer.dataElement("viewwidth", Integer.toString(model.vwidth));
|
||||
writer.dataElement("viewheight", Integer.toString(model.vheight));
|
||||
writer.dataElement("base",
|
||||
StringUtil.toString(model.baseTileIds, "", ""));
|
||||
|
||||
// write our uninteresting object tile information
|
||||
writer.startElement("objects");
|
||||
for (int ii = 0; ii < model.objectTileIds.length; ii++) {
|
||||
AttributesImpl attrs = new AttributesImpl();
|
||||
attrs.addAttribute("", "tileId", "", "",
|
||||
String.valueOf(model.objectTileIds[ii]));
|
||||
attrs.addAttribute("", "x", "", "",
|
||||
String.valueOf(model.objectXs[ii]));
|
||||
attrs.addAttribute("", "y", "", "",
|
||||
String.valueOf(model.objectYs[ii]));
|
||||
writer.emptyElement("", "object", "", attrs);
|
||||
}
|
||||
|
||||
// write our uninteresting object tile information
|
||||
for (int ii = 0; ii < model.objectInfo.length; ii++) {
|
||||
ObjectInfo info = model.objectInfo[ii];
|
||||
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);
|
||||
}
|
||||
writer.endElement("objects");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
//
|
||||
// $Id: SparseMisoSceneParser.java 3749 2005-11-09 04:00:16Z mdb $
|
||||
//
|
||||
// Narya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
|
||||
// http://www.threerings.net/code/narya/
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Lesser General Public License as published
|
||||
// by the Free Software Foundation; either version 2.1 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package com.threerings.miso.tools.xml;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.FileInputStream;
|
||||
|
||||
import org.xml.sax.SAXException;
|
||||
import org.apache.commons.digester.Digester;
|
||||
|
||||
import com.samskivert.io.StreamUtil;
|
||||
import com.samskivert.util.StringUtil;
|
||||
|
||||
import com.threerings.miso.data.SparseMisoSceneModel;
|
||||
|
||||
/**
|
||||
* A simple class for parsing simple miso scene models.
|
||||
*/
|
||||
public class SparseMisoSceneParser
|
||||
{
|
||||
/**
|
||||
* Constructs a scene parser that parses scenes with the specified XML
|
||||
* path prefix.
|
||||
*/
|
||||
public SparseMisoSceneParser (String prefix)
|
||||
{
|
||||
// create and configure our digester
|
||||
_digester = new Digester();
|
||||
|
||||
// create our scene rule set
|
||||
SparseMisoSceneRuleSet set = new SparseMisoSceneRuleSet();
|
||||
|
||||
// configure our top-level path prefix
|
||||
if (StringUtil.isBlank(prefix)) {
|
||||
_prefix = set.getOuterElement();
|
||||
} else {
|
||||
_prefix = prefix + "/" + set.getOuterElement();
|
||||
}
|
||||
|
||||
// add the scene rules
|
||||
set.addRuleInstances(_prefix, _digester);
|
||||
|
||||
// add a rule to grab the finished scene model
|
||||
_digester.addSetNext(
|
||||
_prefix, "setScene", SparseMisoSceneModel.class.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the XML file at the specified path into a scene model
|
||||
* instance.
|
||||
*/
|
||||
public SparseMisoSceneModel parseScene (String path)
|
||||
throws IOException, SAXException
|
||||
{
|
||||
_model = null;
|
||||
_digester.push(this);
|
||||
FileInputStream stream = null;
|
||||
try {
|
||||
stream = new FileInputStream(path);
|
||||
_digester.parse(stream);
|
||||
} finally {
|
||||
StreamUtil.close(stream);
|
||||
}
|
||||
return _model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the parser once the scene is parsed.
|
||||
*/
|
||||
public void setScene (SparseMisoSceneModel model)
|
||||
{
|
||||
_model = model;
|
||||
}
|
||||
|
||||
protected String _prefix;
|
||||
protected Digester _digester;
|
||||
protected SparseMisoSceneModel _model;
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
//
|
||||
// $Id: SparseMisoSceneRuleSet.java 4191 2006-06-13 22:42:20Z ray $
|
||||
//
|
||||
// Narya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
|
||||
// http://www.threerings.net/code/narya/
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Lesser General Public License as published
|
||||
// by the Free Software Foundation; either version 2.1 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package com.threerings.miso.tools.xml;
|
||||
|
||||
import org.xml.sax.Attributes;
|
||||
|
||||
import org.apache.commons.digester.Digester;
|
||||
import org.apache.commons.digester.Rule;
|
||||
|
||||
import com.samskivert.xml.SetFieldRule;
|
||||
import com.samskivert.xml.SetPropertyFieldsRule;
|
||||
|
||||
import com.threerings.tools.xml.NestableRuleSet;
|
||||
|
||||
import com.threerings.miso.data.ObjectInfo;
|
||||
import com.threerings.miso.data.SparseMisoSceneModel.Section;
|
||||
import com.threerings.miso.data.SparseMisoSceneModel;
|
||||
|
||||
/**
|
||||
* Used to parse a {@link SparseMisoSceneModel} from XML.
|
||||
*/
|
||||
public class SparseMisoSceneRuleSet implements NestableRuleSet
|
||||
{
|
||||
// documentation inherited from interface
|
||||
public String getOuterElement ()
|
||||
{
|
||||
return SparseMisoSceneWriter.OUTER_ELEMENT;
|
||||
}
|
||||
|
||||
// documentation inherited from interface
|
||||
public void addRuleInstances (String prefix, Digester dig)
|
||||
{
|
||||
// this creates the appropriate instance when we encounter our
|
||||
// prefix tag
|
||||
dig.addRule(prefix, new Rule() {
|
||||
public void begin (String namespace, String name,
|
||||
Attributes attributes) throws Exception {
|
||||
digester.push(createMisoSceneModel());
|
||||
}
|
||||
public void end (String namespace, String name) throws Exception {
|
||||
digester.pop();
|
||||
}
|
||||
});
|
||||
|
||||
// set up rules to parse and set our fields
|
||||
dig.addRule(prefix + "/swidth", new SetFieldRule("swidth"));
|
||||
dig.addRule(prefix + "/sheight", new SetFieldRule("sheight"));
|
||||
dig.addRule(prefix + "/defTileSet", new SetFieldRule("defTileSet"));
|
||||
|
||||
String sprefix = prefix + "/sections/section";
|
||||
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());
|
||||
dig.addSetNext(sprefix, "setSection", Section.class.getName());
|
||||
}
|
||||
|
||||
protected SparseMisoSceneModel createMisoSceneModel ()
|
||||
{
|
||||
return new SparseMisoSceneModel();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
//
|
||||
// $Id: SparseMisoSceneWriter.java 3749 2005-11-09 04:00:16Z mdb $
|
||||
//
|
||||
// Narya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
|
||||
// http://www.threerings.net/code/narya/
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Lesser General Public License as published
|
||||
// by the Free Software Foundation; either version 2.1 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package com.threerings.miso.tools.xml;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.helpers.AttributesImpl;
|
||||
|
||||
import com.megginson.sax.DataWriter;
|
||||
import com.samskivert.util.StringUtil;
|
||||
import com.threerings.tools.xml.NestableWriter;
|
||||
|
||||
import com.threerings.miso.data.ObjectInfo;
|
||||
import com.threerings.miso.data.SparseMisoSceneModel.Section;
|
||||
import com.threerings.miso.data.SparseMisoSceneModel;
|
||||
|
||||
/**
|
||||
* Generates an XML representation of a {@link SparseMisoSceneModel}.
|
||||
*/
|
||||
public class SparseMisoSceneWriter implements NestableWriter
|
||||
{
|
||||
/** The element used to enclose scene models written with this
|
||||
* writer. */
|
||||
public static final String OUTER_ELEMENT = "miso";
|
||||
|
||||
// documentation inherited from interface
|
||||
public void write (Object object, DataWriter writer)
|
||||
throws SAXException
|
||||
{
|
||||
SparseMisoSceneModel model = (SparseMisoSceneModel)object;
|
||||
writer.startElement(OUTER_ELEMENT);
|
||||
writeSceneData(model, writer);
|
||||
writer.endElement(OUTER_ELEMENT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes just the scene data which is handy for derived classes which
|
||||
* may wish to add their own scene data to the scene output.
|
||||
*/
|
||||
protected void writeSceneData (SparseMisoSceneModel model,
|
||||
DataWriter writer)
|
||||
throws SAXException
|
||||
{
|
||||
writer.dataElement("swidth", Integer.toString(model.swidth));
|
||||
writer.dataElement("sheight", Integer.toString(model.sheight));
|
||||
writer.dataElement("defTileSet", Integer.toString(model.defTileSet));
|
||||
|
||||
writer.startElement("sections");
|
||||
for (Iterator iter = model.getSections(); iter.hasNext(); ) {
|
||||
Section sect = (Section)iter.next();
|
||||
if (sect.isBlank()) {
|
||||
continue;
|
||||
}
|
||||
AttributesImpl attrs = new AttributesImpl();
|
||||
attrs.addAttribute("", "x", "", "", String.valueOf(sect.x));
|
||||
attrs.addAttribute("", "y", "", "", String.valueOf(sect.y));
|
||||
attrs.addAttribute("", "width", "", "", String.valueOf(sect.width));
|
||||
writer.startElement("", "section", "", attrs);
|
||||
|
||||
writer.dataElement(
|
||||
"base", StringUtil.toString(sect.baseTileIds, "", ""));
|
||||
|
||||
// write our uninteresting object tile information
|
||||
writer.startElement("objects");
|
||||
for (int ii = 0; ii < sect.objectTileIds.length; ii++) {
|
||||
attrs = new AttributesImpl();
|
||||
attrs.addAttribute("", "tileId", "", "",
|
||||
String.valueOf(sect.objectTileIds[ii]));
|
||||
attrs.addAttribute("", "x", "", "",
|
||||
String.valueOf(sect.objectXs[ii]));
|
||||
attrs.addAttribute("", "y", "", "",
|
||||
String.valueOf(sect.objectYs[ii]));
|
||||
writer.emptyElement("", "object", "", attrs);
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
writer.endElement("objects");
|
||||
writer.endElement("section");
|
||||
}
|
||||
writer.endElement("sections");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user