From 7d3ef496fde803bd3c6930ad05edb4c34752623a Mon Sep 17 00:00:00 2001 From: Ray Greenwell Date: Wed, 22 Mar 2006 02:10:37 +0000 Subject: [PATCH] More faffing about. - started making chat UI stuff - upgraded SimpleMap some to use the new Dictionary class - Lots of experimenting with attaching functions to interface implementations. I've upgraded to the new beta of Flex and it's giving me the pain. There's new compiler bugs and I am working blind right now. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3966 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- src/as/com/threerings/README.txt | 15 +++++ .../crowd/chat/client/ChatDirector.as | 4 +- .../crowd/client/LocationDirector.as | 62 ++++++++++++------- .../com/threerings/crowd/data/PlaceConfig.as | 19 +++++- src/as/com/threerings/io/ObjectInputStream.as | 11 +--- .../com/threerings/io/ObjectOutputStream.as | 13 +--- .../threerings/msoy/client/ChatTextArea.as | 52 ++++++++++++++++ src/as/com/threerings/msoy/client/MsoyApp.as | 22 +++++++ .../com/threerings/msoy/client/MsoyClient.as | 2 +- .../msoy/client/SimpleChatController.as | 14 +++++ .../threerings/msoy/client/SimpleChatPanel.as | 6 ++ .../threerings/msoy/data/SimpleChatConfig.as | 15 +++++ .../com/threerings/presents/client/Client.as | 8 +++ .../presents/client/InvocationDirector.as | 4 +- src/as/com/threerings/util/ClassUtil.as | 2 + src/as/com/threerings/util/SimpleMap.as | 30 ++++----- src/as/com/threerings/util/StringUtil.as | 2 + 17 files changed, 218 insertions(+), 63 deletions(-) create mode 100644 src/as/com/threerings/msoy/client/ChatTextArea.as create mode 100644 src/as/com/threerings/msoy/client/MsoyApp.as create mode 100644 src/as/com/threerings/msoy/client/SimpleChatController.as create mode 100644 src/as/com/threerings/msoy/client/SimpleChatPanel.as create mode 100644 src/as/com/threerings/msoy/data/SimpleChatConfig.as diff --git a/src/as/com/threerings/README.txt b/src/as/com/threerings/README.txt index 7d7a13a93..ed8549b41 100644 --- a/src/as/com/threerings/README.txt +++ b/src/as/com/threerings/README.txt @@ -317,3 +317,18 @@ ActionScript - Static constants are not inherited by subclasses. You can make them prototype rather than static and they will be. + +- anonymous class options: + + - pass arrays of functions, with just a convention as to which function is + which (no compile-time type checking) + - pass objects with functions of the right names attached (no compile-time) + - make adapters, as necessary, for interfaces (bleah!) (Still no good + compile-time checking, except for the # of args) + - 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/chat/client/ChatDirector.as b/src/as/com/threerings/crowd/chat/client/ChatDirector.as index 71584a9ea..0213d8356 100644 --- a/src/as/com/threerings/crowd/chat/client/ChatDirector.as +++ b/src/as/com/threerings/crowd/chat/client/ChatDirector.as @@ -105,7 +105,9 @@ public class ChatDirector extends BasicDirector */ public function addChatDisplay (display :ChatDisplay) :void { - _displays.addItem(display); + if (-1 == _displays.getItemIndex(display)) { + _displays.addItem(display); + } } /** diff --git a/src/as/com/threerings/crowd/client/LocationDirector.as b/src/as/com/threerings/crowd/client/LocationDirector.as index bceec77b5..294557eab 100644 --- a/src/as/com/threerings/crowd/client/LocationDirector.as +++ b/src/as/com/threerings/crowd/client/LocationDirector.as @@ -166,28 +166,28 @@ public class LocationDirector extends BasicDirector var listener :MoveListenerProxy = new MoveListenerProxy(); // 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; - }; +// listener.moveSucceeded = function (config :PlaceConfig) :void +// { +// // handle the successful move +// didMoveTo(_pendingPlaceId, config); +// +// // and clear out the tracked pending oid +// _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); - }; +// 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); +// }; // issue a moveTo request Log.info("Issuing moveTo(" + placeId + ")."); @@ -408,7 +408,8 @@ public class LocationDirector extends BasicDirector super.clientDidLogon(event); // TODO: Work out new anonyclass construct - var sub :SubscriberProxy = new SubscriberProxy(); +// var sub :SubscriberProxy = new SubscriberProxy(); + var sub :Object = new Object(); sub.objectAvailable = function (object :DObject) :void { gotBodyObject(object as BodyObject); }; @@ -417,10 +418,11 @@ public class LocationDirector extends BasicDirector "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, sub); + client.getDObjectManager().subscribeToObject(cloid, null); } // documentation inherited @@ -611,13 +613,29 @@ public class LocationDirector extends BasicDirector } } +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/data/PlaceConfig.as b/src/as/com/threerings/crowd/data/PlaceConfig.as index 789929b89..f0a1306fb 100644 --- a/src/as/com/threerings/crowd/data/PlaceConfig.as +++ b/src/as/com/threerings/crowd/data/PlaceConfig.as @@ -40,14 +40,18 @@ import com.threerings.crowd.client.PlaceController; * #getControllerClass} and {@link #getManagerClassName}, returning the * appropriate place controller and manager class for that place. */ -public interface PlaceConfig extends Streamable +public /*abstract*/ class PlaceConfig + implements Streamable { /** * Returns the class that should be used to create a controller for * this place. The controller class must derive from {@link * PlaceController}. */ - function getControllerClass () :Class; + public function getControllerClass () :Class + { + return null; + } /** * Returns the name of the class that should be used to create a @@ -60,5 +64,16 @@ public interface PlaceConfig extends Streamable * knowing that it is never used. */ // public function getManagerClassName () :String; + + // documentation inherited from interface Streamable + public function writeObject (out :ObjectOutputStream) :void + { + // nothing needed + } + + public function readObject (ins :ObjectInputStream) :void + { + // nothing needed + } } } diff --git a/src/as/com/threerings/io/ObjectInputStream.as b/src/as/com/threerings/io/ObjectInputStream.as index 11bf8e341..b1b472925 100644 --- a/src/as/com/threerings/io/ObjectInputStream.as +++ b/src/as/com/threerings/io/ObjectInputStream.as @@ -23,7 +23,7 @@ public class ObjectInputStream /** * Set a new source from which to read our data. */ - public function setSource (source :IDataInput) + public function setSource (source :IDataInput) :void { _source = source; } @@ -189,15 +189,6 @@ public class ObjectInputStream return _source.readUTF(); } - /** - * Used by a Streamer that is reading an array of Streamable instances. - */ - protected function setCurrent (streamer :Streamer, current :Object) - { - _streamer = streamer; - _current = current; - } - /** The target DataInput that we route input from. */ protected var _source :IDataInput; diff --git a/src/as/com/threerings/io/ObjectOutputStream.as b/src/as/com/threerings/io/ObjectOutputStream.as index 36c7bf466..34067a00d 100644 --- a/src/as/com/threerings/io/ObjectOutputStream.as +++ b/src/as/com/threerings/io/ObjectOutputStream.as @@ -38,7 +38,7 @@ public class ObjectOutputStream if (cmap == null) { var streamer :Streamer = Streamer.getStreamer(obj); // streamer may be null to indicate a Streamable object - if (streamer === undefined) { + if (streamer == null) { // TODO trace("OMG, cannot stream ", cname); return; @@ -66,7 +66,7 @@ public class ObjectOutputStream writeBareObjectImpl(obj, Streamer.getStreamer(obj)); } - public function writeBareObjectImpl (obj :Object, streamer :Streamer) + public function writeBareObjectImpl (obj :Object, streamer :Streamer) :void { // if it's Streamable, it goes straight through if (streamer == null) { @@ -169,15 +169,6 @@ public class ObjectOutputStream //public function writeUnsignedInt (value :int) :void //public function writeUTFBytes (value :int) :void - /** - * Used by a Streamer that is writing an array of Streamable instances. - */ - internal function setCurrent (streamer :Streamer, current :Object) - { - _streamer = streamer; - _current = current; - } - /** The target DataOutput that we route things to. */ protected var _targ :IDataOutput; diff --git a/src/as/com/threerings/msoy/client/ChatTextArea.as b/src/as/com/threerings/msoy/client/ChatTextArea.as new file mode 100644 index 000000000..83968f1d6 --- /dev/null +++ b/src/as/com/threerings/msoy/client/ChatTextArea.as @@ -0,0 +1,52 @@ +package com.threerings.msoy.client { + +import mx.controls.TextArea; + +import com.threerings.crowd.chat.client.ChatDirector; +import com.threerings.crowd.chat.client.ChatDisplay; + +public class ChatTextArea extends TextArea + implements ChatDisplay +{ + public function ChatTextArea (ctx :MsoyContext) + { + _ctx = ctx; + this.editable = false; + + // set up some events to manage how we'll be shown, etc. + addEventListener("creationComplete", checkVis); + addEventListener("show", checkVis); + addEventListener("hide", checkVis); + } + + // documentation inherited from interface ChatDisplay + public function clear () :void + { + this.htmlText = ""; + } + + // documentation inherited from interface ChatDisplay + public function displayMessage (msg :ChatMessage) :void + { + this.htmlText += "<TODO> " + + msg.message; + } + + /** + * Check to see if we should register or unregister ourselves as a + * ChatDisplay. + */ + protected void checkVis (event :Event) :void + { + var chatdir :ChatDirector = _ctx.getChatDirector(); + if (this.visible) { + chatdir.addChatDisplay(this); + } else { + chatdir.removeChatDisplay(this); + } + } + + /** The giver of life. */ + protected var _ctx :MsoyContext; +} +} diff --git a/src/as/com/threerings/msoy/client/MsoyApp.as b/src/as/com/threerings/msoy/client/MsoyApp.as new file mode 100644 index 000000000..aa4560efc --- /dev/null +++ b/src/as/com/threerings/msoy/client/MsoyApp.as @@ -0,0 +1,22 @@ +package com.threerings.msoy.client { + +import mx.core.Application; +import mx.events.FlexEvent; + +public class MsoyApp extends Application +{ + public function MsoyApp () + { + super(); + addEventListener(attachApplication, nowShowing); + } + + /** + * Called once we're ready to go. + */ + private function nowShowing (event :FlexEvent) :void + { + removeEventListener(attachApplication, nowShowing); + } +} +} diff --git a/src/as/com/threerings/msoy/client/MsoyClient.as b/src/as/com/threerings/msoy/client/MsoyClient.as index dbfa8bdc0..7b85d7334 100644 --- a/src/as/com/threerings/msoy/client/MsoyClient.as +++ b/src/as/com/threerings/msoy/client/MsoyClient.as @@ -21,7 +21,7 @@ public class MsoyClient extends Client { public function MsoyClient () { - super(new UsernamePasswordCreds(new Name("Ray"), "fork-u-2")); + super(new UsernamePasswordCreds(new Name("guest"), "guest")); _ctx = new MsoyContext(this); diff --git a/src/as/com/threerings/msoy/client/SimpleChatController.as b/src/as/com/threerings/msoy/client/SimpleChatController.as new file mode 100644 index 000000000..144481c77 --- /dev/null +++ b/src/as/com/threerings/msoy/client/SimpleChatController.as @@ -0,0 +1,14 @@ +package com.threerings.msoy.client { + +import com.threerings.crowd.client.CrowdContext; +import com.threerings.crowd.client.PlaceController; + +public class SimpleChatController extends PlaceController +{ + // documentation inherited + protected override function createPlaceView (ctx :CrowdContext) :PlaceView + { + return new SimpleChatPanel(ctx as MsoyContext); + } +} +} diff --git a/src/as/com/threerings/msoy/client/SimpleChatPanel.as b/src/as/com/threerings/msoy/client/SimpleChatPanel.as new file mode 100644 index 000000000..4e645fa1b --- /dev/null +++ b/src/as/com/threerings/msoy/client/SimpleChatPanel.as @@ -0,0 +1,6 @@ +package com.threerings.msoy.client { + +public class SimpleChatPanel extends VBox +{ +} +} diff --git a/src/as/com/threerings/msoy/data/SimpleChatConfig.as b/src/as/com/threerings/msoy/data/SimpleChatConfig.as new file mode 100644 index 000000000..11af4cc6e --- /dev/null +++ b/src/as/com/threerings/msoy/data/SimpleChatConfig.as @@ -0,0 +1,15 @@ +package com.threerings.msoy.data { + +import com.threerings.crowd.data.PlaceConfig; + +import com.threerings.msoy.client.SimpleChatController; + +public class SimpleChatConfig implements PlaceConfig +{ + // documentation inherited + public override function getControllerClass () :Class + { + return SimpleChatController; + } +} +} diff --git a/src/as/com/threerings/presents/client/Client.as b/src/as/com/threerings/presents/client/Client.as index deb8b0f4d..09f9dcaf2 100644 --- a/src/as/com/threerings/presents/client/Client.as +++ b/src/as/com/threerings/presents/client/Client.as @@ -359,5 +359,13 @@ public class Client extends EventDispatcher /** Ticks. */ protected var _tickInterval :Timer; + + // client observer constants + internal static const CLIENT_DID_LOGON :int = 0; + internal static const CLIENT_FAILED_TO_LOGON :int = 1; + internal static const CLIENT_OBJECT_CHANGED :int = 2; + internal static const CLIENT_CONNECTION_FAILED :int = 3; + internal static const CLIENT_WILL_LOGOFF :int = 4; + internal static const CLIENT_DID_LOGOFF :int = 5; } } diff --git a/src/as/com/threerings/presents/client/InvocationDirector.as b/src/as/com/threerings/presents/client/InvocationDirector.as index 83033c114..efcbb2b98 100644 --- a/src/as/com/threerings/presents/client/InvocationDirector.as +++ b/src/as/com/threerings/presents/client/InvocationDirector.as @@ -93,9 +93,9 @@ public class InvocationDirector Log.warning("Receiver unregistered for which we have no " + "id to code mapping [code=" + receiverCode + "]."); } else { - var decoder :Object = _receivers.remove(rreg.receiverId); + var odecoder :Object = _receivers.remove(rreg.receiverId); // Log.info("Cleared receiver " + -// StringUtil.shortClassName(decoder) + +// StringUtil.shortClassName(odecoder) + // " " + rreg + "."); } _clobj.removeFromReceivers(receiverCode); diff --git a/src/as/com/threerings/util/ClassUtil.as b/src/as/com/threerings/util/ClassUtil.as index a64a78b14..440fb2425 100644 --- a/src/as/com/threerings/util/ClassUtil.as +++ b/src/as/com/threerings/util/ClassUtil.as @@ -1,5 +1,7 @@ package com.threerings.util { +import flash.util.*; + public class ClassUtil { public static function getClassName (obj :Object) :String diff --git a/src/as/com/threerings/util/SimpleMap.as b/src/as/com/threerings/util/SimpleMap.as index 1480ad94b..985254eff 100644 --- a/src/as/com/threerings/util/SimpleMap.as +++ b/src/as/com/threerings/util/SimpleMap.as @@ -1,5 +1,7 @@ package com.threerings.util { +import flash.util.Dictionary; + /** * I will likely extend this out to be a fully-featured map. */ @@ -7,29 +9,28 @@ public class SimpleMap extends Object { public function clear () :void { - _data = new Object(); + _data = new Dictionary(); + _size = 0; } public function get (key :Object) :Object { - var skey :String = key.toString(); - return _data[skey]; + return _data[key]; } public function keys () :Array { var arr :Array = new Array(); - for (var skey :String in _data) { - arr.push(skey); + for (var key :Object in _data) { + arr.push(key); } return arr; } public function put (key :Object, value :Object) :Object { - var skey :String = key.toString(); - var oldValue :* = _data[skey]; - _data[skey] = value; + var oldValue :* = _data[key]; + _data[key] = value; if (oldValue === undefined) { _size++; } @@ -38,11 +39,12 @@ public class SimpleMap extends Object public function remove (key :Object) :Object { - var skey :String = key.toString(); - var value :Object = _data[skey]; - delete _data[skey]; - _size--; - return value; + var value :* = _data[key]; + if (value !== undefined) { + delete _data[key]; + _size--; + } + return (value as Object); } public function size () :int @@ -50,7 +52,7 @@ public class SimpleMap extends Object return _size; } - protected var _data :Object = new Object(); + protected var _data :Dictionary = new Dictionary(); protected var _size :int = 0; } diff --git a/src/as/com/threerings/util/StringUtil.as b/src/as/com/threerings/util/StringUtil.as index e42095ba9..3ae3f1597 100644 --- a/src/as/com/threerings/util/StringUtil.as +++ b/src/as/com/threerings/util/StringUtil.as @@ -1,5 +1,7 @@ package com.threerings.util { +import mx.utils.*; + public class StringUtil { public static function isBlank (str :String) :Boolean