From c38123f3e2fe9f19daa2ae0599b2cbc85d261d83 Mon Sep 17 00:00:00 2001 From: Walter Korman Date: Thu, 9 Aug 2001 00:01:58 +0000 Subject: [PATCH] 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 --- .../miso/client/SceneRepositoryImpl.java | 9 ++-- .../miso/tools/xml/XMLSceneRepository.java | 46 +++++++++++++++---- tests/rsrc/config/miso/viewer.properties | 4 +- 3 files changed, 43 insertions(+), 16 deletions(-) diff --git a/src/java/com/threerings/miso/client/SceneRepositoryImpl.java b/src/java/com/threerings/miso/client/SceneRepositoryImpl.java index 13ee019a9..51c9839bb 100644 --- a/src/java/com/threerings/miso/client/SceneRepositoryImpl.java +++ b/src/java/com/threerings/miso/client/SceneRepositoryImpl.java @@ -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; @@ -10,10 +10,9 @@ public abstract class SceneRepositoryImpl implements SceneRepository { /** * Initialize the SceneRepository with the given config and tile - * manager objects. The root scene - * directory is read from the given config object, and the tile - * manager is used to obtain tiles when constructing scene objects - * from files. + * manager objects. The root scene directory is read from the + * given config object, and the tile manager is used to obtain + * tiles when constructing scene objects from files. * * @param config the config object. * @param tilemgr the tile manager object. diff --git a/src/java/com/threerings/miso/tools/xml/XMLSceneRepository.java b/src/java/com/threerings/miso/tools/xml/XMLSceneRepository.java index f4cde1cf2..9bef2dcd5 100644 --- a/src/java/com/threerings/miso/tools/xml/XMLSceneRepository.java +++ b/src/java/com/threerings/miso/tools/xml/XMLSceneRepository.java @@ -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; @@ -30,43 +30,71 @@ public class XMLFileSceneRepository extends SceneRepositoryImpl public void init (Config config, TileManager 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); _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 - * specified XML file. + * specified XML file. The filename should be relative to the + * scene root directory. * * @param fname the full pathname to the file. * @return the Scene object. */ 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 - * 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 fname the file to write the scene to. */ 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. */ - protected static final String CFG_ROOT = "miso.sceneroot"; + protected static final String CFG_SROOT = "miso.sceneroot"; /** 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. */ - protected String _root; + protected String _sceneRoot; + + /** The file separator string. */ + protected String _sep; /** The parser object for reading scenes from files. */ protected XMLSceneParser _parser; diff --git a/tests/rsrc/config/miso/viewer.properties b/tests/rsrc/config/miso/viewer.properties index d04ec3588..14f0ba587 100644 --- a/tests/rsrc/config/miso/viewer.properties +++ b/tests/rsrc/config/miso/viewer.properties @@ -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. # -default_scene = /home/shaper/workspace/cocktail/rsrc/scenes/default.xml +default_scene = default.xml