Files
narya/src/java/com/threerings/whirled/tools/EditableSceneImpl.java
T
Michael Bayne 2c27824718 Sweet Mary, mother of Jesus! Another fucking refactor. It turns out that
the way I was doing inheritance between the display and editable scene
implementations was not copacetic. The new method (which is for every
editable scene impl to delegate to a display scene impl so that regardless
of how far along you are on the inheritance chain, there are only ever two
actual objects, the display impl and the editable impl) is somewhat
cleaner, but makes it clear that no method can work as nicely as it would
were we to have mutliple inheritance.

The basic problem is that the editable versions of the scenes have to be
able to manipulate the instance variables in the display versions of the
scenes because they have to keep them up to date so that they are
displaying the right thing. As the editable versions are in different
packages, they don't have access to the display instance variables, so the
display versions simply have to make available enough "editable"
functionality to allow the editable versions to get their job done. It's
more coupling that I'd like, but at least it's only between the display
and editable versions across the inheritance hierarchy rather than down
the hierarchy.

Blah.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@745 542714f4-19e9-0310-aa3c-eee0fc999fb1
2001-12-05 08:45:06 +00:00

136 lines
3.2 KiB
Java

//
// $Id: EditableSceneImpl.java,v 1.5 2001/12/05 08:45:06 mdb Exp $
package com.threerings.whirled.tools;
import java.util.ArrayList;
import com.threerings.crowd.data.PlaceConfig;
import com.threerings.whirled.client.DisplaySceneImpl;
import com.threerings.whirled.data.SceneModel;
/**
* A basic implementation of the {@link EditableScene} interface.
*/
public class EditableSceneImpl implements EditableScene
{
/**
* Creates an instance that will create and use a blank scene model.
*/
public EditableSceneImpl ()
{
this(EditableSceneModel.blankSceneModel());
}
/**
* Creates an instance that will obtain data from the supplied scene
* model and update it when changes are made.
*/
public EditableSceneImpl (EditableSceneModel model)
{
this(model, new DisplaySceneImpl(model.sceneModel, null));
}
/**
* Creates an instance that will obtain data from the supplied scene
* model and update it when changes are made. It will delegate to the
* supplied display scene instead of creating its own delegate.
*/
public EditableSceneImpl (
EditableSceneModel model, DisplaySceneImpl delegate)
{
_model = model.sceneModel;
_emodel = model;
_delegate = delegate;
}
// documentation inherited
public int getId ()
{
return _delegate.getId();
}
// documentation inherited
public int getVersion ()
{
return _delegate.getVersion();
}
// documentation inherited
public int[] getNeighborIds ()
{
return _delegate.getNeighborIds();
}
// documentation inherited
public PlaceConfig getPlaceConfig ()
{
return _delegate.getPlaceConfig();
}
// documentation inherited
public void setId (int sceneId)
{
_model.sceneId = sceneId;
}
// documentation inherited
public void setVersion (int version)
{
_model.version = version;
}
// documentation inherited
public void setNeighborIds (int[] neighborIds)
{
_model.neighborIds = neighborIds;
}
// documentation inherited
public String getName ()
{
return _emodel.sceneName;
}
// documentation inherited
public void setName (String name)
{
_emodel.sceneName = name;
}
// documentation inherited
public ArrayList getNeighborNames ()
{
return _emodel.neighborNames;
}
// documentation inherited
public void addNeighbor (String neighborName)
{
if (!_emodel.neighborNames.contains(neighborName)) {
_emodel.neighborNames.add(neighborName);
}
}
// documentation inherited
public boolean removeNeighbor (String neighborName)
{
return _emodel.neighborNames.remove(neighborName);
}
// documentation inherited
public EditableSceneModel getSceneModel ()
{
return _emodel;
}
/** A reference to our scene model. */
protected SceneModel _model;
/** A reference to our editable scene model. */
protected EditableSceneModel _emodel;
/** Our display scene delegate. */
protected DisplaySceneImpl _delegate;
}