diff --git a/src/java/com/threerings/miso/client/SceneParser.java b/src/java/com/threerings/miso/client/SceneParser.java new file mode 100644 index 000000000..9bb1873e4 --- /dev/null +++ b/src/java/com/threerings/miso/client/SceneParser.java @@ -0,0 +1,22 @@ +// +// $Id: SceneParser.java,v 1.1 2001/07/23 22:45:04 shaper Exp $ + +package com.threerings.miso.scene; + +import java.io.IOException; +import java.util.ArrayList; + +/** + * The SceneParser is a general interface to be implemented by classes + * that load scene descriptions in a particular format from a file. + */ +public interface SceneParser +{ + /** + * Read scene description data from the given file and construct + * Scene objects to suit. Return an ArrayList of all Scene + * objects constructed, or a zero-length array if no scene + * descriptions were fully parsed. + */ + public ArrayList loadScenes (String fname) throws IOException; +} diff --git a/src/java/com/threerings/miso/client/XMLSceneParser.java b/src/java/com/threerings/miso/client/XMLSceneParser.java new file mode 100644 index 000000000..86771b30d --- /dev/null +++ b/src/java/com/threerings/miso/client/XMLSceneParser.java @@ -0,0 +1,17 @@ +// +// $Id: XMLSceneParser.java,v 1.1 2001/07/23 22:45:04 shaper Exp $ + +package com.threerings.miso.scene; + +import java.io.InputStream; +import java.io.IOException; +import java.util.ArrayList; + +public class XMLSceneParser implements SceneParser +{ + public ArrayList loadScenes (InputStream tis) throws IOException + { + // TBD + return null; + } +} diff --git a/src/java/com/threerings/miso/client/XMLSceneWriter.java b/src/java/com/threerings/miso/client/XMLSceneWriter.java new file mode 100644 index 000000000..2fa690f47 --- /dev/null +++ b/src/java/com/threerings/miso/client/XMLSceneWriter.java @@ -0,0 +1,93 @@ +// +// $Id: XMLSceneWriter.java,v 1.1 2001/07/23 22:45:04 shaper Exp $ + +package com.threerings.miso.scene; + +import java.io.*; +import java.util.ArrayList; + +import com.megginson.sax.DataWriter; +import org.xml.sax.*; +import org.xml.sax.helpers.AttributesImpl; + +import com.samskivert.util.StringUtil; +import com.threerings.miso.Log; + +/** + * The XMLSceneWriter writes a list of Scene objects to an XML file + * using Megginson Technologies' XMLWriter class functionality. + */ +public class XMLSceneWriter extends DataWriter +{ + /** + * Construct an XMLSceneWriter object that will be used to write + * the specified set of scenes to an XML file. + * + * @param scenes the scenes to be written. + */ + public XMLSceneWriter (ArrayList scenes) + { + _scenes = scenes; + setIndentStep(2); + } + + /** + * Write the scenes to the specified output file in XML format. + * + * @param fname the absolute pathname of the file to write to. + */ + public void writeToFile (String fname) throws IOException + { + FileOutputStream fos = new FileOutputStream(fname); + setOutput(new OutputStreamWriter(fos)); + + try { + startDocument(); + startElement("scenegroup"); + + int size = _scenes.size(); + for (int ii = 0; ii < size; ii++) { + startElement("scene"); + + Scene scene = (Scene)_scenes.get(ii); + + dataElement("name", scene.getName()); + dataElement("sid", "" + scene.getId()); + dataElement("version", "" + scene.VERSION); + dataElement("hotspots", + StringUtil.toString(scene.getHotSpots())); + dataElement("exits", StringUtil.toString(scene.getExits())); + + startElement("tiles"); + for (int jj = 0; jj < Scene.NUM_LAYERS; jj++) { + AttributesImpl attrs = new AttributesImpl(); + attrs.addAttribute("", "lnum", "", "CDATA", "" + jj); + + startElement("", "layer", "", attrs); + for (int yy = 0; yy < Scene.TILE_HEIGHT; yy++) { + attrs.clear(); + attrs.addAttribute("", "rownum", "", "CDATA", "" + yy); + + startElement("", "row", "", attrs); + // TODO: write row data. + endElement("row"); + } + endElement("layer"); + } + endElement("tiles"); + + endElement("scene"); + } + + endElement("scenegroup"); + endDocument(); + + } catch (SAXException saxe) { + Log.warning("Exception writing scenes to file [fname=" + + fname + ", saxe=" + saxe + "]."); + } + } + + /** The scenes to be written. */ + protected ArrayList _scenes; +}