diff --git a/src/as/com/threerings/README.txt b/src/as/com/threerings/README.txt index ed8549b41..8919e58f7 100644 --- a/src/as/com/threerings/README.txt +++ b/src/as/com/threerings/README.txt @@ -328,7 +328,3 @@ ActionScript - add code to verify the object's functions against describeType calls.. (would need to iterate on types because describeType only finds methods in the terminal interface. Only # of args can be checked) - -- actionscript problems - - helper classes go outside the package - - each cast is broken in one way or another diff --git a/src/as/com/threerings/crowd/client/LocationDirector.as b/src/as/com/threerings/crowd/client/LocationDirector.as index 294557eab..09e08defe 100644 --- a/src/as/com/threerings/crowd/client/LocationDirector.as +++ b/src/as/com/threerings/crowd/client/LocationDirector.as @@ -31,6 +31,7 @@ import com.threerings.presents.client.ClientEvent; import com.threerings.presents.dobj.DObject; import com.threerings.presents.dobj.ObjectAccessError; import com.threerings.presents.dobj.Subscriber; +import com.threerings.presents.dobj.SubscriberAdapter; import com.threerings.crowd.Log; import com.threerings.crowd.data.BodyObject; @@ -163,35 +164,32 @@ public class LocationDirector extends BasicDirector // make a note of our pending place id _pendingPlaceId = placeId; - var listener :MoveListenerProxy = new MoveListenerProxy(); + // documentation inherited from interface MoveListener + var success :Function = function (config :PlaceConfig) :void { + // handle the successful move + didMoveTo(_pendingPlaceId, config); + + // and clear out the tracked pending oid + _pendingPlaceId = -1; + }; // documentation inherited from interface MoveListener -// listener.moveSucceeded = function (config :PlaceConfig) :void -// { -// // handle the successful move -// didMoveTo(_pendingPlaceId, config); -// -// // and clear out the tracked pending oid -// _pendingPlaceId = -1; -// }; + var failure :Function = function (reason :String) :void { + // clear out our pending request oid + var placeId :int = _pendingPlaceId; + _pendingPlaceId = -1; - // documentation inherited from interface -// listener.requestFailed = function (reason :String) :void -// { -// // clear out our pending request oid -// var placeId :int = _pendingPlaceId; -// _pendingPlaceId = -1; -// -// Log.info("moveTo failed [pid=" + placeId + -// ", reason=" + reason + "]."); -// -// // let our observers know that something has gone horribly awry -// notifyFailure(placeId, reason); -// }; + Log.info("moveTo failed [pid=" + placeId + + ", reason=" + reason + "]."); + + // let our observers know that something has gone horribly awry + notifyFailure(placeId, reason); + }; // issue a moveTo request Log.info("Issuing moveTo(" + placeId + ")."); - _lservice.moveTo(_cctx.getClient(), placeId, listener); + _lservice.moveTo(_cctx.getClient(), placeId, + new MoveAdapter(success, failure)); return true; } @@ -407,22 +405,20 @@ public class LocationDirector extends BasicDirector { super.clientDidLogon(event); - // TODO: Work out new anonyclass construct -// var sub :SubscriberProxy = new SubscriberProxy(); - var sub :Object = new Object(); - sub.objectAvailable = function (object :DObject) :void { + var success :Function = function (object :DObject) :void { gotBodyObject(object as BodyObject); }; - sub.requestFailed = function (oid :int, cause :ObjectAccessError) :void { + var failure :Function = function ( + oid :int, cause :ObjectAccessError) :void { Log.warning("Location director unable to fetch body " + "object; all has gone horribly wrong" + "[cause=" + cause + "]."); }; - sub.objectAvailable(null); var client :Client = event.getClient(); var cloid :int = client.getClientOid(); - client.getDObjectManager().subscribeToObject(cloid, null); + client.getDObjectManager().subscribeToObject(cloid, + new SubscriberAdapter(success, failure)); } // documentation inherited @@ -612,30 +608,3 @@ public class LocationDirector extends BasicDirector protected static const STALE_REQUEST_DURATION :int = 60 * 1000; } } - -import com.threerings.presents.dobj.DObject; -import com.threerings.presents.dobj.ObjectAccessError; -import com.threerings.presents.dobj.Subscriber; - -import com.threerings.crowd.client.MoveListener; -import com.threerings.crowd.data.PlaceConfig; - -dynamic class SubscriberProxy implements Subscriber -{ - public function objectAvailable (obj :DObject) :void - { - } - public function requestFailed (oid :int, cause :ObjectAccessError) :void - { - } -} - -dynamic class MoveListenerProxy implements MoveListener -{ - public function moveSucceeded (config :PlaceConfig) :void - { - } - public function requestFailed (cause :String) :void - { - } -} diff --git a/src/as/com/threerings/crowd/client/MoveAdapter.as b/src/as/com/threerings/crowd/client/MoveAdapter.as new file mode 100644 index 000000000..586c128e3 --- /dev/null +++ b/src/as/com/threerings/crowd/client/MoveAdapter.as @@ -0,0 +1,24 @@ +package com.threerings.crowd.client { + +import com.threerings.presents.client.InvocationAdapter; + +import com.threerings.crowd.data.PlaceConfig; + +public class MoveAdapter extends InvocationAdapter + implements MoveListener +{ + public function MoveAdapter (success :Function, failure :Function) + { + super(failure); + _success = success; + } + + // documentation inherited from interface MoveListener + public function moveSucceeded (config :PlaceConfig) :void + { + _success(config); + } + + protected var _success :Function; +} +} diff --git a/src/as/com/threerings/msoy/client/MsoyClient.as b/src/as/com/threerings/msoy/client/MsoyClient.as index 2614c7737..1ac32685b 100644 --- a/src/as/com/threerings/msoy/client/MsoyClient.as +++ b/src/as/com/threerings/msoy/client/MsoyClient.as @@ -8,7 +8,7 @@ import com.threerings.util.Name; import com.threerings.presents.Log; import com.threerings.presents.client.Client; import com.threerings.presents.dobj.DSet; -import com.threerings.presents.dobj.QSet; +import com.threerings.presents.data.ClientObject; import com.threerings.presents.net.UsernamePasswordCreds; import com.threerings.presents.dobj.DObjectManager; diff --git a/src/as/com/threerings/presents/client/ClientSubscriber.as b/src/as/com/threerings/presents/client/ClientSubscriber.as deleted file mode 100644 index 1d5a684ad..000000000 --- a/src/as/com/threerings/presents/client/ClientSubscriber.as +++ /dev/null @@ -1,35 +0,0 @@ -package com.threerings.presents.client { - -import com.threerings.presents.client.InvocationDirector; -import com.threerings.presents.data.ClientObject; -import com.threerings.presents.dobj.DObject; -import com.threerings.presents.dobj.ObjectAccessError; -import com.threerings.presents.dobj.Subscriber; -import com.threerings.presents.Log; - -/** - * This class is used by the InvocationDirector to subscribe - * to the client object. - */ -public class ClientSubscriber implements Subscriber -{ - public function ClientSubscriber (invdir :InvocationDirector) - { - _invdir = invdir; - } - - // documentation inherited from interface Subscriber - public function objectAvailable (obj :DObject) :void - { - _invdir.gotClientObject(obj as ClientObject); - } - - // documentation inherited from interface Subscriber - public function requestFailed (oid :int, cause :ObjectAccessError) :void - { - _invdir.gotClientObjectFailed(oid, cause); - } - - protected var _invdir :InvocationDirector; -} -} diff --git a/src/as/com/threerings/presents/client/InvocationDirector.as b/src/as/com/threerings/presents/client/InvocationDirector.as index 2f287f4ac..0f4c4990c 100644 --- a/src/as/com/threerings/presents/client/InvocationDirector.as +++ b/src/as/com/threerings/presents/client/InvocationDirector.as @@ -16,6 +16,7 @@ import com.threerings.presents.dobj.InvocationNotificationEvent; import com.threerings.presents.dobj.InvocationRequestEvent; import com.threerings.presents.dobj.ObjectAccessError; import com.threerings.presents.dobj.Subscriber; +import com.threerings.presents.dobj.SubscriberAdapter; import com.threerings.presents.data.ClientObject; @@ -35,7 +36,8 @@ public class InvocationDirector _omgr = omgr; _client = client; - _omgr.subscribeToObject(cloid, new ClientSubscriber(this)); + _omgr.subscribeToObject(cloid, new SubscriberAdapter( + this.gotClientObject, this.gotClientObjectFailed)); } public function cleanup () :void @@ -306,7 +308,7 @@ public class InvocationDirector } /** - * Called by the ClientSubscriber helper class when the client object + * Called by the ClientObject SubscriberAdapter when the client object * has been returned by the server. */ internal function gotClientObject (clobj :ClientObject) :void @@ -320,7 +322,7 @@ public class InvocationDirector } /** - * Called by the ClientSubscriber helper class when it fails. + * Called by the ClientObject SubscriberAdapter when it fails. */ internal function gotClientObjectFailed ( oid :int, cause :ObjectAccessError) :void diff --git a/src/as/com/threerings/presents/dobj/SubscriberAdapter.as b/src/as/com/threerings/presents/dobj/SubscriberAdapter.as new file mode 100644 index 000000000..dd2d37b17 --- /dev/null +++ b/src/as/com/threerings/presents/dobj/SubscriberAdapter.as @@ -0,0 +1,27 @@ +package com.threerings.presents.dobj { + +public class SubscriberAdapter + implements Subscriber +{ + public function SubscriberAdapter (success :Function, failure :Function) + { + _success = success; + _failure = failure; + } + + // documentation inherited from interface Subscriber + public function objectAvailable (obj :DObject) :void + { + _success(obj); + } + + // documentation inherited from interface Subscriber + public function requestFailed (oid :int, cause :ObjectAccessError) :void + { + _failure(oid, cause); + } + + protected var _success :Function; + protected var _failure :Function; +} +}