Altered persistent storage of scenes to be handled by the

SceneRepository.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@117 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Walter Korman
2001-07-24 16:10:19 +00:00
parent 3e5060c7c5
commit 05f3a6aa25
15 changed files with 283 additions and 411 deletions
@@ -0,0 +1,18 @@
//
// $Id: XMLSceneParser.java,v 1.1 2001/07/24 16:10:19 shaper Exp $
package com.threerings.miso.scene.xml;
import java.io.IOException;
import java.util.ArrayList;
import com.threerings.miso.scene.Scene;
public class XMLSceneParser
{
public Scene loadScene (String fname) throws IOException
{
// TBD
return null;
}
}
@@ -0,0 +1,74 @@
//
// $Id: XMLSceneRepository.java,v 1.1 2001/07/24 16:10:19 shaper Exp $
package com.threerings.miso.scene.xml;
import java.io.IOException;
import java.util.ArrayList;
import com.samskivert.util.Config;
import com.threerings.miso.Log;
import com.threerings.miso.scene.Scene;
import com.threerings.miso.scene.SceneRepositoryImpl;
import com.threerings.miso.tile.TileManager;
/**
* The XMLFileSceneRepository provides a mechanism for reading scenes
* from and writing scenes to XML files. These files will comprise
* the template scene files from which actual runtime game scenes will
* be constructed.
*/
public class XMLFileSceneRepository extends SceneRepositoryImpl
{
/**
* Initialize the XMLFileSceneRepository with the given config and
* tile manager objects.
*
* @param config the config object.
* @param tilemgr the tile manager object.
*/
public void init (Config config, TileManager tilemgr)
{
super.init(config, tilemgr);
_root = _config.getValue(CONFIG_ROOT, DEF_ROOT);
}
/**
* Loads and returns a Scene object for the scene described in the
* specified XML file.
*
* @param fname the full pathname to the file.
* @return the Scene object.
*/
public Scene loadScene (String fname) throws IOException
{
return _parser.loadScene(fname);
}
/**
* Writes a scene to the specified file in the scene root
* directory in XML format.
*
* @param scene the scene to save.
* @param fname the file to write the scene to.
*/
public void saveScene (Scene scene, String fname) throws IOException
{
_writer.saveScene(scene, fname);
}
/** The config key for the root scene directory. */
protected static final String CONFIG_ROOT = "miso.sceneroot";
/** The default root scene directory path. */
protected static final String DEF_ROOT = "rsrc/scenes";
/** The root scene directory path. */
protected String _root;
/** The parser object for reading scenes from files. */
protected XMLSceneParser _parser;
/** The writer object for writing scenes to files. */
protected XMLSceneWriter _writer;
}
@@ -0,0 +1,79 @@
//
// $Id: XMLSceneWriter.java,v 1.1 2001/07/24 16:10:19 shaper Exp $
package com.threerings.miso.scene.xml;
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;
import com.threerings.miso.scene.Scene;
/**
* The XMLSceneWriter writes a Scene object to an XML file.
*/
public class XMLSceneWriter extends DataWriter
{
/**
* Construct an XMLSceneWriter object.
*/
public XMLSceneWriter ()
{
setIndentStep(2);
}
/**
* Write the scenes to the specified output file in XML format.
*
* @param fname the file to write to.
*/
public void saveScene (Scene scene, String fname) throws IOException
{
FileOutputStream fos = new FileOutputStream(fname);
setOutput(new OutputStreamWriter(fos));
try {
startDocument();
startElement("scene");
dataElement("name", scene.getName());
dataElement("sid", "" + scene.getId());
dataElement("version", "" + Scene.getVersion());
dataElement("hotspots",
StringUtil.toString(scene.getHotSpots()));
dataElement("exits", StringUtil.toString(scene.getExits()));
startElement("tiles");
for (int jj = 0; jj < Scene.getNumLayers(); jj++) {
AttributesImpl attrs = new AttributesImpl();
attrs.addAttribute("", "lnum", "", "CDATA", "" + jj);
startElement("", "layer", "", attrs);
for (int yy = 0; yy < Scene.getTileHeight(); yy++) {
attrs.clear();
attrs.addAttribute("", "rownum", "", "CDATA", "" + yy);
startElement("", "row", "", attrs);
// TODO: write row data.
endElement("row");
}
endElement("layer");
}
endElement("tiles");
endElement("scene");
endDocument();
} catch (SAXException saxe) {
Log.warning("Exception writing scene to file " +
"[scene=" + scene + ", [fname=" + fname +
", saxe=" + saxe + "].");
}
}
}