Added a really basic Config class for storing prefs clientside,
wired it up. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4184 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -80,14 +80,14 @@ public class Communicator
|
||||
|
||||
var host :String = _client.getHostname();
|
||||
var pportKey :String = host + ".preferred_port";
|
||||
// TODO: extract preferred port from saved prefs
|
||||
var pport :int = /** TODO Prefs.getValue(pportKey, **/ (ports[0] as int);
|
||||
var pport :int =
|
||||
(PresentsPrefs.config.getValue(pportKey, ports[0]) as int);
|
||||
var ppidx :int = Math.max(0, ports.indexOf(pport));
|
||||
var port :int = (ports[(_portIdx + ppidx) % ports.length] as int);
|
||||
|
||||
if (logonWasSuccessful) {
|
||||
_portIdx = -1; // indicate that we're no longer trying new ports
|
||||
// TODO: Prefs.setValue(pportKey, port);
|
||||
PresentsPrefs.config.setValue(pportKey, port);
|
||||
|
||||
} else {
|
||||
Log.getLog(this).info(
|
||||
@@ -238,7 +238,6 @@ public class Communicator
|
||||
*/
|
||||
protected function socketError (event :IOErrorEvent) :void
|
||||
{
|
||||
_socket.close();
|
||||
// if we're trying ports, try the next one.
|
||||
if (_portIdx != -1) {
|
||||
_portIdx++;
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.threerings.presents.client {
|
||||
|
||||
import com.threerings.util.Config;
|
||||
|
||||
/**
|
||||
* Provides access to runtime configuration parameters for this package.
|
||||
*/
|
||||
public class PresentsPrefs
|
||||
{
|
||||
/** Used to store our preferences. */
|
||||
public static const config :Config = new Config("rsrc/config/presents");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.threerings.util {
|
||||
|
||||
import flash.net.SharedObject;
|
||||
|
||||
public class Config
|
||||
{
|
||||
/**
|
||||
* Constructs a new config object which will obtain configuration
|
||||
* information from the specified path.
|
||||
*/
|
||||
public function Config (path :String)
|
||||
{
|
||||
_so = SharedObject.getLocal("config_" + path, "/");
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches and returns the value for the specified configuration property.
|
||||
*/
|
||||
public function getValue (name :String, defValue :Object) :Object
|
||||
{
|
||||
var val :* = _so.data[name];
|
||||
return (val === undefined) ? defValue : val;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value specified.
|
||||
*/
|
||||
public function setValue (name :String, value :Object) :void
|
||||
{
|
||||
_so.data[name] = value;
|
||||
_so.flush(); // flushing is not strictly necessary
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove any set value for the specified preference.
|
||||
*/
|
||||
public function remove (name :String) :void
|
||||
{
|
||||
delete _so.data[name];
|
||||
_so.flush(); // flushing is not strictly necessary
|
||||
}
|
||||
|
||||
/** The shared object that contains our preferences. */
|
||||
protected var _so :SharedObject;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user