Fixed up scene loading/saving to use paths relative to the scene root

directory.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@202 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Walter Korman
2001-08-09 00:01:58 +00:00
parent b2d0ddee27
commit c38123f3e2
3 changed files with 43 additions and 16 deletions
@@ -1,5 +1,5 @@
// //
// $Id: SceneRepositoryImpl.java,v 1.1 2001/07/24 16:10:19 shaper Exp $ // $Id: SceneRepositoryImpl.java,v 1.2 2001/08/09 00:01:58 shaper Exp $
package com.threerings.miso.scene; package com.threerings.miso.scene;
@@ -10,10 +10,9 @@ public abstract class SceneRepositoryImpl implements SceneRepository
{ {
/** /**
* Initialize the SceneRepository with the given config and tile * Initialize the SceneRepository with the given config and tile
* manager objects. The root scene * manager objects. The root scene directory is read from the
* directory is read from the given config object, and the tile * given config object, and the tile manager is used to obtain
* manager is used to obtain tiles when constructing scene objects * tiles when constructing scene objects from files.
* from files.
* *
* @param config the config object. * @param config the config object.
* @param tilemgr the tile manager object. * @param tilemgr the tile manager object.
@@ -1,5 +1,5 @@
// //
// $Id: XMLSceneRepository.java,v 1.4 2001/08/02 18:59:00 shaper Exp $ // $Id: XMLSceneRepository.java,v 1.5 2001/08/09 00:01:58 shaper Exp $
package com.threerings.miso.scene.xml; package com.threerings.miso.scene.xml;
@@ -30,43 +30,71 @@ public class XMLFileSceneRepository extends SceneRepositoryImpl
public void init (Config config, TileManager tilemgr) public void init (Config config, TileManager tilemgr)
{ {
super.init(config, tilemgr); super.init(config, tilemgr);
_root = _config.getValue(CFG_ROOT, DEF_ROOT);
// get path-related information
_sep = System.getProperty("file.separator", "/");
_root = System.getProperty("root", "");
_sceneRoot = _config.getValue(CFG_SROOT, DEF_SROOT);
// create the parser and writer objects
_parser = new XMLSceneParser(_tilemgr); _parser = new XMLSceneParser(_tilemgr);
_writer = new XMLSceneWriter(); _writer = new XMLSceneWriter();
} }
/**
* Return the path to the scene root directory.
*/
public String getScenePath ()
{
return _root + _sep + _sceneRoot + _sep;
}
/** /**
* Loads and returns a Scene object for the scene described in the * Loads and returns a Scene object for the scene described in the
* specified XML file. * specified XML file. The filename should be relative to the
* scene root directory.
* *
* @param fname the full pathname to the file. * @param fname the full pathname to the file.
* @return the Scene object. * @return the Scene object.
*/ */
public Scene loadScene (String fname) throws IOException public Scene loadScene (String fname) throws IOException
{ {
return _parser.loadScene(fname); String path = getScenePath() + fname;
Log.info("Loading scene [path=" + path + "].");
return _parser.loadScene(path);
} }
/** /**
* Writes a scene to the specified file in the scene root * Writes a scene to the specified file in the scene root
* directory in XML format. * directory in XML format. The filename should be relative to
* the scene root directory.
* *
* @param scene the scene to save. * @param scene the scene to save.
* @param fname the file to write the scene to. * @param fname the file to write the scene to.
*/ */
public void saveScene (Scene scene, String fname) throws IOException public void saveScene (Scene scene, String fname) throws IOException
{ {
_writer.saveScene(scene, fname); String path = getScenePath() + fname;
Log.info("Saving scene [path=" + path + "].");
_writer.saveScene(scene, path);
} }
/** The config key for the root scene directory. */ /** The config key for the root scene directory. */
protected static final String CFG_ROOT = "miso.sceneroot"; protected static final String CFG_SROOT = "miso.sceneroot";
/** The default root scene directory path. */ /** The default root scene directory path. */
protected static final String DEF_ROOT = "rsrc/scenes"; protected static final String DEF_SROOT = "rsrc/scenes";
/** The main program absolute root directory. */
protected String _root;
/** The root scene directory path. */ /** The root scene directory path. */
protected String _root; protected String _sceneRoot;
/** The file separator string. */
protected String _sep;
/** The parser object for reading scenes from files. */ /** The parser object for reading scenes from files. */
protected XMLSceneParser _parser; protected XMLSceneParser _parser;
+2 -2
View File
@@ -1,7 +1,7 @@
# #
# $Id: viewer.properties,v 1.1 2001/07/25 17:38:15 shaper Exp $ # $Id: viewer.properties,v 1.2 2001/08/09 00:01:57 shaper Exp $
# #
# Miso scene viewer application config values. # Miso scene viewer application config values.
# #
default_scene = /home/shaper/workspace/cocktail/rsrc/scenes/default.xml default_scene = default.xml