Allow specifying the scene file to load on the command-line.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@329 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Walter Korman
2001-09-05 00:45:27 +00:00
parent 87de9dc3ea
commit 84f2a373cd
5 changed files with 56 additions and 24 deletions
@@ -1,5 +1,5 @@
//
// $Id: ViewerApp.java,v 1.7 2001/08/29 18:41:46 shaper Exp $
// $Id: ViewerApp.java,v 1.8 2001/09/05 00:45:27 shaper Exp $
package com.threerings.miso.viewer;
@@ -24,7 +24,7 @@ public class ViewerApp
/**
* Construct and initialize the ViewerApp object.
*/
public ViewerApp ()
public ViewerApp (String[] args)
{
// create and size the main application frame
_frame = new ViewerFrame();
@@ -33,8 +33,11 @@ public class ViewerApp
// create the handles on our various services
_config = createConfig();
_model = createModel(_config, args);
_tilemgr = MisoUtil.createTileManager(_config, _frame);
_screpo = MisoUtil.createSceneRepository(_config, _tilemgr);
// create the context object
_ctx = new ViewerContextImpl();
// initialize the frame with the now-prepared context
@@ -63,6 +66,15 @@ public class ViewerApp
return config;
}
protected ViewerModel createModel (Config config, String args[])
{
ViewerModel model = new ViewerModel(config);
if (args.length >= 1) {
model.scenefile = args[0];
}
return model;
}
/**
* The implementation of the ViewerContext interface that provides
* handles to the config and manager objects that offer commonly used
@@ -84,6 +96,11 @@ public class ViewerApp
{
return _screpo;
}
public ViewerModel getViewerModel ()
{
return _model;
}
}
/**
@@ -99,7 +116,7 @@ public class ViewerApp
*/
public static void main (String[] args)
{
ViewerApp app = new ViewerApp();
ViewerApp app = new ViewerApp(args);
app.run();
}
@@ -116,6 +133,9 @@ public class ViewerApp
/** The tile manager object. */
protected TileManager _tilemgr;
/** The viewer data model. */
protected ViewerModel _model;
/** The context object. */
protected ViewerContext _ctx;
@@ -1,5 +1,5 @@
//
// $Id: ViewerFrame.java,v 1.16 2001/08/21 19:41:58 mdb Exp $
// $Id: ViewerFrame.java,v 1.17 2001/09/05 00:45:27 shaper Exp $
package com.threerings.miso.viewer;
@@ -44,7 +44,7 @@ class ViewerFrame extends JFrame implements WindowListener
// add the test character sprite to the sprite manager
MultiFrameImage[] anims =
TileUtil.getSpriteFrames(tilemgr, TSID_CHAR);
TileUtil.getAmbulatorySpriteFrames(tilemgr, TSID_CHAR);
AmbulatorySprite sprite = new AmbulatorySprite(300, 300, anims);
sprite.setVelocity(6, 6);
spritemgr.addSprite(sprite);
@@ -1,10 +1,27 @@
//
// $Id: ViewerModel.java,v 1.1 2001/08/29 18:41:46 shaper Exp $
// $Id: ViewerModel.java,v 1.2 2001/09/05 00:45:27 shaper Exp $
package com.threerings.miso.viewer;
import com.samskivert.util.Config;
public class ViewerModel
{
/** The config key prefix for miso viewer properties. */
public static final String CONFIG_KEY = "miso-viewer";
/** The filename of the scene to display. */
public String scenefile;
public ViewerModel (Config config)
{
scenefile = config.getValue(SCENE_KEY, DEF_SCENE);
}
/** The config key to obtain the default scene filename. */
protected static final String SCENE_KEY =
CONFIG_KEY + ".default_scene";
/** The default scene to load and display. */
protected static final String DEF_SCENE = "rsrc/scenes/default.xml";
}
@@ -1,5 +1,5 @@
//
// $Id: ViewerSceneViewPanel.java,v 1.14 2001/08/29 18:41:46 shaper Exp $
// $Id: ViewerSceneViewPanel.java,v 1.15 2001/09/05 00:45:27 shaper Exp $
package com.threerings.miso.viewer;
@@ -49,17 +49,13 @@ public class ViewerSceneViewPanel extends SceneViewPanel
*/
protected void prepareStartingScene ()
{
XMLFileSceneRepository screpo = _ctx.getSceneRepository();
// get the starting scene filename
Config config = _ctx.getConfig();
String fname = config.getValue(SCENE_KEY, DEF_SCENE);
ViewerModel model = _ctx.getViewerModel();
try {
// load and set up the scene
_view.setScene(screpo.loadScene(fname));
XMLFileSceneRepository screpo = _ctx.getSceneRepository();
_view.setScene(screpo.loadScene(model.scenefile));
} catch (IOException ioe) {
Log.warning("Exception loading scene [fname=" + fname +
Log.warning("Exception loading scene [fname=" + model.scenefile +
", ioe=" + ioe + "].");
}
}
@@ -100,13 +96,6 @@ public class ViewerSceneViewPanel extends SceneViewPanel
public void mouseMoved (MouseEvent e) { }
public void mouseDragged (MouseEvent e) { }
/** The config key to obtain the default scene filename. */
protected static final String SCENE_KEY =
ViewerModel.CONFIG_KEY + ".default_scene";
/** The default scene to load and display. */
protected static final String DEF_SCENE = "rsrc/scenes/default.xml";
/** The animation manager. */
AnimationManager _animmgr;
@@ -1,5 +1,5 @@
//
// $Id: ViewerContext.java,v 1.3 2001/08/15 00:10:59 mdb Exp $
// $Id: ViewerContext.java,v 1.4 2001/09/05 00:45:27 shaper Exp $
package com.threerings.miso.viewer.util;
@@ -7,6 +7,7 @@ import com.samskivert.util.Context;
import com.threerings.miso.scene.xml.XMLFileSceneRepository;
import com.threerings.miso.util.MisoContext;
import com.threerings.miso.viewer.ViewerModel;
/**
* A mix-in interface that combines the MisoContext and Context
@@ -18,4 +19,9 @@ public interface ViewerContext extends MisoContext, Context
* Returns the scene repository that we can use to get scenes.
*/
public XMLFileSceneRepository getSceneRepository ();
/**
* Returns the viewer data model.
*/
public ViewerModel getViewerModel ();
}