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; return result;
} }
trace("Chatted: " + record + ", " + hist[0]);
if (record) { if (record) {
// get the final history-ready command string // get the final history-ready command string
hist[0] = "/" + ((hist[0] == null) ? command : hist[0]); hist[0] = "/" + ((hist[0] == null) ? command : hist[0]);
@@ -21,6 +21,8 @@
package com.threerings.whirled.spot.data { package com.threerings.whirled.spot.data {
import com.threerings.util.Cloneable;
import com.threerings.io.Streamable; import com.threerings.io.Streamable;
import com.threerings.io.ObjectInputStream; import com.threerings.io.ObjectInputStream;
import com.threerings.io.ObjectOutputStream; import com.threerings.io.ObjectOutputStream;
@@ -37,7 +39,7 @@ import com.threerings.util.Hashable;
* appear in that target scene. * appear in that target scene.
*/ */
public class Portal public class Portal
implements Streamable, Hashable implements Streamable, Hashable, Cloneable
{ {
/** This portal's unique identifier. */ /** This portal's unique identifier. */
public var portalId :int; public var portalId :int;
@@ -104,9 +106,7 @@ public class Portal
targetPortalId = ins.readShort(); targetPortalId = ins.readShort();
} }
/** // documentation inherited from interface Cloneable
* Creates a clone of this instance.
*/
public function clone () :Object public function clone () :Object
{ {
var p :Portal = new Portal(); var p :Portal = new Portal();
@@ -21,6 +21,7 @@
package com.threerings.whirled.spot.data { package com.threerings.whirled.spot.data {
import com.threerings.util.ArrayIterator;
import com.threerings.util.Iterator; import com.threerings.util.Iterator;
import com.threerings.util.HashMap; import com.threerings.util.HashMap;
@@ -34,71 +35,67 @@ public class SpotSceneImpl
* Creates an instance that will obtain data from the supplied spot * Creates an instance that will obtain data from the supplied spot
* scene model. * scene model.
*/ */
public function SpotSceneImpl (model :SpotSceneModel) public function SpotSceneImpl (model :SpotSceneModel = null)
{ {
_smodel = smodel; if (model != null) {
readPortals(); _smodel = model;
readPortals();
} else {
_smodel = new SpotSceneModel();
}
} }
protected function readPortals () :void protected function readPortals () :void
{ {
_portals.clear(); _portals.clear();
for (int ii = 0, ll = _smodel.portals.length; ii < ll; ii++) { for each (var port :Portal in _smodel.portals) {
Portal port = _smodel.portals[ii];
_portals.put(port.portalId, port); _portals.put(port.portalId, port);
} }
} }
/** // documentation inherited from interface
* Instantiates a blank scene implementation. public function getPortal (portalId :int) :Portal
*/
public SpotSceneImpl ()
{ {
_smodel = new SpotSceneModel(); return (_portals.get(portalId) as Portal);
} }
// documentation inherited from interface // documentation inherited from interface
public Portal getPortal (int portalId) public function getPortalCount () :int
{
return (Portal)_portals.get(portalId);
}
// documentation inherited from interface
public int getPortalCount ()
{ {
return _portals.size(); return _portals.size();
} }
// documentation inherited from interface // documentation inherited from interface
public Iterator getPortals () public function getPortals () :Iterator
{ {
return _portals.values().iterator(); return new ArrayIterator(_portals.values());
} }
// documentation inherited from interface // documentation inherited from interface
public short getNextPortalId () public function getNextPortalId () :int
{ {
// compute a new portal id for our friend the portal // 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)) { if (!_portals.containsKey(ii)) {
return ii; return ii;
} }
} }
return (short)-1; return -1;
} }
// documentation inherited from interface // documentation inherited from interface
public Portal getDefaultEntrance () public function getDefaultEntrance () :Portal
{ {
return getPortal(_smodel.defaultEntranceId); return getPortal(_smodel.defaultEntranceId);
} }
// documentation inherited from interface // documentation inherited from interface
public void addPortal (Portal portal) public function addPortal (portal :Portal) :void
{ {
if (portal.portalId <= 0) { if (portal.portalId <= 0) {
Log.warning("Refusing to add zero-id portal " + Log.getLog(this).warning("Refusing to add zero-id portal " +
"[scene=" + this + ", portal=" + portal + "]."); "[scene=" + this + ", portal=" + portal + "].");
return; return;
} }
@@ -110,7 +107,7 @@ public class SpotSceneImpl
} }
// documentation inherited from interface // documentation inherited from interface
public void removePortal (Portal portal) public function removePortal (portal :Portal) :void
{ {
// remove the portal from our mapping // remove the portal from our mapping
_portals.remove(portal.portalId); _portals.remove(portal.portalId);
@@ -122,13 +119,13 @@ public class SpotSceneImpl
/** /**
* Used when we're being parsed from an XML scene model. * 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; _smodel.defaultEntranceId = defaultEntranceId;
} }
// documentation inherited from interface // documentation inherited from interface
public void setDefaultEntrance (Portal portal) public function setDefaultEntrance (portal :Portal) :void
{ {
_smodel.defaultEntranceId = (portal == null) ? -1 : portal.portalId; _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 * This should be called if a scene update was received that caused
* our underlying scene model to change. * our underlying scene model to change.
*/ */
public void updateReceived () public function updateReceived () :void
{ {
readPortals(); readPortals();
} }
@@ -21,9 +21,12 @@
package com.threerings.whirled.spot.data { package com.threerings.whirled.spot.data {
import com.threerings.util.ClassUtil;
import com.threerings.io.Streamable; import com.threerings.io.Streamable;
import com.threerings.io.ObjectInputStream; import com.threerings.io.ObjectInputStream;
import com.threerings.io.ObjectOutputStream; import com.threerings.io.ObjectOutputStream;
import com.threerings.io.TypedArray;
import com.threerings.whirled.data.AuxModel; import com.threerings.whirled.data.AuxModel;
import com.threerings.whirled.data.SceneModel; import com.threerings.whirled.data.SceneModel;
@@ -38,7 +41,8 @@ public class SpotSceneModel
implements Streamable, AuxModel implements Streamable, AuxModel
{ {
/** An array containing all portals in this scene. */ /** 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 /** The portal id of the default entrance to this scene. If a body
* enters the scene without coming from another scene, this is the * enters the scene without coming from another scene, this is the
@@ -66,16 +70,14 @@ public class SpotSceneModel
} }
} }
// documentation inherited // documentation inherited from superinterface Cloneable
public Object clone () public function clone () :Object
throws CloneNotSupportedException
{ {
// TODO var clazz :Class = ClassUtil.getClass(this);
SpotSceneModel model = (SpotSceneModel)super.clone(); var model :SpotSceneModel = new clazz();
// clone our portals individually
model.portals = new Portal[portals.length]; for each (var portal :Portal in portals) {
for (int ii = 0, ll = portals.length; ii < ll; ii++) { model.portals.push(portal.clone());
model.portals[ii] = (Portal)portals[ii].clone();
} }
return model; return model;
} }
@@ -102,9 +104,9 @@ public class SpotSceneModel
*/ */
public static function getSceneModel (model :SceneModel) :SpotSceneModel public static function getSceneModel (model :SceneModel) :SpotSceneModel
{ {
for (var ii :int = 0; ii < model.auxModels.length; ii++) { for each (var aux :AuxModel in model.auxModels) {
if (model.auxModels[ii] is SpotSceneModel) { if (aux is SpotSceneModel) {
return (model.auxModels[ii] as SpotSceneModel); return (aux as SpotSceneModel);
} }
} }
return null; return null;