Initial versions.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@114 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Walter Korman
2001-07-23 22:45:04 +00:00
parent f02475b4c2
commit 98e19f8fac
3 changed files with 132 additions and 0 deletions
@@ -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;
}
@@ -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;
}
}
@@ -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;
}