Checkpoint. This is not compiling right now due to three annoying problems:
- There seems to be a compiler bug that causes classes to be imported spuriously, or something. Classes that import only one of the Log classes are complaining about visibility of more than one of them. - static constants are not inherited by subclasses, which is super annoying. I will try switching to prototype consts, but there seems to be a problem initializing those, and we don't want to make them vars... - The fact that there are no inner classes combined with no method overloading is making things very inconvenient. I've been experimenting with faking an anonymous class by instantiating a dynamic object and attaching functions to it, but it's not working. I'll continue experimenting, because if we can't do this then someone shoot me. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3957 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -314,3 +314,6 @@ ActionScript
|
||||
// this is illegal because MAX_VALUE is not defined until the
|
||||
// static initializer is run for this class. It's not around at compile time.
|
||||
public function getCrap (minValue :int, maxValue :int = MAX_VALUE) :Crap
|
||||
|
||||
- Static constants are not inherited by subclasses. You can make them
|
||||
prototype rather than static and they will be.
|
||||
|
||||
@@ -29,6 +29,8 @@ import com.threerings.util.SimpleMap;
|
||||
|
||||
import com.threerings.presents.client.BasicDirector;
|
||||
import com.threerings.presents.client.Client;
|
||||
import com.threerings.presents.client.ClientEvent;
|
||||
import com.threerings.presents.client.InvocationAdapter;
|
||||
import com.threerings.presents.data.ClientObject;
|
||||
import com.threerings.presents.dobj.DObject;
|
||||
import com.threerings.presents.dobj.MessageEvent;
|
||||
@@ -249,7 +251,7 @@ public class ChatDirector extends BasicDirector
|
||||
public function displayFeedback (bundle :String, message :String) :void
|
||||
{
|
||||
displaySystem(
|
||||
bundle, message, SystemMessage.FEEDBACK, PLACE_CHAT_TYPE);
|
||||
bundle, message, SystemMessage.FEEDBACK, ChatCodes.PLACE_CHAT_TYPE);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -262,7 +264,7 @@ public class ChatDirector extends BasicDirector
|
||||
public function displayAttention (bundle :String, message :String) :void
|
||||
{
|
||||
displaySystem(
|
||||
bundle, message, SystemMessage.ATTENTION, PLACE_CHAT_TYPE);
|
||||
bundle, message, SystemMessage.ATTENTION, ChatCodes.PLACE_CHAT_TYPE);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -458,15 +460,15 @@ public class ChatDirector extends BasicDirector
|
||||
}
|
||||
|
||||
// if they are idle, report that
|
||||
if (idletime > 0) {
|
||||
// adjust by the time it took them to become idle
|
||||
idletime += _cctx.getConfig().getValue(
|
||||
IDLE_TIME_KEY, DEFAULT_IDLE_TIME);
|
||||
var msg :String = MessageBundle.compose(
|
||||
"m.recipient_idle", MessageBundle.taint(target),
|
||||
TimeUtil.getTimeOrderString(idletime, TimeUtil.MINUTE));
|
||||
displayFeedback(_bundle, msg);
|
||||
}
|
||||
// if (idletime > 0) {
|
||||
// // adjust by the time it took them to become idle
|
||||
// idletime += _cctx.getConfig().getValue(
|
||||
// IDLE_TIME_KEY, DEFAULT_IDLE_TIME);
|
||||
// var msg :String = MessageBundle.compose(
|
||||
// "m.recipient_idle", MessageBundle.taint(target),
|
||||
// TimeUtil.getTimeOrderString(idletime, TimeUtil.MINUTE));
|
||||
// displayFeedback(_bundle, msg);
|
||||
// }
|
||||
};
|
||||
|
||||
_cservice.tell(_cctx.getClient(), target, message,
|
||||
@@ -622,32 +624,32 @@ public class ChatDirector extends BasicDirector
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public override function clientDidLogon (client :Client) :void
|
||||
public override function clientDidLogon (event :ClientEvent) :void
|
||||
{
|
||||
super.clientDidLogon(client);
|
||||
super.clientDidLogon(event);
|
||||
|
||||
// listen on the client object for tells
|
||||
addAuxiliarySource(_clobj = client.getClientObject(),
|
||||
addAuxiliarySource(_clobj = event.getClient().getClientObject(),
|
||||
ChatCodes.USER_CHAT_TYPE);
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public override function clientObjectDidChange (client :Client) :void
|
||||
public override function clientObjectDidChange (event :ClientEvent) :void
|
||||
{
|
||||
super.clientObjectDidChange(client);
|
||||
super.clientObjectDidChange(event);
|
||||
|
||||
// change what we're listening to for tells
|
||||
removeAuxiliarySource(_clobj);
|
||||
addAuxiliarySource(_clobj = client.getClientObject(),
|
||||
addAuxiliarySource(_clobj = event.getClient().getClientObject(),
|
||||
ChatCodes.USER_CHAT_TYPE);
|
||||
|
||||
clearDisplays();
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public override function clientDidLogoff (client :Client) :void
|
||||
public override function clientDidLogoff (event :ClientEvent) :void
|
||||
{
|
||||
super.clientDidLogoff(client);
|
||||
super.clientDidLogoff(event);
|
||||
|
||||
// stop listening to it for tells
|
||||
if (_clobj != null) {
|
||||
@@ -702,7 +704,7 @@ public class ChatDirector extends BasicDirector
|
||||
// mogrification may result in something being turned into a slash
|
||||
// command, in which case we have to run everything through again
|
||||
// from the start
|
||||
if (message.startsWith("/")) {
|
||||
if (message.indexOf("/") == 0) {
|
||||
return requestChat(speakSvc, message, false);
|
||||
}
|
||||
|
||||
@@ -818,7 +820,7 @@ public class ChatDirector extends BasicDirector
|
||||
{
|
||||
var bundle :MessageBundle = _msgmgr.getBundle(_bundle);
|
||||
if (!bundle.exists(key)) {
|
||||
return buf;
|
||||
return text;
|
||||
}
|
||||
var repls :Array = bundle.get(key).split("#");
|
||||
// apply the replacements to each mogrification that matches
|
||||
@@ -835,7 +837,7 @@ public class ChatDirector extends BasicDirector
|
||||
* specified command (i.e. the specified command is a prefix of their
|
||||
* registered command string).
|
||||
*/
|
||||
protected function getCommandHandlers (command :String) :SimpleMap
|
||||
internal function getCommandHandlers (command :String) :SimpleMap
|
||||
{
|
||||
var matches :SimpleMap = new SimpleMap();
|
||||
var user :BodyObject =
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.threerings.crowd.chat.client {
|
||||
|
||||
import com.threerings.crowd.chat.data.ChatCodes;
|
||||
|
||||
public class ClearHandler extends CommandHandler
|
||||
{
|
||||
public function ClearHandler (chatdir :ChatDirector)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.threerings.crowd.chat.client {
|
||||
|
||||
import com.threerings.util.MessageBundle;
|
||||
import com.threerings.util.SimpleMap;
|
||||
import com.threerings.util.StringUtil;
|
||||
|
||||
import com.threerings.crowd.chat.data.ChatCodes;
|
||||
@@ -29,7 +30,7 @@ public class HelpHandler extends CommandHandler
|
||||
|
||||
// let the user give commands with or without the /
|
||||
if (hcmd.charAt(0) == "/") {
|
||||
hcmd = hcm.substring(1);
|
||||
hcmd = hcmd.substring(1);
|
||||
}
|
||||
|
||||
// handle "/help help" and "/help boguscmd"
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
package com.threerings.crowd.chat.data {
|
||||
|
||||
import com.samskivert.util.StringUtil;
|
||||
import com.threerings.util.ClassUtil;
|
||||
|
||||
import com.threerings.io.ObjectInputStream;
|
||||
import com.threerings.io.ObjectOutputStream;
|
||||
@@ -43,6 +43,12 @@ public /*abstract*/ class ChatMessage
|
||||
* registered with an auxiliary source in the ChatDirector. */
|
||||
public var localtype :String;
|
||||
|
||||
public function ChatMessage (msg :String = null, bundle :String = null)
|
||||
{
|
||||
this.message = msg;
|
||||
this.bundle = bundle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Once this message reaches the client, the information contained within
|
||||
* is changed around a bit.
|
||||
@@ -67,8 +73,8 @@ public /*abstract*/ class ChatMessage
|
||||
// documentation inherited from interface Streamable
|
||||
public function readObject (ins :ObjectInputStream) :void
|
||||
{
|
||||
message = ins.readField(String);
|
||||
bundle = ins.readField(String);
|
||||
message = (ins.readField(String) as String);
|
||||
bundle = (ins.readField(String) as String);
|
||||
}
|
||||
|
||||
// documentation inherited from interface Streamable
|
||||
|
||||
@@ -41,11 +41,16 @@ public class SystemMessage extends ChatMessage
|
||||
/** Attention level constant to indicate that some action is required. */
|
||||
public static const ATTENTION :int = 2;
|
||||
|
||||
//----
|
||||
|
||||
/** The attention level of this message. */
|
||||
public var attentionLevel :int;
|
||||
|
||||
public function SystemMessage (
|
||||
msg :String = null, bundle :String = null, attLevel :int = 0)
|
||||
{
|
||||
super(msg, bundle);
|
||||
this.attentionLevel = attLevel;
|
||||
}
|
||||
|
||||
public override function readObject (ins :ObjectInputStream) :void
|
||||
{
|
||||
super.readObject(ins);
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
//
|
||||
// $Id: TellFeedbackMessage.java 3098 2004-08-27 02:12:55Z mdb $
|
||||
//
|
||||
// Narya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
|
||||
// http://www.threerings.net/code/narya/
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Lesser General Public License as published
|
||||
// by the Free Software Foundation; either version 2.1 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package com.threerings.crowd.chat.data {
|
||||
|
||||
/**
|
||||
* A feedback message to indicate that a tell succeeded.
|
||||
*/
|
||||
public class TellFeedbackMessage extends ChatMessage
|
||||
{
|
||||
/**
|
||||
* A tell feedback message is only composed on the client.
|
||||
*/
|
||||
public function TellFeedbackMessage (message :String)
|
||||
{
|
||||
super(message, null);
|
||||
setClientInfo(message, ChatCodes.PLACE_CHAT_TYPE);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
//
|
||||
// $Id$
|
||||
|
||||
package com.threerings.crowd.chat.data {
|
||||
|
||||
import com.threerings.util.Name;
|
||||
|
||||
import com.threerings.io.ObjectInputStream;
|
||||
import com.threerings.io.ObjectOutputStream;
|
||||
|
||||
/**
|
||||
* A system message triggered by the activity of another user.
|
||||
* If the user is muted we can suppress this message, unlike a normal
|
||||
* system message.
|
||||
*/
|
||||
public class UserSystemMessage extends SystemMessage
|
||||
{
|
||||
/** The "speaker" of this message, the user that triggered that this
|
||||
* message be sent to us. */
|
||||
public var speaker :Name;
|
||||
|
||||
/**
|
||||
* Construct a UserSystemMessage.
|
||||
*/
|
||||
public function UserSystemMessage (
|
||||
sender :Name = null, message :String = null, bundle :String = null,
|
||||
attLevel :int = 0)
|
||||
{
|
||||
super(message, bundle, attLevel);
|
||||
this.speaker = sender;
|
||||
}
|
||||
|
||||
public override function readObject (ins :ObjectInputStream) :void
|
||||
{
|
||||
super.readObject(ins);
|
||||
speaker = (ins.readObject() as Name);
|
||||
}
|
||||
|
||||
public override function writeObject (out :ObjectOutputStream) :void
|
||||
{
|
||||
super.writeObject(out);
|
||||
out.writeObject(speaker);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,13 +21,12 @@
|
||||
|
||||
package com.threerings.crowd.client {
|
||||
|
||||
// TODO: class is in progress of conversion
|
||||
|
||||
import com.threerings.util.ObserverList;
|
||||
import com.threerings.util.ResultListener;
|
||||
|
||||
import com.threerings.presents.client.BasicDirector;
|
||||
import com.threerings.presents.client.Client;
|
||||
import com.threerings.presents.client.ClientEvent;
|
||||
|
||||
import com.threerings.presents.dobj.DObject;
|
||||
import com.threerings.presents.dobj.ObjectAccessError;
|
||||
@@ -48,7 +47,7 @@ import com.threerings.crowd.util.CrowdContext;
|
||||
* before actually issuing the request.
|
||||
*/
|
||||
public class LocationDirector extends BasicDirector
|
||||
implements Subscriber, LocationReceiver, MoveListener
|
||||
implements Subscriber, LocationReceiver
|
||||
{
|
||||
/**
|
||||
* Used to recover from a moveTo request that was accepted but
|
||||
@@ -164,9 +163,35 @@ 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
|
||||
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);
|
||||
};
|
||||
|
||||
// issue a moveTo request
|
||||
Log.info("Issuing moveTo(" + placeId + ").");
|
||||
_lservice.moveTo(_cctx.getClient(), placeId, this);
|
||||
_lservice.moveTo(_cctx.getClient(), placeId, listener);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -290,7 +315,7 @@ public class LocationDirector extends BasicDirector
|
||||
_placeId = placeId;
|
||||
|
||||
// check whether we should use a custom class loader
|
||||
cclass :Class = config.getControllerClass();
|
||||
var cclass :Class = config.getControllerClass();
|
||||
try {
|
||||
// start up a new place controller to manage the new place
|
||||
_controller = (new cclass() as PlaceController);
|
||||
@@ -383,7 +408,7 @@ public class LocationDirector extends BasicDirector
|
||||
super.clientDidLogon(event);
|
||||
|
||||
// TODO: Work out new anonyclass construct
|
||||
var sub :Subscriber = new SubscriberProxy();
|
||||
var sub :SubscriberProxy = new SubscriberProxy();
|
||||
sub.objectAvailable = function (object :DObject) :void {
|
||||
gotBodyObject(object as BodyObject);
|
||||
};
|
||||
@@ -393,7 +418,8 @@ public class LocationDirector extends BasicDirector
|
||||
"[cause=" + cause + "].");
|
||||
};
|
||||
|
||||
var cloid :int = event.getClient().getClientOid();
|
||||
var client :Client = event.getClient();
|
||||
var cloid :int = client.getClientOid();
|
||||
client.getDObjectManager().subscribeToObject(cloid, sub);
|
||||
}
|
||||
|
||||
@@ -431,30 +457,6 @@ public class LocationDirector extends BasicDirector
|
||||
// we'll want to be going there straight away
|
||||
}
|
||||
|
||||
// documentation inherited from interface
|
||||
public function moveSucceeded (config :PlaceConfig) :void
|
||||
{
|
||||
// handle the successful move
|
||||
didMoveTo(_pendingPlaceId, config);
|
||||
|
||||
// and clear out the tracked pending oid
|
||||
_pendingPlaceId = -1;
|
||||
}
|
||||
|
||||
// documentation inherited from interface
|
||||
public function requestFailed (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);
|
||||
}
|
||||
|
||||
// documentation inherited from interface
|
||||
public function forcedMove (placeId :int) :void
|
||||
{
|
||||
@@ -470,10 +472,7 @@ public class LocationDirector extends BasicDirector
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when we receive the place object to which we subscribed
|
||||
* after a successful moveTo request.
|
||||
*/
|
||||
// documentation inherited from interface Subscriber
|
||||
public function objectAvailable (object :DObject) :void
|
||||
{
|
||||
// yay, we have our new place object
|
||||
@@ -494,12 +493,7 @@ public class LocationDirector extends BasicDirector
|
||||
_observers.apply(_didChangeOp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called if we are unable to subscribe to the place object that was
|
||||
* provided to us with our successful moveTo request. This is
|
||||
* generally a bad scene and we do our best to recover by going back
|
||||
* to the previously known location.
|
||||
*/
|
||||
// documentation inherited from interface Subscriber
|
||||
public function requestFailed (oid :int, cause :ObjectAccessError) :void
|
||||
{
|
||||
// aiya! we were unable to fetch our new place object; something
|
||||
@@ -520,17 +514,17 @@ public class LocationDirector extends BasicDirector
|
||||
// does whatever's necessary
|
||||
|
||||
// try to return to our previous location
|
||||
if (_failureHandler != null) {
|
||||
_failureHandler.recoverFailedMove(placeId);
|
||||
|
||||
} else {
|
||||
// if (_failureHandler != null) {
|
||||
// _failureHandler.recoverFailedMove(placeId);
|
||||
//
|
||||
// } else {
|
||||
// if we were previously somewhere (and that somewhere isn't
|
||||
// where we just tried to go), try going back to that happy
|
||||
// place
|
||||
if (_previousPlaceId != -1 && _previousPlaceId != placeId) {
|
||||
moveTo(_previousPlaceId);
|
||||
}
|
||||
}
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -618,7 +612,12 @@ public class LocationDirector extends BasicDirector
|
||||
}
|
||||
|
||||
import com.threerings.presents.dobj.Subscriber;
|
||||
import com.threerings.crowd.client.MoveListener;
|
||||
|
||||
dynamic class SubscriberProxy implements Subscriber
|
||||
{
|
||||
}
|
||||
|
||||
dynamic class MoveListenerProxy implements MoveListener
|
||||
{
|
||||
}
|
||||
|
||||
@@ -53,3 +53,4 @@ public interface LocationService extends InvocationService
|
||||
*/
|
||||
function leavePlace (client :Client) :void;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
package com.threerings.crowd.client {
|
||||
|
||||
import com.threerings.presents.client.ClientEvent;
|
||||
import com.threerings.presents.client.InvocationListener;
|
||||
|
||||
import com.threerings.crowd.data.PlaceConfig;
|
||||
|
||||
public interface MoveListener extends InvocationListener
|
||||
{
|
||||
function moveSucceeded (config :PlaceConfig) :void;
|
||||
|
||||
@@ -47,7 +47,7 @@ public interface PlaceConfig extends Streamable
|
||||
* this place. The controller class must derive from {@link
|
||||
* PlaceController}.
|
||||
*/
|
||||
public function getControllerClass () :Class;
|
||||
function getControllerClass () :Class;
|
||||
|
||||
/**
|
||||
* Returns the name of the class that should be used to create a
|
||||
|
||||
@@ -120,7 +120,7 @@ public class PlaceObject extends DObject
|
||||
*/
|
||||
public function addToOccupantInfo (elem :DSetEntry) :void
|
||||
{
|
||||
requestEntryAdd(OCCUPANT_INFO, occupantInfo, elem);
|
||||
requestEntryAdd(OCCUPANT_INFO, elem);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -130,7 +130,7 @@ public class PlaceObject extends DObject
|
||||
*/
|
||||
public function removeFromOccupantInfo (key :Object) :void
|
||||
{
|
||||
requestEntryRemove(OCCUPANT_INFO, occupantInfo, key);
|
||||
requestEntryRemove(OCCUPANT_INFO, key);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -140,7 +140,7 @@ public class PlaceObject extends DObject
|
||||
*/
|
||||
public function updateOccupantInfo (elem :DSetEntry) :void
|
||||
{
|
||||
requestEntryUpdate(OCCUPANT_INFO, occupantInfo, elem);
|
||||
requestEntryUpdate(OCCUPANT_INFO, elem);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.threerings.msoy.client {
|
||||
|
||||
import com.threerings.util.MessageManager;
|
||||
|
||||
import com.threerings.presents.client.Client;
|
||||
import com.threerings.presents.dobj.DObjectManager;
|
||||
|
||||
|
||||
@@ -88,8 +88,7 @@ public class InvocationDirector
|
||||
// if we're logged on, clear out any receiver id mapping
|
||||
if (_clobj != null) {
|
||||
var rreg :InvocationRegistration =
|
||||
(_clobj.receivers.getByKey(receiverCode)
|
||||
as InvocationRegistration);
|
||||
(_clobj.receivers.get(receiverCode) as InvocationRegistration);
|
||||
if (rreg == null) {
|
||||
Log.warning("Receiver unregistered for which we have no " +
|
||||
"id to code mapping [code=" + receiverCode + "].");
|
||||
|
||||
@@ -61,7 +61,7 @@ public class DSet
|
||||
*/
|
||||
public function containsKey (key :Object) :Boolean
|
||||
{
|
||||
return getByKey(key) != null;
|
||||
return get(key) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -69,7 +69,7 @@ public class DSet
|
||||
* the specified key or null if no entry could be found that matches
|
||||
* the key.
|
||||
*/
|
||||
public function getByKey (key :Object) :DSetEntry
|
||||
public function get (key :Object) :DSetEntry
|
||||
{
|
||||
// o(n) for now
|
||||
for each (var entry :DSetEntry in _entries) {
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.threerings.util {
|
||||
|
||||
import mx.logging.ILogger;
|
||||
|
||||
public class Log extends LogDaddy
|
||||
{
|
||||
/** The Logger for this package. */
|
||||
public static var log :ILogger = getLogger("util");
|
||||
|
||||
/** Convenience function. */
|
||||
public static function debug (message :String, ... rest) :void
|
||||
{
|
||||
log.debug(message, rest);
|
||||
}
|
||||
|
||||
/** Convenience function. */
|
||||
public static function info (message :String, ... rest) :void
|
||||
{
|
||||
log.info(message, rest);
|
||||
}
|
||||
|
||||
/** Convenience function. */
|
||||
public static function warning (message :String, ... rest) :void
|
||||
{
|
||||
log.warn(message, rest);
|
||||
}
|
||||
|
||||
/** Convenience function. */
|
||||
public static function logStackTrace (err :Error) :void
|
||||
{
|
||||
log.warn(err.getStackTrace());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,8 @@
|
||||
|
||||
package com.threerings.util {
|
||||
|
||||
import flash.util.StringBuilder;
|
||||
|
||||
/**
|
||||
* A message bundle provides an easy mechanism by which to obtain
|
||||
* translated message strings from a resource bundle. It uses the {@link
|
||||
@@ -65,31 +67,29 @@ public class MessageBundle
|
||||
protected function getResourceString (
|
||||
key :String, reportMissing :Boolean = true) :String
|
||||
{
|
||||
// TODO!!!
|
||||
// try {
|
||||
// if (_bundle != null) {
|
||||
// return _bundle.getString(key);
|
||||
// }
|
||||
// } catch (MissingResourceException mre) {
|
||||
// // fall through and try the parent
|
||||
// }
|
||||
//
|
||||
// // if we have a parent, try getting the string from them
|
||||
// if (_parent != null) {
|
||||
// String value = _parent.getResourceString(key, false);
|
||||
// if (value != null) {
|
||||
// return value;
|
||||
// }
|
||||
// // if we didn't find it in our parent, we want to fall
|
||||
// // through and report missing appropriately
|
||||
// }
|
||||
//
|
||||
// if (reportMissing) {
|
||||
// Log.warning("Missing translation message " +
|
||||
// "[bundle=" + _path + ", key=" + key + "].");
|
||||
// Thread.dumpStack();
|
||||
// }
|
||||
//
|
||||
try {
|
||||
if (_bundle != null) {
|
||||
return _bundle.getString(key);
|
||||
}
|
||||
} catch (missingResource :Error) {
|
||||
// fall through and try the parent
|
||||
}
|
||||
|
||||
// if we have a parent, try getting the string from them
|
||||
if (_parent != null) {
|
||||
var value :String = _parent.getResourceString(key, false);
|
||||
if (value != null) {
|
||||
return value;
|
||||
}
|
||||
// if we didn't find it in our parent, we want to fall
|
||||
// through and report missing appropriately
|
||||
}
|
||||
|
||||
if (reportMissing) {
|
||||
Log.warning("Missing translation message " +
|
||||
"[bundle=" + _path + ", key=" + key + "].");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ public class MessageBundle
|
||||
{
|
||||
// if this string is tainted, we don't translate it, instead we
|
||||
// simply remove the taint character and return it to the caller
|
||||
if (key.chatAt(0) === TAINT_CHAR) {
|
||||
if (key.charAt(0) === TAINT_CHAR) {
|
||||
return key.substring(1);
|
||||
}
|
||||
|
||||
@@ -151,8 +151,8 @@ public class MessageBundle
|
||||
}
|
||||
|
||||
return (msg != null) ?
|
||||
MessageFormat.format(MessageUtil.escape(msg), args)
|
||||
: (key + StringUtil.toString(args));
|
||||
MessageFormat.format(escape(msg), args)
|
||||
: (key + args);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -352,7 +352,7 @@ public class MessageBundle
|
||||
|
||||
var buf :StringBuilder = new StringBuilder();
|
||||
for (var ii :int = 0; ii < val.length; ii++) {
|
||||
var ch :String = value.charAt(0);
|
||||
var ch :String = val.charAt(0);
|
||||
if (ch != "\\" || ii == val.length-1) {
|
||||
buf.append(ch);
|
||||
} else {
|
||||
@@ -385,7 +385,11 @@ public class MessageBundle
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: figure out how this is all actually going to even work
|
||||
class ResourceBundle
|
||||
// TODO: figure out what we're going to do here
|
||||
class MessageFormat
|
||||
{
|
||||
public static function format (msg :String, ... rest) :String
|
||||
{
|
||||
return msg + rest;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,11 +125,11 @@ public class MessageManager
|
||||
// if (_loader != null) {
|
||||
// rbundle = ResourceBundle.getBundle(fqpath, _locale, _loader);
|
||||
// } else {
|
||||
rbundle = ResourceBundle.getBundle(fqpath, _locale);
|
||||
rbundle = ResourceBundle.getBundle(fqpath);
|
||||
// }
|
||||
} catch (mre :Error) {
|
||||
Log.warning("Unable to resolve resource bundle " +
|
||||
"[path=" + fqpath + ", locale=" + _locale + "].");
|
||||
"[path=" + fqpath + "].");
|
||||
}
|
||||
|
||||
// if the resource bundle contains a special resource, we'll
|
||||
@@ -140,8 +140,8 @@ public class MessageManager
|
||||
try {
|
||||
mbclass = rbundle.getString(MBUNDLE_CLASS_KEY);
|
||||
if (!StringUtil.isBlank(mbclass)) {
|
||||
bundle = (MessageBundle)
|
||||
Class.forName(mbclass).newInstance();
|
||||
var clazz :Class = ClassUtil.getClassByName(mbclass);
|
||||
bundle = new clazz();
|
||||
}
|
||||
|
||||
} catch (mre :Error) {
|
||||
@@ -174,7 +174,7 @@ public class MessageManager
|
||||
// protected var _locale :Locale;
|
||||
|
||||
/** A custom class loader that we use to load resource bundles. */
|
||||
protected var _loader :ClassLoader;
|
||||
// protected var _loader :ClassLoader;
|
||||
|
||||
/** A cache of instantiated message bundles. */
|
||||
protected var _cache :SimpleMap = new SimpleMap();
|
||||
@@ -185,6 +185,6 @@ public class MessageManager
|
||||
|
||||
/** A key that can contain the classname of a custom message bundle
|
||||
* class to be used to handle messages for a particular bundle. */
|
||||
// protected static const MBUNDLE_CLASS_KEY :String = "msgbundle_class";
|
||||
protected static const MBUNDLE_CLASS_KEY :String = "msgbundle_class";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.threerings.util {
|
||||
|
||||
public class ResourceBundle
|
||||
{
|
||||
public static function getBundle (path :String) :ResourceBundle
|
||||
{
|
||||
return new ResourceBundle();
|
||||
}
|
||||
|
||||
public function getString (key :String) :String
|
||||
{
|
||||
return "TODO: resource:" + key;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -51,7 +51,7 @@ public class TimeUtil
|
||||
* displayed, the minimum is 1.
|
||||
*/
|
||||
public static function getTimeOrderString (
|
||||
duration :long, minUnit :int, maxUnit :int = -1) :String
|
||||
duration :Number, minUnit :int, maxUnit :int = -1) :String
|
||||
{
|
||||
// enforce sanity
|
||||
if (maxUnit == -1) {
|
||||
@@ -78,7 +78,8 @@ public class TimeUtil
|
||||
* Get a translatable string specifying the duration, down to the
|
||||
* minimum granularity.
|
||||
*/
|
||||
public static function getTimeString (duration :long, minUnit :int) :String
|
||||
public static function getTimeString (
|
||||
duration :Number, minUnit :int) :String
|
||||
{
|
||||
// sanity
|
||||
minUnit = Math.min(minUnit, MAX_UNIT);
|
||||
@@ -116,7 +117,7 @@ public class TimeUtil
|
||||
case MILLISECOND: return 1000;
|
||||
case SECOND: case MINUTE: return 60;
|
||||
case HOUR: return 24;
|
||||
case DAY: return Integer.MAX_VALUE;
|
||||
case DAY: return int.MAX_VALUE;
|
||||
default: return -1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ public class Util
|
||||
if (obj == null || obj is clazz) {
|
||||
return obj;
|
||||
} else {
|
||||
throw new Error("wah");
|
||||
throw new TypeError("value is not a " + clazz);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user