From d948eb4f37c41f25d3b766b4fb670ada983e6912 Mon Sep 17 00:00:00 2001 From: Ray Greenwell Date: Thu, 8 Jun 2006 22:12:19 +0000 Subject: [PATCH] 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 --- .../presents/client/Communicator.as | 7 ++- .../presents/client/PresentsPrefs.as | 13 ++++++ src/as/com/threerings/util/Config.as | 46 +++++++++++++++++++ 3 files changed, 62 insertions(+), 4 deletions(-) create mode 100644 src/as/com/threerings/presents/client/PresentsPrefs.as create mode 100644 src/as/com/threerings/util/Config.as diff --git a/src/as/com/threerings/presents/client/Communicator.as b/src/as/com/threerings/presents/client/Communicator.as index 3ed161145..cfc9cea79 100644 --- a/src/as/com/threerings/presents/client/Communicator.as +++ b/src/as/com/threerings/presents/client/Communicator.as @@ -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++; diff --git a/src/as/com/threerings/presents/client/PresentsPrefs.as b/src/as/com/threerings/presents/client/PresentsPrefs.as new file mode 100644 index 000000000..8ae3dab79 --- /dev/null +++ b/src/as/com/threerings/presents/client/PresentsPrefs.as @@ -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"); +} +} diff --git a/src/as/com/threerings/util/Config.as b/src/as/com/threerings/util/Config.as new file mode 100644 index 000000000..a30d04a5e --- /dev/null +++ b/src/as/com/threerings/util/Config.as @@ -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; +} +}