More scene and spot scene refactoring. Got parsers working for those in
the new new style (or was that the new new new style). git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@739 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
//
|
||||
// $Id: EditableScene.java,v 1.2 2001/12/04 22:34:04 mdb Exp $
|
||||
// $Id: EditableScene.java,v 1.3 2001/12/05 03:38:09 mdb Exp $
|
||||
|
||||
package com.threerings.whirled.tools;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.threerings.whirled.client.DisplayScene;
|
||||
import com.threerings.whirled.data.SceneModel;
|
||||
|
||||
@@ -53,12 +55,21 @@ public interface EditableScene extends DisplayScene
|
||||
/**
|
||||
* Returns the names of the neighbors of this scene.
|
||||
*/
|
||||
public String[] getNeighborNames ();
|
||||
public ArrayList getNeighborNames ();
|
||||
|
||||
/**
|
||||
* Sets the names of the neighbors of this scene.
|
||||
* Adds a neighbor to this scene. If the neighbor is already listed
|
||||
* among the neighbors, it will not be added again.
|
||||
*/
|
||||
public void setNeighborNames (String[] neighborNames);
|
||||
public void addNeighbor (String neighborName);
|
||||
|
||||
/**
|
||||
* Adds a neighbor to this scene.
|
||||
*
|
||||
* @return true if the neighbor was removed, false if they were not in
|
||||
* the neighbor list.
|
||||
*/
|
||||
public boolean removeNeighbor (String neighborName);
|
||||
|
||||
/**
|
||||
* Implementations must provide an editable scene model that
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
//
|
||||
// $Id: EditableSceneImpl.java,v 1.3 2001/12/04 22:34:04 mdb Exp $
|
||||
// $Id: EditableSceneImpl.java,v 1.4 2001/12/05 03:38:09 mdb Exp $
|
||||
|
||||
package com.threerings.whirled.tools;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.threerings.whirled.client.DisplaySceneImpl;
|
||||
import com.threerings.whirled.data.SceneModel;
|
||||
|
||||
@@ -20,6 +22,15 @@ public class EditableSceneImpl
|
||||
public EditableSceneImpl (EditableSceneModel model)
|
||||
{
|
||||
super(model.sceneModel, null);
|
||||
_emodel = model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an instance that will create and use a blank scene model.
|
||||
*/
|
||||
public EditableSceneImpl ()
|
||||
{
|
||||
this(EditableSceneModel.blankSceneModel());
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
@@ -53,15 +64,23 @@ public class EditableSceneImpl
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public String[] getNeighborNames ()
|
||||
public ArrayList getNeighborNames ()
|
||||
{
|
||||
return _emodel.neighborNames;
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public void setNeighborNames (String[] neighborNames)
|
||||
public void addNeighbor (String neighborName)
|
||||
{
|
||||
_emodel.neighborNames = neighborNames;
|
||||
if (!_emodel.neighborNames.contains(neighborName)) {
|
||||
_emodel.neighborNames.add(neighborName);
|
||||
}
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public boolean removeNeighbor (String neighborName)
|
||||
{
|
||||
return _emodel.neighborNames.remove(neighborName);
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
//
|
||||
// $Id: EditableSceneModel.java,v 1.1 2001/12/04 22:34:04 mdb Exp $
|
||||
// $Id: EditableSceneModel.java,v 1.2 2001/12/05 03:38:09 mdb Exp $
|
||||
|
||||
package com.threerings.whirled.tools;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import com.samskivert.util.StringUtil;
|
||||
|
||||
import com.threerings.whirled.data.SceneModel;
|
||||
|
||||
/**
|
||||
@@ -18,5 +21,56 @@ public class EditableSceneModel
|
||||
public String sceneName;
|
||||
|
||||
/** The human readable name of this scene's neighbors. */
|
||||
public String[] neighborNames;
|
||||
public ArrayList neighborNames;
|
||||
|
||||
/**
|
||||
* Generates a string representation of this scene model.
|
||||
*/
|
||||
public String toString ()
|
||||
{
|
||||
StringBuffer buf = new StringBuffer("[");
|
||||
delegatesToString(buf);
|
||||
toString(buf);
|
||||
return buf.append("]").toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Derived classes override this to tack their <code>toString</code>
|
||||
* data on to the string buffer.
|
||||
*/
|
||||
protected void delegatesToString (StringBuffer buf)
|
||||
{
|
||||
buf.append(sceneModel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Derived classes override this to tack their <code>toString</code>
|
||||
* data on to the string buffer.
|
||||
*/
|
||||
protected void toString (StringBuffer buf)
|
||||
{
|
||||
buf.append(", sceneName=").append(sceneName);
|
||||
buf.append(", neighborNames=").
|
||||
append(StringUtil.toString(neighborNames));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns a blank editable scene model.
|
||||
*/
|
||||
public static EditableSceneModel blankSceneModel ()
|
||||
{
|
||||
EditableSceneModel model = new EditableSceneModel();
|
||||
model.sceneModel = SceneModel.blankSceneModel();
|
||||
populateBlankSceneModel(model);
|
||||
return model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Populates a blank editable scene model with blank values.
|
||||
*/
|
||||
protected static void populateBlankSceneModel (EditableSceneModel model)
|
||||
{
|
||||
model.sceneName = "";
|
||||
model.neighborNames = new ArrayList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
//
|
||||
// $Id: SceneParser.java,v 1.1 2001/12/05 03:38:09 mdb Exp $
|
||||
|
||||
package com.threerings.whirled.tools.xml;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.FileInputStream;
|
||||
|
||||
import org.xml.sax.SAXException;
|
||||
import org.apache.commons.digester.Digester;
|
||||
|
||||
import com.threerings.whirled.tools.EditableScene;
|
||||
import com.threerings.whirled.tools.EditableSceneImpl;
|
||||
|
||||
/**
|
||||
* A simple class for parsing an editable scene instance.
|
||||
*/
|
||||
public class SceneParser
|
||||
{
|
||||
/**
|
||||
* Constructs a scene parser that parses scenes with the specified XML
|
||||
* path prefix. See the {@link SceneRuleSet#SceneRuleSet}
|
||||
* documentation for more information.
|
||||
*/
|
||||
public SceneParser (String prefix)
|
||||
{
|
||||
// create and configure our digester
|
||||
_digester = new Digester();
|
||||
SceneRuleSet set = new SceneRuleSet();
|
||||
set.setPrefix(prefix);
|
||||
_digester.addRuleSet(set);
|
||||
_digester.addSetNext(prefix, "setScene", EditableScene.class.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the XML file at the specified path into an editable scene
|
||||
* instance.
|
||||
*/
|
||||
public EditableScene parseScene (String path)
|
||||
throws IOException, SAXException
|
||||
{
|
||||
_scene = null;
|
||||
_digester.push(this);
|
||||
_digester.parse(new FileInputStream(path));
|
||||
return _scene;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the parser once the scene is parsed.
|
||||
*/
|
||||
public void setScene (EditableScene scene)
|
||||
{
|
||||
_scene = scene;
|
||||
}
|
||||
|
||||
protected Digester _digester;
|
||||
protected EditableScene _scene;
|
||||
}
|
||||
@@ -1,17 +1,16 @@
|
||||
//
|
||||
// $Id: SceneRuleSet.java,v 1.1 2001/11/29 19:31:52 mdb Exp $
|
||||
// $Id: SceneRuleSet.java,v 1.2 2001/12/05 03:38:09 mdb Exp $
|
||||
|
||||
package com.threerings.whirled.tools.xml;
|
||||
|
||||
import org.apache.commons.digester.Digester;
|
||||
import org.apache.commons.digester.RuleSetBase;
|
||||
|
||||
import com.samskivert.xml.SetFieldRule;
|
||||
|
||||
import com.threerings.whirled.data.SceneModel;
|
||||
import com.threerings.whirled.tools.EditableScene;
|
||||
import com.threerings.whirled.tools.EditableSceneImpl;
|
||||
|
||||
/**
|
||||
* Used to parse a {@link SceneModel} from XML.
|
||||
* Used to parse an {@link EditableScene} from XML.
|
||||
*/
|
||||
public class SceneRuleSet extends RuleSetBase
|
||||
{
|
||||
@@ -21,9 +20,9 @@ public class SceneRuleSet extends RuleSetBase
|
||||
* scene in the following XML file:
|
||||
*
|
||||
* <pre>
|
||||
* <scene>
|
||||
* <sceneId>50</sceneId>
|
||||
* <version>50</version>
|
||||
* <scene name="Scene Name" version="3">
|
||||
* <neighbor>North Scene</neighbor>
|
||||
* <neighbor>West Scene</neighbor>
|
||||
* <!-- ... -->
|
||||
* </scene>
|
||||
* </pre>
|
||||
@@ -39,26 +38,21 @@ public class SceneRuleSet extends RuleSetBase
|
||||
*/
|
||||
public void addRuleInstances (Digester digester)
|
||||
{
|
||||
// this creates the appropriate instance when we encounter our
|
||||
// prefix tag
|
||||
digester.addObjectCreate(_prefix, getSceneModelClass().getName());
|
||||
// this creates the appropriate instance when we encounter our tag
|
||||
digester.addObjectCreate(_prefix, getSceneClass().getName());
|
||||
|
||||
// set up rules to parse and set our fields
|
||||
digester.addRule(_prefix + "/sceneId",
|
||||
new SetFieldRule(digester, "sceneId"));
|
||||
digester.addRule(_prefix + "/version",
|
||||
new SetFieldRule(digester, "version"));
|
||||
digester.addRule(_prefix + "/neighborIds",
|
||||
new SetFieldRule(digester, "neighborIds"));
|
||||
digester.addSetProperties(_prefix);
|
||||
digester.addCallMethod(_prefix + "/neighbor", "addNeighbor", 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* This indicates the class (which should derive from {@link
|
||||
* SceneModel}) to be instantiated during the parsing process.
|
||||
* This indicates the class (which should implement {@link
|
||||
* EditableScene}) to be instantiated during the parsing process.
|
||||
*/
|
||||
protected Class getSceneModelClass ()
|
||||
protected Class getSceneClass ()
|
||||
{
|
||||
return SceneModel.class;
|
||||
return EditableSceneImpl.class;
|
||||
}
|
||||
|
||||
/** The prefix at which me match our scenes. */
|
||||
|
||||
Reference in New Issue
Block a user