zone moves and portal traversals can now have an optional result listener
passed in. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1460 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: LocationDirector.java,v 1.23 2002/06/14 01:24:48 mdb Exp $
|
||||
// $Id: LocationDirector.java,v 1.24 2002/06/14 01:40:16 ray Exp $
|
||||
|
||||
package com.threerings.crowd.client;
|
||||
|
||||
@@ -8,6 +8,7 @@ import java.util.List;
|
||||
|
||||
import com.samskivert.util.ObserverList;
|
||||
import com.samskivert.util.ObserverList.ObserverOp;
|
||||
import com.samskivert.util.ResultListener;
|
||||
|
||||
import com.threerings.presents.client.Client;
|
||||
import com.threerings.presents.client.InvocationReceiver;
|
||||
@@ -105,7 +106,7 @@ public class LocationDirector
|
||||
{
|
||||
// first check to see if our observers are happy with this move
|
||||
// request
|
||||
if (!mayMoveTo(placeId)) {
|
||||
if (!mayMoveTo(placeId, null)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -170,7 +171,7 @@ public class LocationDirector
|
||||
* @return true if everyone is happy with the move, false if it was
|
||||
* vetoed by one of the location observers.
|
||||
*/
|
||||
public boolean mayMoveTo (final int placeId)
|
||||
public boolean mayMoveTo (final int placeId, ResultListener rl)
|
||||
{
|
||||
final boolean[] vetoed = new boolean[1];
|
||||
_observers.apply(new ObserverOp() {
|
||||
@@ -180,6 +181,17 @@ public class LocationDirector
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
// if we have a result listener, let it know if we failed
|
||||
// or keep it for later if we're still going
|
||||
if (rl != null) {
|
||||
if (vetoed[0]) {
|
||||
rl.requestFailed(new MoveVetoedException());
|
||||
} else {
|
||||
_moveListener = rl;
|
||||
}
|
||||
}
|
||||
// and return the result
|
||||
return !vetoed[0];
|
||||
}
|
||||
|
||||
@@ -195,6 +207,11 @@ public class LocationDirector
|
||||
*/
|
||||
public void didMoveTo (int placeId, PlaceConfig config)
|
||||
{
|
||||
if (_moveListener != null) {
|
||||
_moveListener.requestCompleted(config);
|
||||
_moveListener = null;
|
||||
}
|
||||
|
||||
// keep track of our previous place id
|
||||
_previousPlaceId = _placeId;
|
||||
|
||||
@@ -266,6 +283,11 @@ public class LocationDirector
|
||||
*/
|
||||
public void failedToMoveTo (int placeId, String reason)
|
||||
{
|
||||
if (_moveListener != null) {
|
||||
_moveListener.requestFailed(new MoveFailedException(reason));
|
||||
_moveListener = null;
|
||||
}
|
||||
|
||||
// clear out our last request time
|
||||
_lastRequestTime = 0;
|
||||
|
||||
@@ -500,6 +522,10 @@ public class LocationDirector
|
||||
* object. */
|
||||
protected FailureHandler _failureHandler;
|
||||
|
||||
/** A listener that wants to know if we succeeded or
|
||||
* how we failed to move. */
|
||||
protected ResultListener _moveListener;
|
||||
|
||||
/** The operation used to inform observers that the location changed. */
|
||||
protected ObserverOp _didChangeOp = new ObserverOp() {
|
||||
public boolean apply (Object obs) {
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
//
|
||||
// $Id: MoveFailedException.java,v 1.1 2002/06/14 01:40:16 ray Exp $
|
||||
|
||||
package com.threerings.crowd.client;
|
||||
|
||||
/**
|
||||
* An exception that indicates that the server did not allow us to move.
|
||||
*/
|
||||
public class MoveFailedException extends Exception
|
||||
{
|
||||
public MoveFailedException (String message)
|
||||
{
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
//
|
||||
// $Id: MoveVetoedException.java,v 1.1 2002/06/14 01:40:16 ray Exp $
|
||||
|
||||
package com.threerings.crowd.client;
|
||||
|
||||
/**
|
||||
* An exception that indicates that a LocationObserver vetoed our move request.
|
||||
*/
|
||||
public class MoveVetoedException extends Exception
|
||||
{
|
||||
}
|
||||
@@ -1,10 +1,11 @@
|
||||
//
|
||||
// $Id: SceneDirector.java,v 1.18 2002/06/14 01:24:49 mdb Exp $
|
||||
// $Id: SceneDirector.java,v 1.19 2002/06/14 01:40:16 ray Exp $
|
||||
|
||||
package com.threerings.whirled.client;
|
||||
|
||||
import java.io.IOException;
|
||||
import com.samskivert.util.HashIntMap;
|
||||
import com.samskivert.util.ResultListener;
|
||||
|
||||
import com.threerings.presents.client.Client;
|
||||
import com.threerings.presents.client.InvocationReceiver;
|
||||
@@ -101,7 +102,7 @@ public class SceneDirector
|
||||
}
|
||||
|
||||
// prepare to move to this scene (sets up pending data)
|
||||
if (!prepareMoveTo(sceneId)) {
|
||||
if (!prepareMoveTo(sceneId, null)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -124,11 +125,11 @@ public class SceneDirector
|
||||
* the scene repository. This can be called by cooperating directors
|
||||
* that need to coopt the moveTo process.
|
||||
*/
|
||||
public boolean prepareMoveTo (int sceneId)
|
||||
public boolean prepareMoveTo (int sceneId, ResultListener rl)
|
||||
{
|
||||
// first check to see if our observers are happy with this move
|
||||
// request
|
||||
if (!_locdir.mayMoveTo(sceneId)) {
|
||||
if (!_locdir.mayMoveTo(sceneId, rl)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
//
|
||||
// $Id: SpotSceneDirector.java,v 1.13 2002/06/14 01:27:53 mdb Exp $
|
||||
// $Id: SpotSceneDirector.java,v 1.14 2002/06/14 01:40:16 ray Exp $
|
||||
|
||||
package com.threerings.whirled.spot.client;
|
||||
|
||||
import java.util.Iterator;
|
||||
import com.samskivert.util.ResultListener;
|
||||
import com.samskivert.util.StringUtil;
|
||||
|
||||
import com.threerings.presents.dobj.DObject;
|
||||
@@ -93,6 +94,17 @@ public class SpotSceneDirector
|
||||
* a location observer or because we have another request outstanding.
|
||||
*/
|
||||
public boolean traversePortal (int portalId)
|
||||
{
|
||||
return traversePortal(portalId, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests that this client move to the location specified by the
|
||||
* supplied portal id. A request will be made and when the response is
|
||||
* received, the location observers will be notified of success or
|
||||
* failure.
|
||||
*/
|
||||
public boolean traversePortal (int portalId, ResultListener rl)
|
||||
{
|
||||
// look up the destination scene and location
|
||||
DisplaySpotScene scene = (DisplaySpotScene)_scdir.getScene();
|
||||
@@ -122,7 +134,7 @@ public class SpotSceneDirector
|
||||
}
|
||||
|
||||
// prepare to move to this scene (sets up pending data)
|
||||
if (!_scdir.prepareMoveTo(targetSceneId)) {
|
||||
if (!_scdir.prepareMoveTo(targetSceneId, rl)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
//
|
||||
// $Id: ZoneDirector.java,v 1.7 2002/06/14 01:24:49 mdb Exp $
|
||||
// $Id: ZoneDirector.java,v 1.8 2002/06/14 01:40:16 ray Exp $
|
||||
|
||||
package com.threerings.whirled.zone.client;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.samskivert.util.ResultListener;
|
||||
|
||||
import com.threerings.presents.client.InvocationReceiver;
|
||||
import com.threerings.crowd.data.PlaceConfig;
|
||||
|
||||
@@ -77,6 +79,16 @@ public class ZoneDirector
|
||||
* location observers will be notified of success or failure.
|
||||
*/
|
||||
public boolean moveTo (int zoneId, int sceneId)
|
||||
{
|
||||
return moveTo(zoneId, sceneId, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests that this client move the specified scene in the specified
|
||||
* zone. A request will be made and when the response is received, the
|
||||
* location observers will be notified of success or failure.
|
||||
*/
|
||||
public boolean moveTo (int zoneId, int sceneId, ResultListener rl)
|
||||
{
|
||||
// if the requested zone is the same as our current zone, we just
|
||||
// want a regular old moveTo request
|
||||
@@ -86,7 +98,7 @@ public class ZoneDirector
|
||||
|
||||
// otherwise, we make a zoned moveTo request; prepare to move to
|
||||
// this scene (sets up pending data)
|
||||
if (!_scdir.prepareMoveTo(sceneId)) {
|
||||
if (!_scdir.prepareMoveTo(sceneId, rl)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -171,7 +183,7 @@ public class ZoneDirector
|
||||
_scdir.didLeaveScene();
|
||||
|
||||
// move to the new zone and scene
|
||||
moveTo(zoneId, sceneId);
|
||||
moveTo(zoneId, sceneId, null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user