Some fixups and enhancements.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4294 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,8 +1,10 @@
|
|||||||
package com.threerings.io {
|
package com.threerings.io {
|
||||||
|
|
||||||
import com.threerings.util.ClassUtil;
|
import com.threerings.util.ClassUtil;
|
||||||
|
import com.threerings.util.Cloneable;
|
||||||
|
|
||||||
public dynamic class TypedArray extends Array
|
public dynamic class TypedArray extends Array
|
||||||
|
implements Cloneable
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Create a TypedArray
|
* Create a TypedArray
|
||||||
@@ -21,9 +23,18 @@ public dynamic class TypedArray extends Array
|
|||||||
*/
|
*/
|
||||||
public static function getJavaType (of :Class) :String
|
public static function getJavaType (of :Class) :String
|
||||||
{
|
{
|
||||||
|
if (of === Boolean) {
|
||||||
|
return "[Z";
|
||||||
|
|
||||||
|
} else if (of === int) { // Number will be int if something like 3.0
|
||||||
|
return "[I";
|
||||||
|
|
||||||
|
} else if (of === Number) {
|
||||||
|
return "[D";
|
||||||
|
}
|
||||||
|
|
||||||
var cname :String = Translations.getToServer(
|
var cname :String = Translations.getToServer(
|
||||||
ClassUtil.getClassName(of));
|
ClassUtil.getClassName(of));
|
||||||
// TODO: primitive types
|
|
||||||
return "[L" + cname + ";";
|
return "[L" + cname + ";";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,6 +52,17 @@ public dynamic class TypedArray extends Array
|
|||||||
return _jtype;
|
return _jtype;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// from Cloneable
|
||||||
|
public function clone () :Object
|
||||||
|
{
|
||||||
|
var clazz :Class = ClassUtil.getClass(this);
|
||||||
|
var copy :TypedArray = new clazz(_jtype);
|
||||||
|
for (var ii :int = length - 1; ii >= 0; ii--) {
|
||||||
|
copy[ii] = this[ii];
|
||||||
|
}
|
||||||
|
return copy;
|
||||||
|
}
|
||||||
|
|
||||||
/** The 'type' of this array, which doesn't really mean anything
|
/** The 'type' of this array, which doesn't really mean anything
|
||||||
* except gives it a clue as to how to stream to our server. */
|
* except gives it a clue as to how to stream to our server. */
|
||||||
protected var _jtype :String;
|
protected var _jtype :String;
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ import flash.events.TimerEvent;
|
|||||||
|
|
||||||
import flash.utils.Timer;
|
import flash.utils.Timer;
|
||||||
|
|
||||||
|
import mx.core.Application;
|
||||||
|
|
||||||
import com.threerings.util.ObserverList;
|
import com.threerings.util.ObserverList;
|
||||||
|
|
||||||
import com.threerings.presents.data.ClientObject;
|
import com.threerings.presents.data.ClientObject;
|
||||||
@@ -26,10 +28,10 @@ public class Client extends EventDispatcher
|
|||||||
|
|
||||||
private static const log :Log = Log.getLog(Client);
|
private static const log :Log = Log.getLog(Client);
|
||||||
|
|
||||||
public function Client (creds :Credentials, stage :Stage)
|
public function Client (creds :Credentials, app :Application)
|
||||||
{
|
{
|
||||||
_creds = creds;
|
_creds = creds;
|
||||||
_stage = stage;
|
_app = app;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -94,12 +96,17 @@ public class Client extends EventDispatcher
|
|||||||
_ports = ports;
|
_ports = ports;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function callLater (fn :Function, args :Array = null) :void
|
||||||
|
{
|
||||||
|
_app.callLater(fn, args);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the Stage object we're living in.
|
* @return the Stage object we're living in.
|
||||||
*/
|
*/
|
||||||
public function getStage () :Stage
|
public function getStage () :Stage
|
||||||
{
|
{
|
||||||
return _stage;
|
return _app.stage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getHostname () :String
|
public function getHostname () :String
|
||||||
@@ -365,8 +372,8 @@ public class Client extends EventDispatcher
|
|||||||
/** The credentials we used to authenticate with the server. */
|
/** The credentials we used to authenticate with the server. */
|
||||||
protected var _creds :Credentials;
|
protected var _creds :Credentials;
|
||||||
|
|
||||||
/** The stage we're on, needed for creating the Communicator. */
|
/** The app we're in, needed for creating the Communicator. */
|
||||||
protected var _stage :Stage;
|
protected var _app :Application;
|
||||||
|
|
||||||
/** The version string reported to the server at auth time. */
|
/** The version string reported to the server at auth time. */
|
||||||
protected var _version :String = "";
|
protected var _version :String = "";
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
package com.threerings.util {
|
package com.threerings.util {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains methods that should be in Array, but aren't.
|
* Contains methods that should be in Array, but aren't. Additionally
|
||||||
|
* contains methods that understand the interfaces in this package.
|
||||||
|
* So, for example, removeFirst() understands Equalable and will remove
|
||||||
|
* an element that is equals() to the specified element, rather than just
|
||||||
|
* ===.
|
||||||
*/
|
*/
|
||||||
public class ArrayUtil
|
public class ArrayUtil
|
||||||
{
|
{
|
||||||
@@ -24,6 +28,18 @@ public class ArrayUtil
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function indexOf (arr :Array, element :Object) :int
|
||||||
|
{
|
||||||
|
if (arr != null) {
|
||||||
|
for (var ii :int = 0; ii < arr.length; ii++) {
|
||||||
|
if (Util.equals(arr[ii], element)) {
|
||||||
|
return ii;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1; // never found
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove the first instance of the specified element from the array.
|
* Remove the first instance of the specified element from the array.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -4,6 +4,22 @@ import mx.utils.*;
|
|||||||
|
|
||||||
public class StringUtil
|
public class StringUtil
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Get a reasonable hash code for the specified String.
|
||||||
|
*/
|
||||||
|
public static function hashCode (str :String) :int
|
||||||
|
{
|
||||||
|
var code :int = 0;
|
||||||
|
if (str != null) {
|
||||||
|
// sample at most 8 chars
|
||||||
|
var lastChar :int = Math.min(8, str.length);
|
||||||
|
for (var ii :int = 0; ii < lastChar; ii++) {
|
||||||
|
code = code * 31 + str.charCodeAt(ii);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
public static function isBlank (str :String) :Boolean
|
public static function isBlank (str :String) :Boolean
|
||||||
{
|
{
|
||||||
return (str == null) || (str.search("\\S") == -1);
|
return (str == null) || (str.search("\\S") == -1);
|
||||||
@@ -15,7 +31,7 @@ public class StringUtil
|
|||||||
public static function endsWith (str :String, substr :String) :Boolean
|
public static function endsWith (str :String, substr :String) :Boolean
|
||||||
{
|
{
|
||||||
var startDex :int = str.length - substr.length;
|
var startDex :int = str.length - substr.length;
|
||||||
return (startDex >= 0) && (str.indexOf(substr, startDex) > 0);
|
return (startDex >= 0) && (str.indexOf(substr, startDex) >= 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user