A few bits of cleany/fixy.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4150 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Ray Greenwell
2006-05-25 22:51:04 +00:00
parent 86fd2c05ae
commit 9c33f1de53
4 changed files with 46 additions and 48 deletions
@@ -325,7 +325,6 @@ public class ChatDirector extends BasicDirector
return result;
}
trace("Chatted: " + record + ", " + hist[0]);
if (record) {
// get the final history-ready command string
hist[0] = "/" + ((hist[0] == null) ? command : hist[0]);
@@ -21,6 +21,8 @@
package com.threerings.whirled.spot.data {
import com.threerings.util.Cloneable;
import com.threerings.io.Streamable;
import com.threerings.io.ObjectInputStream;
import com.threerings.io.ObjectOutputStream;
@@ -37,7 +39,7 @@ import com.threerings.util.Hashable;
* appear in that target scene.
*/
public class Portal
implements Streamable, Hashable
implements Streamable, Hashable, Cloneable
{
/** This portal's unique identifier. */
public var portalId :int;
@@ -104,9 +106,7 @@ public class Portal
targetPortalId = ins.readShort();
}
/**
* Creates a clone of this instance.
*/
// documentation inherited from interface Cloneable
public function clone () :Object
{
var p :Portal = new Portal();
@@ -21,6 +21,7 @@
package com.threerings.whirled.spot.data {
import com.threerings.util.ArrayIterator;
import com.threerings.util.Iterator;
import com.threerings.util.HashMap;
@@ -34,71 +35,67 @@ public class SpotSceneImpl
* Creates an instance that will obtain data from the supplied spot
* scene model.
*/
public function SpotSceneImpl (model :SpotSceneModel)
public function SpotSceneImpl (model :SpotSceneModel = null)
{
_smodel = smodel;
readPortals();
if (model != null) {
_smodel = model;
readPortals();
} else {
_smodel = new SpotSceneModel();
}
}
protected function readPortals () :void
{
_portals.clear();
for (int ii = 0, ll = _smodel.portals.length; ii < ll; ii++) {
Portal port = _smodel.portals[ii];
for each (var port :Portal in _smodel.portals) {
_portals.put(port.portalId, port);
}
}
/**
* Instantiates a blank scene implementation.
*/
public SpotSceneImpl ()
// documentation inherited from interface
public function getPortal (portalId :int) :Portal
{
_smodel = new SpotSceneModel();
return (_portals.get(portalId) as Portal);
}
// documentation inherited from interface
public Portal getPortal (int portalId)
{
return (Portal)_portals.get(portalId);
}
// documentation inherited from interface
public int getPortalCount ()
public function getPortalCount () :int
{
return _portals.size();
}
// documentation inherited from interface
public Iterator getPortals ()
public function getPortals () :Iterator
{
return _portals.values().iterator();
return new ArrayIterator(_portals.values());
}
// documentation inherited from interface
public short getNextPortalId ()
public function getNextPortalId () :int
{
// compute a new portal id for our friend the portal
for (short ii = 1; ii < MAX_PORTAL_ID; ii++) {
for (var ii :int = 1; ii < MAX_PORTAL_ID; ii++) {
if (!_portals.containsKey(ii)) {
return ii;
}
}
return (short)-1;
return -1;
}
// documentation inherited from interface
public Portal getDefaultEntrance ()
public function getDefaultEntrance () :Portal
{
return getPortal(_smodel.defaultEntranceId);
}
// documentation inherited from interface
public void addPortal (Portal portal)
public function addPortal (portal :Portal) :void
{
if (portal.portalId <= 0) {
Log.warning("Refusing to add zero-id portal " +
"[scene=" + this + ", portal=" + portal + "].");
Log.getLog(this).warning("Refusing to add zero-id portal " +
"[scene=" + this + ", portal=" + portal + "].");
return;
}
@@ -110,7 +107,7 @@ public class SpotSceneImpl
}
// documentation inherited from interface
public void removePortal (Portal portal)
public function removePortal (portal :Portal) :void
{
// remove the portal from our mapping
_portals.remove(portal.portalId);
@@ -122,13 +119,13 @@ public class SpotSceneImpl
/**
* Used when we're being parsed from an XML scene model.
*/
public void setDefaultEntranceId (int defaultEntranceId)
public function setDefaultEntranceId (defaultEntranceId :int) :void
{
_smodel.defaultEntranceId = defaultEntranceId;
}
// documentation inherited from interface
public void setDefaultEntrance (Portal portal)
public function setDefaultEntrance (portal :Portal) :void
{
_smodel.defaultEntranceId = (portal == null) ? -1 : portal.portalId;
}
@@ -137,7 +134,7 @@ public class SpotSceneImpl
* This should be called if a scene update was received that caused
* our underlying scene model to change.
*/
public void updateReceived ()
public function updateReceived () :void
{
readPortals();
}
@@ -21,9 +21,12 @@
package com.threerings.whirled.spot.data {
import com.threerings.util.ClassUtil;
import com.threerings.io.Streamable;
import com.threerings.io.ObjectInputStream;
import com.threerings.io.ObjectOutputStream;
import com.threerings.io.TypedArray;
import com.threerings.whirled.data.AuxModel;
import com.threerings.whirled.data.SceneModel;
@@ -38,7 +41,8 @@ public class SpotSceneModel
implements Streamable, AuxModel
{
/** An array containing all portals in this scene. */
public var portals :TypedArray = new TypedArray(Portal);
public var portals :TypedArray =
new TypedArray(TypedArray.getJavaType(Portal));
/** The portal id of the default entrance to this scene. If a body
* enters the scene without coming from another scene, this is the
@@ -66,16 +70,14 @@ public class SpotSceneModel
}
}
// documentation inherited
public Object clone ()
throws CloneNotSupportedException
// documentation inherited from superinterface Cloneable
public function clone () :Object
{
// TODO
SpotSceneModel model = (SpotSceneModel)super.clone();
// clone our portals individually
model.portals = new Portal[portals.length];
for (int ii = 0, ll = portals.length; ii < ll; ii++) {
model.portals[ii] = (Portal)portals[ii].clone();
var clazz :Class = ClassUtil.getClass(this);
var model :SpotSceneModel = new clazz();
for each (var portal :Portal in portals) {
model.portals.push(portal.clone());
}
return model;
}
@@ -102,9 +104,9 @@ public class SpotSceneModel
*/
public static function getSceneModel (model :SceneModel) :SpotSceneModel
{
for (var ii :int = 0; ii < model.auxModels.length; ii++) {
if (model.auxModels[ii] is SpotSceneModel) {
return (model.auxModels[ii] as SpotSceneModel);
for each (var aux :AuxModel in model.auxModels) {
if (aux is SpotSceneModel) {
return (aux as SpotSceneModel);
}
}
return null;