diff --git a/src/java/com/threerings/stage/data/StageScene.java b/src/java/com/threerings/stage/data/StageScene.java index 899144977..c4ff4de5c 100644 --- a/src/java/com/threerings/stage/data/StageScene.java +++ b/src/java/com/threerings/stage/data/StageScene.java @@ -161,6 +161,12 @@ public class StageScene extends SceneImpl return _sdelegate.getPortals(); } + // documentation inherited from interface + public short getNextPortalId () + { + return _sdelegate.getNextPortalId(); + } + // documentation inherited from interface public Portal getDefaultEntrance () { diff --git a/src/java/com/threerings/stage/tools/editor/PortalTool.java b/src/java/com/threerings/stage/tools/editor/PortalTool.java index 0757b6e3b..01a4537f1 100644 --- a/src/java/com/threerings/stage/tools/editor/PortalTool.java +++ b/src/java/com/threerings/stage/tools/editor/PortalTool.java @@ -119,6 +119,7 @@ public class PortalTool extends MouseInputAdapter _portal.name = name; // add the portal to the scene and pop up the editor dialog + _portal.portalId = _scene.getNextPortalId(); _scene.addPortal(_portal); _panel.editPortal(_portal); } diff --git a/src/java/com/threerings/whirled/spot/data/SpotScene.java b/src/java/com/threerings/whirled/spot/data/SpotScene.java index 412fd5e34..54b60dbe1 100644 --- a/src/java/com/threerings/whirled/spot/data/SpotScene.java +++ b/src/java/com/threerings/whirled/spot/data/SpotScene.java @@ -1,5 +1,5 @@ // -// $Id: SpotScene.java,v 1.2 2004/08/27 02:20:46 mdb Exp $ +// $Id$ // // Narya library - tools for developing networked games // Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved @@ -45,6 +45,12 @@ public interface SpotScene */ public Iterator getPortals (); + /** + * Returns the portal id that should be assigned to the next portal + * added to this scene. + */ + public short getNextPortalId (); + /** * Returns the portal that represents the default entrance to this * scene. If a body enters the scene at logon time rather than @@ -55,8 +61,9 @@ public interface SpotScene /** * Adds a portal to this scene, immediately making the requisite - * modifications to the underlying scene model. A portal id will be - * assigned to the portal by this method. + * modifications to the underlying scene model. The portal id should + * have already been assigned using the value obtained from {@link + * #getNextPortalId}. */ public void addPortal (Portal portal); diff --git a/src/java/com/threerings/whirled/spot/data/SpotSceneImpl.java b/src/java/com/threerings/whirled/spot/data/SpotSceneImpl.java index b24787269..e26e77e21 100644 --- a/src/java/com/threerings/whirled/spot/data/SpotSceneImpl.java +++ b/src/java/com/threerings/whirled/spot/data/SpotSceneImpl.java @@ -1,5 +1,5 @@ // -// $Id: SpotSceneImpl.java,v 1.4 2004/08/27 02:20:46 mdb Exp $ +// $Id$ // // Narya library - tools for developing networked games // Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved @@ -78,6 +78,18 @@ public class SpotSceneImpl return _portals.values().iterator(); } + // documentation inherited from interface + public short getNextPortalId () + { + // compute a new portal id for our friend the portal + for (short ii = 1; ii < MAX_PORTAL_ID; ii++) { + if (!_portals.containsKey(ii)) { + return ii; + } + } + return (short)-1; + } + // documentation inherited from interface public Portal getDefaultEntrance () { @@ -87,21 +99,13 @@ public class SpotSceneImpl // documentation inherited from interface public void addPortal (Portal portal) { - // compute a new portal id for our friend the portal - portal.portalId = 0; - for (short ii = 1; ii < MAX_PORTAL_ID; ii++) { - if (!_portals.containsKey(ii)) { - portal.portalId = ii; - break; - } - } - if (portal.portalId == 0) { - Log.warning("Unable to assign id to new portal " + - "[scene=" + this + "]."); + if (portal.portalId <= 0) { + Log.warning("Refusing to add zero-id portal " + + "[scene=" + this + ", portal=" + portal + "]."); return; } - // add this beyotch to our model + // add it to our model _smodel.addPortal(portal); // and slap it into our table