From 70b9c7e43bfb37487eb7d60ade5453d86cd255f5 Mon Sep 17 00:00:00 2001 From: Ray Greenwell Date: Fri, 2 Mar 2007 08:38:45 +0000 Subject: [PATCH] It's a shame, because it's cool, but GameData isn't really needed anymore. It acted as a proxy for the distributed ez properties, such that you could set properties in the object and they'd magically go out over the network. Like so: var data :Object = _gameCtrl.data; data.scores = [ 0, 0 ]; data.startingPlayer = (Math.random() > .5) ? 0 : 1; Of course, you could read props too and even iterate over them in a for or for-each loop. But, with the addition of testAndSet() and setImmediately() it was decided that this direct access was ripe for confusion. Also, because there was not a *second-level* proxy for every array property, it didn't send individual array element updates over the network. I suppose I could write an array proxy and create one for every array property set, but jeezgod let's not get too crazy. Let's just keep it EZ and make people use our nice well-documented methods. If we want to add a method to EZGameControl for iterating over all properties, we can. That might be useful... There is one small concern, which is that now we're handing off our internal storage Object to usercode, so someone would have to modify their copy of EZGameControl and then they could... mess up their own game. Whatever. git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@221 c613c5cb-e716-0410-b11b-feb51c14d237 --- src/as/com/threerings/ezgame/EZGameControl.as | 8 - .../ezgame/client/GameControlBackend.as | 4 +- .../com/threerings/ezgame/client/GameData.as | 142 ------------------ 3 files changed, 2 insertions(+), 152 deletions(-) delete mode 100644 src/as/com/threerings/ezgame/client/GameData.as diff --git a/src/as/com/threerings/ezgame/EZGameControl.as b/src/as/com/threerings/ezgame/EZGameControl.as index 51913dc2..0aa151e4 100644 --- a/src/as/com/threerings/ezgame/EZGameControl.as +++ b/src/as/com/threerings/ezgame/EZGameControl.as @@ -173,14 +173,6 @@ public class EZGameControl extends BaseControl return _seating; } -// /** -// * Data accessor. -// */ -// public function get data () :Object -// { -// return _gameData; -// } - /** * Get a property from data. */ diff --git a/src/as/com/threerings/ezgame/client/GameControlBackend.as b/src/as/com/threerings/ezgame/client/GameControlBackend.as index 17522523..331185d0 100644 --- a/src/as/com/threerings/ezgame/client/GameControlBackend.as +++ b/src/as/com/threerings/ezgame/client/GameControlBackend.as @@ -94,7 +94,7 @@ public class GameControlBackend _ctx = ctx; _ezObj = ezObj; _ctrl = ctrl; - _gameData = new GameData(setProperty_v1, _ezObj.getUserProps()); + _gameData = _ezObj.getUserProps(); _ezObj.addListener(this); _ctx.getClient().getClientObject().addListener(_userListener); @@ -843,7 +843,7 @@ public class GameControlBackend * dispatch events to the user's game. */ protected var _ezDispatcher :Function; - protected var _gameData :GameData; + protected var _gameData :Object; /** playerIndex -> callback functions waiting for the cookie. */ protected var _cookieCallbacks :Dictionary; diff --git a/src/as/com/threerings/ezgame/client/GameData.as b/src/as/com/threerings/ezgame/client/GameData.as deleted file mode 100644 index 8b03a4e3..00000000 --- a/src/as/com/threerings/ezgame/client/GameData.as +++ /dev/null @@ -1,142 +0,0 @@ -// -// $Id$ -// -// Vilya library - tools for developing networked games -// Copyright (C) 2002-2007 Three Rings Design, Inc., All Rights Reserved -// http://www.threerings.net/code/vilya/ -// -// 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.ezgame.client { - -import flash.errors.IllegalOperationError; - -import flash.utils.Proxy; - -import flash.utils.flash_proxy; - -use namespace flash_proxy; - -public class GameData extends Proxy -{ - public function GameData (propSetFn :Function, props :Object) - { - _propSetFn = propSetFn; - _props = props; - } - - public function hasOwnProperty (propName :String) :Boolean - { - // pass-through - return _props.hasOwnProperty(propName); - } - - public function propertyIsEnumerable (propName :String) :Boolean - { - // pass-through - return _props.propertyIsEnumerable(propName); - } - - public function setPropertyIsEnumerable ( - propName :String, isEnum :Boolean = true) :void - { - // pass-through - _props.setPropertyIsEnumerable(propName, isEnum); - } - - override flash_proxy function callProperty (propName :*, ... rest) :* - { - // don't allow function calls - throw new IllegalOperationError(); - } - - override flash_proxy function getDescendants (name :*) :* - { - // we don't need this XML business - throw new IllegalOperationError(); - } - - override flash_proxy function isAttribute (name :*) :Boolean - { - // we don't need this XML business - throw new IllegalOperationError(); - } - - override flash_proxy function getProperty (propName :*) :* - { - // pass-through - return _props[propName]; - } - - override flash_proxy function hasProperty (propName :*) :Boolean - { - // pass-through - return (_props[propName] !== undefined); - } - - override flash_proxy function setProperty (propName :*, value :*) :void - { - _propSetFn(String(propName), value, -1); - } - - override flash_proxy function deleteProperty (propName :*) :Boolean - { - var hasProp :Boolean = hasProperty(propName); - setProperty(propName, null); - return hasProp; - } - - override flash_proxy function nextNameIndex (index :int) :int - { - // possibly set up the property list on the first call - if (index == 0) { - _propertyList = []; - for (var prop :String in _props) { - _propertyList.push(prop); - } - } - - // return a 1-based index to indicate that there is a property - if (index < _propertyList.length) { - return index + 1; - - } else { - // we're done, clear the prop list - _propertyList = null; - return 0; - } - } - - override flash_proxy function nextName (index :int) :String - { - // the index is 1-based, so subtract one - return (_propertyList[index - 1] as String); - } - - override flash_proxy function nextValue (index :int) :* - { - return _props[nextName(index)]; - } - - /** The function which we pass property setting to. */ - protected var _propSetFn :Function; - - /** The object we're proxying. */ - protected var _props :Object = { }; - - /** Used temporarily while iterating over our names or values. */ - protected var _propertyList :Array; -} -}