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:
@@ -0,0 +1,83 @@
|
||||
//
|
||||
// $Id$
|
||||
|
||||
package com.threerings.ezgame.data {
|
||||
|
||||
import com.threerings.util.MessageBundle;
|
||||
|
||||
import com.threerings.io.ObjectInputStream;
|
||||
import com.threerings.io.ObjectOutputStream;
|
||||
|
||||
import com.threerings.crowd.client.PlaceController;
|
||||
|
||||
import com.threerings.parlor.game.client.GameConfigurator;
|
||||
import com.threerings.parlor.game.data.GameConfig;
|
||||
import com.threerings.parlor.game.data.PartyGameConfig;
|
||||
import com.threerings.parlor.game.data.PartyGameCodes;
|
||||
|
||||
import com.threerings.ezgame.client.EZGameController;
|
||||
|
||||
/**
|
||||
* A game config for a simple multiplayer ez game.
|
||||
*/
|
||||
public /* abstract */ class EZGameConfig extends GameConfig
|
||||
implements PartyGameConfig
|
||||
{
|
||||
/** A creator-submitted name of the game. */
|
||||
public var gameName :String;
|
||||
|
||||
override public function createController () :PlaceController
|
||||
{
|
||||
return new EZGameController();
|
||||
}
|
||||
|
||||
override public function getBundleName () :String
|
||||
{
|
||||
return "general";
|
||||
}
|
||||
|
||||
// TODO
|
||||
//override public function createConfigurator () :GameConfigurator
|
||||
|
||||
override public function getGameName () :String
|
||||
{
|
||||
return MessageBundle.taint(gameName);
|
||||
}
|
||||
|
||||
// from PartyGameConfig
|
||||
public function getPartyGameType () :int
|
||||
{
|
||||
// TODO
|
||||
return PartyGameCodes.NOT_PARTY_GAME;
|
||||
}
|
||||
|
||||
override public function equals (other :Object) :Boolean
|
||||
{
|
||||
if (!super.equals(other)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var that :EZGameConfig = (other as EZGameConfig);
|
||||
return (this.gameName === that.gameName);
|
||||
}
|
||||
|
||||
override public function hashCode () :int
|
||||
{
|
||||
return super.hashCode(); // TODO: incorporate gamename?
|
||||
}
|
||||
|
||||
override public function writeObject (out :ObjectOutputStream) :void
|
||||
{
|
||||
super.writeObject(out);
|
||||
|
||||
out.writeField(gameName);
|
||||
}
|
||||
|
||||
override public function readObject (ins :ObjectInputStream) :void
|
||||
{
|
||||
super.readObject(ins);
|
||||
|
||||
gameName = (ins.readField(String) as String);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
//
|
||||
// $Id$
|
||||
|
||||
package com.threerings.ezgame.data {
|
||||
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
import com.threerings.util.langBoolean;
|
||||
import com.threerings.util.Integer;
|
||||
|
||||
import com.threerings.io.TypedArray;
|
||||
|
||||
import com.threerings.ezgame.client.EZGameService;
|
||||
import com.threerings.presents.client.Client;
|
||||
import com.threerings.presents.client.InvocationService;
|
||||
import com.threerings.presents.client.InvocationService_ConfirmListener;
|
||||
import com.threerings.presents.client.InvocationService_InvocationListener;
|
||||
import com.threerings.presents.data.InvocationMarshaller;
|
||||
import com.threerings.presents.data.InvocationMarshaller_ConfirmMarshaller;
|
||||
import com.threerings.presents.data.InvocationMarshaller_ListenerMarshaller;
|
||||
import com.threerings.presents.dobj.InvocationResponseEvent;
|
||||
|
||||
/**
|
||||
* Provides the implementation of the {@link EZGameService} interface
|
||||
* that marshalls the arguments and delivers the request to the provider
|
||||
* on the server. Also provides an implementation of the response listener
|
||||
* interfaces that marshall the response arguments and deliver them back
|
||||
* to the requesting client.
|
||||
*/
|
||||
public class EZGameMarshaller extends InvocationMarshaller
|
||||
implements EZGameService
|
||||
{
|
||||
/** The method id used to dispatch {@link #addToCollection} requests. */
|
||||
public static const ADD_TO_COLLECTION :int = 1;
|
||||
|
||||
// documentation inherited from interface
|
||||
public function addToCollection (arg1 :Client, arg2 :String, arg3 :TypedArray /* of ByteArray */, arg4 :Boolean, arg5 :InvocationService_InvocationListener) :void
|
||||
{
|
||||
var listener5 :InvocationMarshaller_ListenerMarshaller = new InvocationMarshaller_ListenerMarshaller();
|
||||
listener5.listener = arg5;
|
||||
sendRequest(arg1, ADD_TO_COLLECTION, [
|
||||
arg2, arg3, langBoolean.valueOf(arg4), listener5
|
||||
]);
|
||||
}
|
||||
|
||||
/** The method id used to dispatch {@link #endGame} requests. */
|
||||
public static const END_GAME :int = 2;
|
||||
|
||||
// documentation inherited from interface
|
||||
public function endGame (arg1 :Client, arg2 :TypedArray, arg3 :InvocationService_InvocationListener) :void
|
||||
{
|
||||
var listener3 :InvocationMarshaller_ListenerMarshaller = new InvocationMarshaller_ListenerMarshaller();
|
||||
listener3.listener = arg3;
|
||||
sendRequest(arg1, END_GAME, [
|
||||
arg2, listener3
|
||||
]);
|
||||
}
|
||||
|
||||
/** The method id used to dispatch {@link #endTurn} requests. */
|
||||
public static const END_TURN :int = 3;
|
||||
|
||||
// documentation inherited from interface
|
||||
public function endTurn (arg1 :Client, arg2 :int, arg3 :InvocationService_InvocationListener) :void
|
||||
{
|
||||
var listener3 :InvocationMarshaller_ListenerMarshaller = new InvocationMarshaller_ListenerMarshaller();
|
||||
listener3.listener = arg3;
|
||||
sendRequest(arg1, END_TURN, [
|
||||
Integer.valueOf(arg2), listener3
|
||||
]);
|
||||
}
|
||||
|
||||
/** The method id used to dispatch {@link #getFromCollection} requests. */
|
||||
public static const GET_FROM_COLLECTION :int = 4;
|
||||
|
||||
// documentation inherited from interface
|
||||
public function getFromCollection (arg1 :Client, arg2 :String, arg3 :Boolean, arg4 :int, arg5 :String, arg6 :int, arg7 :InvocationService_ConfirmListener) :void
|
||||
{
|
||||
var listener7 :InvocationMarshaller_ConfirmMarshaller = new InvocationMarshaller_ConfirmMarshaller();
|
||||
listener7.listener = arg7;
|
||||
sendRequest(arg1, GET_FROM_COLLECTION, [
|
||||
arg2, langBoolean.valueOf(arg3), Integer.valueOf(arg4), arg5, Integer.valueOf(arg6), listener7
|
||||
]);
|
||||
}
|
||||
|
||||
/** The method id used to dispatch {@link #mergeCollection} requests. */
|
||||
public static const MERGE_COLLECTION :int = 5;
|
||||
|
||||
// documentation inherited from interface
|
||||
public function mergeCollection (arg1 :Client, arg2 :String, arg3 :String, arg4 :InvocationService_InvocationListener) :void
|
||||
{
|
||||
var listener4 :InvocationMarshaller_ListenerMarshaller = new InvocationMarshaller_ListenerMarshaller();
|
||||
listener4.listener = arg4;
|
||||
sendRequest(arg1, MERGE_COLLECTION, [
|
||||
arg2, arg3, listener4
|
||||
]);
|
||||
}
|
||||
|
||||
/** The method id used to dispatch {@link #sendMessage} requests. */
|
||||
public static const SEND_MESSAGE :int = 6;
|
||||
|
||||
// documentation inherited from interface
|
||||
public function sendMessage (arg1 :Client, arg2 :String, arg3 :Object, arg4 :int, arg5 :InvocationService_InvocationListener) :void
|
||||
{
|
||||
var listener5 :InvocationMarshaller_ListenerMarshaller = new InvocationMarshaller_ListenerMarshaller();
|
||||
listener5.listener = arg5;
|
||||
sendRequest(arg1, SEND_MESSAGE, [
|
||||
arg2, arg3, Integer.valueOf(arg4), listener5
|
||||
]);
|
||||
}
|
||||
|
||||
/** The method id used to dispatch {@link #setProperty} requests. */
|
||||
public static const SET_PROPERTY :int = 7;
|
||||
|
||||
// documentation inherited from interface
|
||||
public function setProperty (arg1 :Client, arg2 :String, arg3 :Object, arg4 :int, arg5 :InvocationService_InvocationListener) :void
|
||||
{
|
||||
var listener5 :InvocationMarshaller_ListenerMarshaller = new InvocationMarshaller_ListenerMarshaller();
|
||||
listener5.listener = arg5;
|
||||
sendRequest(arg1, SET_PROPERTY, [
|
||||
arg2, arg3, Integer.valueOf(arg4), listener5
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
//
|
||||
// $Id$
|
||||
|
||||
package com.threerings.ezgame.data {
|
||||
|
||||
import flash.utils.ByteArray;
|
||||
import flash.utils.IExternalizable;
|
||||
|
||||
import com.threerings.io.ObjectInputStream;
|
||||
import com.threerings.io.ObjectOutputStream;
|
||||
import com.threerings.io.Streamer;
|
||||
|
||||
import com.threerings.presents.dobj.DObject;
|
||||
import com.threerings.presents.dobj.NamedEvent;
|
||||
|
||||
import com.threerings.ezgame.util.EZObjectMarshaller;
|
||||
|
||||
/**
|
||||
* Represents a property change on the actionscript object we
|
||||
* use in FlashGameObject.
|
||||
*/
|
||||
public class PropertySetEvent extends NamedEvent
|
||||
{
|
||||
/**
|
||||
* Create a PropertySetEvent.
|
||||
*/
|
||||
public function PropertySetEvent () // unserialize-only
|
||||
{
|
||||
super(0, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value that was set for the property.
|
||||
*/
|
||||
public function getValue () :Object
|
||||
{
|
||||
return _data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the old value.
|
||||
*/
|
||||
public function getOldValue () :Object
|
||||
{
|
||||
return _oldValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the index, or -1 if not applicable.
|
||||
*/
|
||||
public function getIndex () :int
|
||||
{
|
||||
return _index;
|
||||
}
|
||||
|
||||
override public function applyToObject (target :DObject) :Boolean
|
||||
{
|
||||
_oldValue =
|
||||
EZGameObject(target).applyPropertySet(_name, _data, _index);
|
||||
return true;
|
||||
}
|
||||
|
||||
override protected function notifyListener (listener :Object) :void
|
||||
{
|
||||
if (listener is PropertySetListener) {
|
||||
(listener as PropertySetListener).propertyWasSet(this);
|
||||
}
|
||||
}
|
||||
|
||||
override public function readObject (ins :ObjectInputStream) :void
|
||||
{
|
||||
super.readObject(ins);
|
||||
|
||||
_index = ins.readInt();
|
||||
_data = EZObjectMarshaller.decode(ins.readObject());
|
||||
}
|
||||
|
||||
/** The index of the property, if applicable. */
|
||||
protected var _index :int;
|
||||
|
||||
/** The client-side data that is assigned to this property. */
|
||||
protected var _data :Object;
|
||||
|
||||
/** The old value. */
|
||||
protected var _oldValue :Object;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.threerings.ezgame.data {
|
||||
|
||||
import com.threerings.presents.dobj.ChangeListener;
|
||||
|
||||
/**
|
||||
* A listener that will be notified of PropertySet events.
|
||||
*/
|
||||
public interface PropertySetListener extends ChangeListener
|
||||
{
|
||||
/**
|
||||
* Called when a property was set on a flash game object.
|
||||
* This will be called <em>after</em> the event has been applied
|
||||
* to the object.
|
||||
*/
|
||||
function propertyWasSet (event :PropertySetEvent) :void;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user