package com.threerings.ezgame.data { import flash.events.Event; import flash.utils.ByteArray; import com.threerings.util.Name; import com.threerings.io.ObjectInputStream; import com.threerings.io.ObjectOutputStream; import com.threerings.io.TypedArray; import com.threerings.parlor.game.data.GameObject; import com.threerings.parlor.turn.data.TurnGameObject; import com.threerings.ezgame.util.EZObjectMarshaller; public class EZGameObject extends GameObject implements TurnGameObject { /** The identifier for a MessageEvent containing a user message. */ public static const USER_MESSAGE :String = "Umsg"; /** The identifier for a MessageEvent containing game-system chat. */ public static const GAME_CHAT :String = "Uchat"; // AUTO-GENERATED: FIELDS START /** The field name of the turnHolder field. */ public static const TURN_HOLDER :String = "turnHolder"; /** The field name of the ezGameService field. */ public static const EZ_GAME_SERVICE :String = "ezGameService"; // AUTO-GENERATED: FIELDS END /** The current turn holder. */ public var turnHolder :Name; /** The service interface for requesting special things from the server. */ public var ezGameService :EZGameMarshaller; /** * Access the underlying user properties. */ public function getUserProps () :Object { return _props; } // from TurnGameObject public function getTurnHolderFieldName () :String { return TURN_HOLDER; } // from TurnGameObject public function getTurnHolder () :Name { return turnHolder; } // from TurnGameObject public function getPlayers () :TypedArray /* of Name */ { return players; } // // AUTO-GENERATED: METHODS START // /** // * Requests that the turnHolder field be set to the // * specified value. The local value will be updated immediately and an // * event will be propagated through the system to notify all listeners // * that the attribute did change. Proxied copies of this object (on // * clients) will apply the value change when they received the // * attribute changed notification. // */ // public function setTurnHolder (value :Name) :void // { // var ovalue :Name = this.turnHolder; // requestAttributeChange( // TURN_HOLDER, value, ovalue); // this.turnHolder = value; // } // // AUTO-GENERATED: METHODS END /** * Called by a PropertySetEvent to enact a property change. * @return the old value */ public function applyPropertySet ( propName :String, value :Object, index :int) :Object { var oldValue :Object = _props[propName]; if (index >= 0) { // set an array element var arr :Array = (oldValue as Array); if (arr == null) { arr = []; _props[propName] = arr; } oldValue = arr[index]; arr[index] = value; } else if (value != null) { // normal property set _props[propName] = value; } else { // remove a property delete _props[propName]; } return oldValue; } // override public function writeObject (out :ObjectOutputStream) :void // { // super.writeObject(out); // // out.writeObject(turnHolder); // out.writeObject(ezGameService); // // out.writeInt(_props.length); // for (var key :String in _props) { // out.writeUTF(key); // out.writeObject(EZObjectMarshaller.encode(_props[key])); // } // } override public function readObject (ins :ObjectInputStream) :void { super.readObject(ins); // first read any regular bits turnHolder = (ins.readObject() as Name); ezGameService = (ins.readObject() as EZGameMarshaller); // then user properties var count :int = ins.readInt(); while (count-- > 0) { var key :String = ins.readUTF(); var value :Object = EZObjectMarshaller.decode(ins.readObject()); _props[key] = value; } } /** The raw properties set by the game. */ protected var _props :Object = new Object(); } }