Moved the serverless game stuff out of msoy and back into the vilya library.

We'll be using this in game gardens, at least.
Note that the actionscript side currently doesn't compile because of
limitations in building a .swc file, but that'll be fixed soon.


git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@47 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
Ray Greenwell
2006-08-23 02:28:36 +00:00
parent a90d7e655b
commit 70b0d759c0
27 changed files with 2835 additions and 0 deletions
@@ -0,0 +1,141 @@
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 <code>turnHolder</code> field. */
public static const TURN_HOLDER :String = "turnHolder";
/** The field name of the <code>ezGameService</code> 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 <code>turnHolder</code> 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);
throw new Error("Un-needed");
}
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();
}
}