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:
@@ -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