From 6bbce232b40673b5e465e7fc4dcae494d4e0ccb3 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Thu, 29 Nov 2001 06:36:29 +0000 Subject: [PATCH] Implemented and/or cleaned up the XML scene writers. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@675 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../miso/tools/xml/MisoSceneWriter.java | 26 ++++++-- .../spot/tools/xml/SpotSceneWriter.java | 59 +++++++++++++++++++ .../whirled/tools/xml/SceneWriter.java | 44 ++++++++++++++ 3 files changed, 123 insertions(+), 6 deletions(-) create mode 100644 src/java/com/threerings/whirled/spot/tools/xml/SpotSceneWriter.java create mode 100644 src/java/com/threerings/whirled/tools/xml/SceneWriter.java diff --git a/src/java/com/threerings/miso/tools/xml/MisoSceneWriter.java b/src/java/com/threerings/miso/tools/xml/MisoSceneWriter.java index 4edf4cb39..e75f8c3f7 100644 --- a/src/java/com/threerings/miso/tools/xml/MisoSceneWriter.java +++ b/src/java/com/threerings/miso/tools/xml/MisoSceneWriter.java @@ -1,11 +1,12 @@ // -// $Id: MisoSceneWriter.java,v 1.2 2001/11/20 04:15:44 mdb Exp $ +// $Id: MisoSceneWriter.java,v 1.3 2001/11/29 06:36:28 mdb Exp $ package com.threerings.miso.tools.scene.xml; import org.xml.sax.SAXException; import com.megginson.sax.DataWriter; import com.samskivert.util.StringUtil; + import com.threerings.miso.scene.MisoSceneModel; /** @@ -24,11 +25,24 @@ public class MisoSceneWriter throws SAXException { writer.startElement("miso"); - writer.dataElement("width", Integer.toString(model.width)); - writer.dataElement("height", Integer.toString(model.height)); - writer.dataElement("base", StringUtil.toString(model.baseTileIds)); - writer.dataElement("fringe", StringUtil.toString(model.fringeTileIds)); - writer.dataElement("object", StringUtil.toString(model.objectTileIds)); + writeSceneData(model, writer); writer.endElement("miso"); } + + /** + * 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 (MisoSceneModel model, DataWriter writer) + throws SAXException + { + writer.dataElement("width", Integer.toString(model.width)); + writer.dataElement("height", Integer.toString(model.height)); + writer.dataElement("base", + StringUtil.toString(model.baseTileIds, "", "")); + writer.dataElement("fringe", + StringUtil.toString(model.fringeTileIds, "", "")); + writer.dataElement("object", + StringUtil.toString(model.objectTileIds, "", "")); + } } diff --git a/src/java/com/threerings/whirled/spot/tools/xml/SpotSceneWriter.java b/src/java/com/threerings/whirled/spot/tools/xml/SpotSceneWriter.java new file mode 100644 index 000000000..c72593d83 --- /dev/null +++ b/src/java/com/threerings/whirled/spot/tools/xml/SpotSceneWriter.java @@ -0,0 +1,59 @@ +// +// $Id: SpotSceneWriter.java,v 1.1 2001/11/29 06:36:28 mdb Exp $ + +package com.threerings.whirled.tools.spot.xml; + +import org.xml.sax.SAXException; +import com.megginson.sax.DataWriter; +import com.samskivert.util.StringUtil; + +import com.threerings.whirled.tools.xml.SceneWriter; +import com.threerings.whirled.spot.data.SpotSceneModel; + +/** + * Generates an XML representation of a {@link SpotSceneModel}. + */ +public class SpotSceneWriter extends SceneWriter +{ + /** + * Writes the data for the supplied {@link SceneModel} to the XML + * writer supplied. The writer will already be configured with the + * appropriate indentation level so that this writer can simply output + * its elements and allow the calling code to determine where in the + * greater scene description file the scene data should live. + */ + public void writeScene (SpotSceneModel model, DataWriter writer) + throws SAXException + { + writer.startElement("spot"); + writeSceneData(model, writer); + writer.endElement("spot"); + } + + /** + * 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 (SpotSceneModel model, DataWriter writer) + throws SAXException + { + super.writeSceneData(model, writer); + + writer.dataElement("locationIds", + StringUtil.toString(model.locationIds, "", "")); + writer.dataElement("locationX", + StringUtil.toString(model.locationX, "", "")); + writer.dataElement("locationY", + StringUtil.toString(model.locationY, "", "")); + writer.dataElement("locationOrients", + StringUtil.toString(model.locationOrients, "", "")); + writer.dataElement("locationClusters", + StringUtil.toString(model.locationClusters, "", "")); + writer.dataElement("defaultEntranceId", + Integer.toString(model.defaultEntranceId)); + writer.dataElement("portalIds", + StringUtil.toString(model.portalIds, "", "")); + writer.dataElement("targetLocIds", + StringUtil.toString(model.targetLocIds, "", "")); + } +} diff --git a/src/java/com/threerings/whirled/tools/xml/SceneWriter.java b/src/java/com/threerings/whirled/tools/xml/SceneWriter.java new file mode 100644 index 000000000..7dec3f903 --- /dev/null +++ b/src/java/com/threerings/whirled/tools/xml/SceneWriter.java @@ -0,0 +1,44 @@ +// +// $Id: SceneWriter.java,v 1.1 2001/11/29 06:36:29 mdb Exp $ + +package com.threerings.whirled.tools.xml; + +import org.xml.sax.SAXException; +import com.megginson.sax.DataWriter; +import com.samskivert.util.StringUtil; + +import com.threerings.whirled.data.SceneModel; + +/** + * Generates an XML representation of a {@link SceneModel}. + */ +public class SceneWriter +{ + /** + * Writes the data for the supplied {@link SceneModel} to the XML + * writer supplied. The writer will already be configured with the + * appropriate indentation level so that this writer can simply output + * its elements and allow the calling code to determine where in the + * greater scene description file the scene data should live. + */ + public void writeScene (SceneModel model, DataWriter writer) + throws SAXException + { + writer.startElement("scene"); + writeSceneData(model, writer); + writer.endElement("scene"); + } + + /** + * 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 (SceneModel model, DataWriter writer) + throws SAXException + { + writer.dataElement("sceneId", Integer.toString(model.sceneId)); + writer.dataElement("version", Integer.toString(model.version)); + writer.dataElement("neighborIds", + StringUtil.toString(model.neighborIds, "", "")); + } +}