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
This commit is contained in:
Ray Greenwell
2006-03-22 02:10:37 +00:00
parent 95ff914ab6
commit 7d3ef496fd
17 changed files with 218 additions and 63 deletions
+15
View File
@@ -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
@@ -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);
}
}
/**
@@ -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
{
}
}
@@ -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
}
}
}
+1 -10
View File
@@ -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;
+2 -11
View File
@@ -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;
@@ -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 += "<font color=\"red\">&lt;TODO&gt;</font> " +
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;
}
}
@@ -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);
}
}
}
@@ -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);
@@ -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);
}
}
}
@@ -0,0 +1,6 @@
package com.threerings.msoy.client {
public class SimpleChatPanel extends VBox
{
}
}
@@ -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;
}
}
}
@@ -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;
}
}
@@ -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);
+2
View File
@@ -1,5 +1,7 @@
package com.threerings.util {
import flash.util.*;
public class ClassUtil
{
public static function getClassName (obj :Object) :String
+16 -14
View File
@@ -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;
}
+2
View File
@@ -1,5 +1,7 @@
package com.threerings.util {
import mx.utils.*;
public class StringUtil
{
public static function isBlank (str :String) :Boolean