Hold on to your seats kids, it's another installment of "A Boy and His
Blowtorch". Refactored GameConfig and the EZ game framework, cleaning up some old cruft from GameConfig (which will break other projects and which I'll fix ASAP) and moved the XML based configuration system from ToyBox into EZGame. git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@286 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
@@ -27,179 +27,117 @@ import mx.controls.ComboBox;
|
||||
import mx.controls.HSlider;
|
||||
import mx.controls.Label;
|
||||
|
||||
import com.threerings.util.StreamableHashMap;
|
||||
import com.threerings.util.StringUtil;
|
||||
|
||||
import com.threerings.flex.LabeledSlider;
|
||||
|
||||
import com.threerings.parlor.game.client.FlexGameConfigurator;
|
||||
|
||||
import com.threerings.ezgame.data.ChoiceParameter;
|
||||
import com.threerings.ezgame.data.EZGameConfig;
|
||||
import com.threerings.ezgame.data.Parameter;
|
||||
import com.threerings.ezgame.data.RangeParameter;
|
||||
import com.threerings.ezgame.data.ToggleParameter;
|
||||
|
||||
/**
|
||||
* Adds custom configuration of options specified in XML.
|
||||
*/
|
||||
public class EZGameConfigurator extends FlexGameConfigurator
|
||||
{
|
||||
/**
|
||||
* Set XML game configuration options.
|
||||
*/
|
||||
public function setXMLConfig (config :XML) :void
|
||||
// from GameConfigurator
|
||||
override protected function gotGameConfig () :void
|
||||
{
|
||||
var log :Log = Log.getLog(this);
|
||||
super.gotGameConfig();
|
||||
|
||||
for each (var param :XML in config..params.children()) {
|
||||
if (StringUtil.isBlank(param.@ident)) {
|
||||
log.warning("Bad configuration option: no 'ident' in " +
|
||||
param + ", ignoring.");
|
||||
continue;
|
||||
}
|
||||
switch (param.localName().toLowerCase()) {
|
||||
case "range":
|
||||
addRangeOption(param, log);
|
||||
break;
|
||||
var params :Array = (_config as EZGameConfig).getGameDefinition().params;
|
||||
if (params == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
case "choice":
|
||||
addChoiceOption(param, log);
|
||||
break;
|
||||
for each (var param :Parameter in params) {
|
||||
if (param is RangeParameter) {
|
||||
var range :RangeParameter = (param as RangeParameter);
|
||||
var slider :HSlider = new HSlider();
|
||||
slider.minimum = range.minimum;
|
||||
slider.maximum = range.maximum;
|
||||
slider.value = range.start;
|
||||
slider.liveDragging = true;
|
||||
slider.snapInterval = 1;
|
||||
addLabeledControl(param, new LabeledSlider(slider));
|
||||
|
||||
case "toggle":
|
||||
addToggleOption(param, log);
|
||||
break;
|
||||
} else if (param is ChoiceParameter) {
|
||||
var choice :ChoiceParameter = (param as ChoiceParameter);
|
||||
var startDex :int = choice.choices.indexOf(choice.start);
|
||||
if (startDex == -1) {
|
||||
Log.getLog(this).warning(
|
||||
"Start value does not appear in list of choices [param=" + choice + "].");
|
||||
} else {
|
||||
var combo :ComboBox = new ComboBox();
|
||||
combo.dataProvider = choice.choices;
|
||||
combo.selectedIndex = startDex;
|
||||
addLabeledControl(param, combo);
|
||||
}
|
||||
|
||||
default:
|
||||
log.warning("Unknown XML configuration option: " + param +
|
||||
", ignoring.");
|
||||
break;
|
||||
} else if (param is ToggleParameter) {
|
||||
var check :CheckBox = new CheckBox();
|
||||
check.selected = (param as ToggleParameter).start;
|
||||
addLabeledControl(param, check);
|
||||
|
||||
} else {
|
||||
Log.getLog(this).warning("Unknown parameter in config [param=" + param + "].");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a control that came from parsing our custom option XML.
|
||||
*/
|
||||
protected function addXMLControl (spec :XML, control :UIComponent) :void
|
||||
{
|
||||
var ident :String = String(spec.@ident);
|
||||
var name :String = String(spec.@name);
|
||||
var tip :String = String(spec.@tip);
|
||||
if (StringUtil.isBlank(name)) {
|
||||
name = ident;
|
||||
}
|
||||
|
||||
var lbl :Label = new Label();
|
||||
lbl.text = name + ":";
|
||||
lbl.styleName = "lobbyLabel";
|
||||
lbl.toolTip = tip == "" ? name : tip;
|
||||
control.toolTip = tip == "" ? name : tip;
|
||||
|
||||
addControl(lbl, control);
|
||||
_customConfigs.push(ident, control);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a 'range' option specified in XML
|
||||
*/
|
||||
protected function addRangeOption (spec :XML, log :Log) :void
|
||||
{
|
||||
var min :Number = Number(spec.@minimum);
|
||||
var max :Number = Number(spec.@maximum);
|
||||
var start :Number = Number(spec.@start);
|
||||
if (isNaN(min) || isNaN(max) || isNaN(start)) {
|
||||
log.warning("Unable to parse range specification. " +
|
||||
"Required numeric values: minimum, maximum, start " +
|
||||
"[xml=" + spec + "].");
|
||||
return;
|
||||
}
|
||||
|
||||
var slider :HSlider = new HSlider();
|
||||
slider.minimum = min;
|
||||
slider.maximum = max;
|
||||
slider.value = start;
|
||||
slider.liveDragging = true;
|
||||
slider.snapInterval = 1;
|
||||
|
||||
addXMLControl(spec, new LabeledSlider(slider));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a 'choice' option specified in XML
|
||||
*/
|
||||
protected function addChoiceOption (spec :XML, log :Log) :void
|
||||
{
|
||||
if (spec.@choices.length == 0 || spec.@start.length == 0) {
|
||||
log.warning("Unable to parse choice specification. " +
|
||||
"Required 'choices' or 'start' is missing. " +
|
||||
"[xml=" + spec + "].");
|
||||
return;
|
||||
}
|
||||
|
||||
var choiceString :String = String(spec.@choices);
|
||||
var start :String = String(spec.@start);
|
||||
|
||||
var choices :Array = choiceString.split(",");
|
||||
var startDex :int = choices.indexOf(start);
|
||||
if (startDex == -1) {
|
||||
log.warning("Choice start value does not appear in list of choices "+
|
||||
"[xml=" + spec + "].");
|
||||
return;
|
||||
}
|
||||
|
||||
var box :ComboBox = new ComboBox();
|
||||
box.dataProvider = choices;
|
||||
box.selectedIndex = startDex;
|
||||
|
||||
addXMLControl(spec, box);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a 'toggle' option specified in XML
|
||||
*/
|
||||
protected function addToggleOption (spec :XML, log :Log) :void
|
||||
{
|
||||
if (spec.@start.length == 0) {
|
||||
log.warning("Unable to parse toggle specification. " +
|
||||
"Required 'start' is missing. " +
|
||||
"[xml=" + spec + "].");
|
||||
return;
|
||||
}
|
||||
|
||||
var startStr :String = String(spec.@start).toLowerCase();
|
||||
|
||||
var box :CheckBox = new CheckBox();
|
||||
box.selected = ("true" == startStr);
|
||||
|
||||
addXMLControl(spec, box);
|
||||
}
|
||||
|
||||
override protected function flushGameConfig () :void
|
||||
{
|
||||
super.flushGameConfig();
|
||||
|
||||
|
||||
// if there were any custom XML configs, flush those as well.
|
||||
if (_customConfigs.length > 0) {
|
||||
var options :Object = {};
|
||||
var params :StreamableHashMap = new StreamableHashMap();
|
||||
|
||||
for (var ii :int = 0; ii < _customConfigs.length; ii += 2) {
|
||||
var ident :String = String(_customConfigs[ii]);
|
||||
var control :UIComponent = (_customConfigs[ii + 1] as UIComponent);
|
||||
if (control is LabeledSlider) {
|
||||
options[ident] = (control as LabeledSlider).slider.value;
|
||||
params.put(ident, (control as LabeledSlider).slider.value);
|
||||
|
||||
} else if (control is CheckBox) {
|
||||
options[ident] = (control as CheckBox).selected;
|
||||
params.put(ident, (control as CheckBox).selected);
|
||||
|
||||
} else if (control is ComboBox) {
|
||||
options[ident] = (control as ComboBox).value;
|
||||
params.put(ident, (control as ComboBox).value);
|
||||
|
||||
} else {
|
||||
Log.getLog(this).warning("Unknow custom config type " + control);
|
||||
}
|
||||
}
|
||||
|
||||
(_config as EZGameConfig).customConfig = options;
|
||||
(_config as EZGameConfig).params = params;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a control that came from parsing our custom option XML.
|
||||
*/
|
||||
protected function addLabeledControl (param :Parameter, control :UIComponent) :void
|
||||
{
|
||||
if (StringUtil.isBlank(param.name)) {
|
||||
param.name = param.ident;
|
||||
}
|
||||
|
||||
var lbl :Label = new Label();
|
||||
lbl.text = param.name + ":";
|
||||
lbl.styleName = "lobbyLabel";
|
||||
lbl.toolTip = param.tip;
|
||||
control.toolTip = param.tip;
|
||||
|
||||
addControl(lbl, control);
|
||||
_customConfigs.push(param.ident, control);
|
||||
}
|
||||
|
||||
/** Contains pairs of identString, control, identString, control.. */
|
||||
protected var _customConfigs :Array = [];
|
||||
}
|
||||
|
||||
@@ -63,12 +63,11 @@ public class EZGamePanel extends Canvas
|
||||
_ezObj = (plobj as EZGameObject);
|
||||
backend = createBackend();
|
||||
|
||||
_gameView = new GameContainer(cfg.gameMedia);
|
||||
_gameView = new GameContainer(cfg.getGameDefinition().getMediaPath(cfg.getGameId()));
|
||||
_gameView.percentWidth = 100;
|
||||
_gameView.percentHeight = 100;
|
||||
backend.setSharedEvents(
|
||||
Loader(_gameView.getMediaContainer().getMedia()).
|
||||
contentLoaderInfo.sharedEvents);
|
||||
Loader(_gameView.getMediaContainer().getMedia()).contentLoaderInfo.sharedEvents);
|
||||
backend.setContainer(_gameView);
|
||||
addChild(_gameView);
|
||||
}
|
||||
|
||||
@@ -47,6 +47,7 @@ import com.threerings.util.Iterator;
|
||||
import com.threerings.util.MessageBundle;
|
||||
import com.threerings.util.Name;
|
||||
import com.threerings.util.StringUtil;
|
||||
import com.threerings.util.Wrapped;
|
||||
|
||||
import com.threerings.presents.client.ConfirmAdapter;
|
||||
import com.threerings.presents.client.ResultWrapper;
|
||||
@@ -176,7 +177,14 @@ public class GameControlBackend
|
||||
|
||||
// straight data
|
||||
o["gameData"] = _gameData;
|
||||
o["gameConfig"] = (_ctrl.getPlaceConfig() as EZGameConfig).customConfig;
|
||||
|
||||
// convert our game config from a HashMap to a Dictionary
|
||||
var gameConfig :Object = {};
|
||||
var cfg :EZGameConfig = (_ctrl.getPlaceConfig() as EZGameConfig);
|
||||
cfg.params.forEach(function (key :Object, value :Object) :void {
|
||||
gameConfig[key] = (value is Wrapped) ? Wrapped(value).unwrap() : value;
|
||||
});
|
||||
o["gameConfig"] = gameConfig;
|
||||
|
||||
// functions
|
||||
o["setProperty_v1"] = setProperty_v1;
|
||||
@@ -388,7 +396,7 @@ public class GameControlBackend
|
||||
var uc :UserCookie =
|
||||
(_ezObj.userCookies.get(playerId) as UserCookie);
|
||||
if (uc != null) {
|
||||
callback(uc.cookie);
|
||||
callback(EZObjectMarshaller.decode(uc.cookie));
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -901,7 +909,7 @@ public class GameControlBackend
|
||||
delete _cookieCallbacks[cookie.playerId];
|
||||
for each (var fn :Function in arr) {
|
||||
try {
|
||||
fn(cookie.cookie);
|
||||
fn(EZObjectMarshaller.decode(cookie.cookie));
|
||||
} catch (err :Error) {
|
||||
// cope
|
||||
}
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
//
|
||||
// $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.data {
|
||||
|
||||
import com.threerings.io.ObjectInputStream;
|
||||
import com.threerings.io.ObjectOutputStream;
|
||||
import com.threerings.io.TypedArray;
|
||||
|
||||
/**
|
||||
* Models a parameter that allows the selection of one of a list of choices (specified as strings).
|
||||
*/
|
||||
public class ChoiceParameter extends Parameter
|
||||
{
|
||||
/** The set of choices available for this parameter. */
|
||||
public var choices :TypedArray;
|
||||
|
||||
/** The starting selection. */
|
||||
public var start :String;
|
||||
|
||||
public function ChoiceParameter ()
|
||||
{
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
override public function getDefaultValue () :Object
|
||||
{
|
||||
return start;
|
||||
}
|
||||
|
||||
// from interface Streamable
|
||||
override public function readObject (ins :ObjectInputStream) :void
|
||||
{
|
||||
super.readObject(ins);
|
||||
choices = (ins.readObject() as TypedArray);
|
||||
start = (ins.readField(String) as String);
|
||||
}
|
||||
|
||||
// from interface Streamable
|
||||
override public function writeObject (out :ObjectOutputStream) :void
|
||||
{
|
||||
super.writeObject(out);
|
||||
out.writeObject(choices);
|
||||
out.writeField(start);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,7 @@ package com.threerings.ezgame.data {
|
||||
|
||||
import com.threerings.util.Hashable;
|
||||
import com.threerings.util.MessageBundle;
|
||||
import com.threerings.util.StreamableHashMap;
|
||||
|
||||
import com.threerings.io.ObjectInputStream;
|
||||
import com.threerings.io.ObjectOutputStream;
|
||||
@@ -39,53 +40,45 @@ import com.threerings.ezgame.util.EZObjectMarshaller;
|
||||
* A game config for a simple multiplayer ez game.
|
||||
*/
|
||||
public class EZGameConfig extends GameConfig
|
||||
implements Hashable
|
||||
{
|
||||
/** The name of the game. */
|
||||
public var name :String;
|
||||
/** Our configuration parameters. These will be seeded with the defaults from the game
|
||||
* definition and then configured by the player in the lobby. */
|
||||
public var params :StreamableHashMap = new StreamableHashMap();
|
||||
|
||||
/** If non-zero, a game id used to persistently identify the game.
|
||||
* This could be thought of as a new-style rating id. */
|
||||
public var persistentGameId:int;
|
||||
|
||||
/** The media for the game. In flash, this is the URL to the SWF file. */
|
||||
public var gameMedia :String;
|
||||
|
||||
/** The game type. */
|
||||
public var gameType :int = SEATED_GAME;
|
||||
|
||||
/** Any custom configuration options. */
|
||||
public var customConfig :Object;
|
||||
|
||||
public function EZGameConfig ()
|
||||
public function EZGameConfig (gameId :int = 0, gameDef :GameDefinition = null)
|
||||
{
|
||||
// nothing needed
|
||||
_gameId = gameId;
|
||||
_gameDef = gameDef;
|
||||
}
|
||||
|
||||
override public function getGameType () :int
|
||||
/** Returns the game definition associated with this config instance. */
|
||||
public function getGameDefinition () :GameDefinition
|
||||
{
|
||||
return gameType;
|
||||
return _gameDef;
|
||||
}
|
||||
|
||||
// from abstract GameConfig
|
||||
override public function getBundleName () :String
|
||||
// from GameConfig
|
||||
override public function getGameId () :int
|
||||
{
|
||||
return "general";
|
||||
return _gameId;
|
||||
}
|
||||
|
||||
// TODO
|
||||
//override public function createConfigurator () :GameConfigurator
|
||||
|
||||
|
||||
override public function getGameName () :String
|
||||
// from GameConfig
|
||||
override public function getGameIdent () :String
|
||||
{
|
||||
return MessageBundle.taint(name);
|
||||
return _gameDef.ident;
|
||||
}
|
||||
|
||||
// from PlaceConfig
|
||||
override public function createController () :PlaceController
|
||||
// from GameConfig
|
||||
override public function getMatchType () :int
|
||||
{
|
||||
return new EZGameController();
|
||||
return _gameDef.match.getMatchType();
|
||||
}
|
||||
|
||||
// from GameConfig
|
||||
override public function createConfigurator () :GameConfigurator
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// from abstract PlaceConfig
|
||||
@@ -94,46 +87,40 @@ public class EZGameConfig extends GameConfig
|
||||
throw new Error("Not implemented.");
|
||||
}
|
||||
|
||||
override public function hashCode () :int
|
||||
{
|
||||
return super.hashCode() ^ persistentGameId;
|
||||
}
|
||||
|
||||
override public function equals (other :Object) :Boolean
|
||||
{
|
||||
if (!super.equals(other)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var that :EZGameConfig = (other as EZGameConfig);
|
||||
return (this.persistentGameId == that.persistentGameId) &&
|
||||
(this.gameMedia === that.gameMedia);
|
||||
}
|
||||
|
||||
// from interface Streamable
|
||||
override public function readObject (ins :ObjectInputStream) :void
|
||||
{
|
||||
super.readObject(ins);
|
||||
|
||||
name = (ins.readField(String) as String)
|
||||
persistentGameId = ins.readInt();
|
||||
gameMedia = (ins.readField(String) as String);
|
||||
gameType = ins.readByte();
|
||||
|
||||
customConfig = EZObjectMarshaller.decode(ins.readObject());
|
||||
params = (ins.readObject() as StreamableHashMap);
|
||||
_gameId = ins.readInt();
|
||||
_gameDef = (ins.readObject() as GameDefinition);
|
||||
}
|
||||
|
||||
// from interface Streamable
|
||||
override public function writeObject (out :ObjectOutputStream) :void
|
||||
{
|
||||
super.writeObject(out);
|
||||
|
||||
out.writeField(name);
|
||||
out.writeInt(persistentGameId);
|
||||
out.writeField(gameMedia);
|
||||
out.writeByte(gameType);
|
||||
|
||||
out.writeObject(EZObjectMarshaller.encode(customConfig, false));
|
||||
out.writeObject(params);
|
||||
out.writeInt(_gameId);
|
||||
out.writeObject(_gameDef);
|
||||
}
|
||||
|
||||
/** Returns true if this is a party game, false otherwise. */
|
||||
public function isPartyGame () :Boolean
|
||||
{
|
||||
return getMatchType() == PARTY;
|
||||
}
|
||||
|
||||
// from PlaceConfig
|
||||
override public function createController () :PlaceController
|
||||
{
|
||||
return new EZGameController();
|
||||
}
|
||||
|
||||
/** Our game's unique id. */
|
||||
protected var _gameId :int;
|
||||
|
||||
/** Our game definition. */
|
||||
protected var _gameDef :GameDefinition;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
//
|
||||
// $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.data {
|
||||
|
||||
import com.threerings.io.ObjectInputStream;
|
||||
import com.threerings.io.ObjectOutputStream;
|
||||
import com.threerings.io.Streamable;
|
||||
import com.threerings.io.TypedArray;
|
||||
|
||||
/**
|
||||
* Contains the information about a game as described by the game definition XML file.
|
||||
*/
|
||||
public /*abstract*/ class GameDefinition
|
||||
implements Streamable
|
||||
{
|
||||
/** A string identifier for the game. */
|
||||
public var ident :String;
|
||||
|
||||
/** The class name of the <code>GameController</code> derivation that we use to bootstrap on
|
||||
* the client. */
|
||||
public var controller :String;
|
||||
|
||||
/** The class name of the <code>GameManager</code> derivation that we use to manage the game on
|
||||
* the server. */
|
||||
public var manager :String;
|
||||
|
||||
/** The MD5 digest of the game media file. */
|
||||
public var digest :String;
|
||||
|
||||
/** The configuration of the match-making mechanism. */
|
||||
public var match :MatchConfig;
|
||||
|
||||
/** Parameters used to configure the game itself. */
|
||||
public var params :TypedArray;
|
||||
|
||||
public function GameDefinition ()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides the path to this game's media (a jar file or an SWF).
|
||||
*
|
||||
* @param gameId the unique id of the game provided when this game definition was registered
|
||||
* with the system, or -1 if we're running in test mode.
|
||||
*/
|
||||
public function getMediaPath (gameId :int) :String
|
||||
{
|
||||
throw new Error("abstract");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if a single player can play this game (possibly against AI opponents), or if
|
||||
* opponents are needed.
|
||||
*/
|
||||
public function isSinglePlayerPlayable () :Boolean
|
||||
{
|
||||
throw new Error("Not implemented");
|
||||
}
|
||||
|
||||
/** Generates a string representation of this instance. */
|
||||
public function toString () :String
|
||||
{
|
||||
return "[ident=" + ident + ", ctrl=" + controller + ", mgr=" + manager +
|
||||
", match=" + match + ", params=" + params + ", digest=" + digest + "]";
|
||||
}
|
||||
|
||||
// from interface Streamable
|
||||
public function readObject (ins :ObjectInputStream) :void
|
||||
{
|
||||
ident = (ins.readField(String) as String);
|
||||
controller = (ins.readField(String) as String);
|
||||
manager = (ins.readField(String) as String);
|
||||
digest = (ins.readField(String) as String);
|
||||
match = (ins.readObject() as MatchConfig);
|
||||
params = (ins.readObject() as TypedArray);
|
||||
}
|
||||
|
||||
// from interface Streamable
|
||||
public function writeObject (out :ObjectOutputStream) :void
|
||||
{
|
||||
out.writeField(ident);
|
||||
out.writeField(controller);
|
||||
out.writeField(manager);
|
||||
out.writeField(digest);
|
||||
out.writeObject(match);
|
||||
out.writeObject(params);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
//
|
||||
// $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.data {
|
||||
|
||||
import com.threerings.io.SimpleStreamableObject;
|
||||
|
||||
import com.threerings.parlor.game.data.GameConfig;
|
||||
|
||||
/**
|
||||
* Used to configure the match-making interface for a game. Particular match-making mechanisms
|
||||
* extend this class and specify their own special configuration parameters.
|
||||
*/
|
||||
public /*abstract*/ class MatchConfig extends SimpleStreamableObject
|
||||
{
|
||||
public function MatchConfig ()
|
||||
{
|
||||
}
|
||||
|
||||
/** Returns the matchmaking type to use for this game, e.g. {@link GameConfig.SEATED_GAME}. */
|
||||
public function getMatchType () :int
|
||||
{
|
||||
throw new Error("Abstract");
|
||||
}
|
||||
|
||||
/** Returns the minimum number of players needed to play this game. */
|
||||
public function getMinimumPlayers () :int
|
||||
{
|
||||
throw new Error("Abstract");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
//
|
||||
// $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.data {
|
||||
|
||||
import com.threerings.io.ObjectInputStream;
|
||||
import com.threerings.io.ObjectOutputStream;
|
||||
import com.threerings.io.Streamable;
|
||||
|
||||
/**
|
||||
* Defines a configuration parameter for a game. Various derived classes exist that define
|
||||
* particular types of configuration parameters including choices, toggles, ranges, etc.
|
||||
*/
|
||||
public /*abstract*/ class Parameter
|
||||
implements Streamable
|
||||
{
|
||||
/** A string identifier that names this parameter. */
|
||||
public var ident :String;
|
||||
|
||||
/** A human readable name for this configuration parameter. */
|
||||
public var name :String;
|
||||
|
||||
/** A human readable tooltip to display when the mouse is hovered over this configuration
|
||||
* parameter. */
|
||||
public var tip :String;
|
||||
|
||||
public function Parameter ()
|
||||
{
|
||||
}
|
||||
|
||||
public function toString () :String
|
||||
{
|
||||
return ident;
|
||||
}
|
||||
|
||||
public function getDefaultValue () :Object
|
||||
{
|
||||
throw new Error("Abstract");
|
||||
}
|
||||
|
||||
/** Returns the translation key for this parameter's label. */
|
||||
public function getLabel () :String
|
||||
{
|
||||
return "m." + ident;
|
||||
}
|
||||
|
||||
// from interface Streamable
|
||||
public function readObject (ins :ObjectInputStream) :void
|
||||
{
|
||||
ident = (ins.readField(String) as String);
|
||||
name = (ins.readField(String) as String);
|
||||
tip = (ins.readField(String) as String);
|
||||
}
|
||||
|
||||
// from interface Streamable
|
||||
public function writeObject (out :ObjectOutputStream) :void
|
||||
{
|
||||
out.writeField(ident);
|
||||
out.writeField(name);
|
||||
out.writeField(tip);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -53,8 +53,7 @@ public class PropertySetEvent extends NamedEvent
|
||||
override public function applyToObject (target :DObject) :Boolean
|
||||
{
|
||||
// since we're in actionscript, we're always on the client
|
||||
_oldValue =
|
||||
EZGameObject(target).applyPropertySet(_name, _data, _index);
|
||||
_oldValue = EZGameObject(target).applyPropertySet(_name, _data, _index);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -63,7 +62,7 @@ public class PropertySetEvent extends NamedEvent
|
||||
*/
|
||||
public function getValue () :Object
|
||||
{
|
||||
return _data;
|
||||
return EZObjectMarshaller.decode(_data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -87,7 +86,7 @@ public class PropertySetEvent extends NamedEvent
|
||||
{
|
||||
super.readObject(ins);
|
||||
_index = ins.readInt();
|
||||
_data = EZObjectMarshaller.decode(ins.readObject());
|
||||
_data = (ins.readObject() as Object);
|
||||
}
|
||||
|
||||
// from interface Streamable
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
//
|
||||
// $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.data {
|
||||
|
||||
import com.threerings.io.ObjectInputStream;
|
||||
import com.threerings.io.ObjectOutputStream;
|
||||
|
||||
/**
|
||||
* Models a parameter that can contain an integer value in a specified range.
|
||||
*/
|
||||
public class RangeParameter extends Parameter
|
||||
{
|
||||
/** The minimum value of this parameter. */
|
||||
public var minimum :int;
|
||||
|
||||
/** The maximum value of this parameter. */
|
||||
public var maximum :int;
|
||||
|
||||
/** The starting value for this parameter. */
|
||||
public var start :int;
|
||||
|
||||
public function RangeParameter ()
|
||||
{
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
override public function getDefaultValue () :Object
|
||||
{
|
||||
return start;
|
||||
}
|
||||
|
||||
// from interface Streamable
|
||||
override public function readObject (ins :ObjectInputStream) :void
|
||||
{
|
||||
super.readObject(ins);
|
||||
minimum = ins.readInt();
|
||||
maximum = ins.readInt();
|
||||
start = ins.readInt();
|
||||
}
|
||||
|
||||
// from interface Streamable
|
||||
override public function writeObject (out :ObjectOutputStream) :void
|
||||
{
|
||||
super.writeObject(out);
|
||||
out.writeInt(minimum);
|
||||
out.writeInt(maximum);
|
||||
out.writeInt(start);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
//
|
||||
// $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.data {
|
||||
|
||||
import com.threerings.io.ObjectInputStream;
|
||||
import com.threerings.io.ObjectOutputStream;
|
||||
|
||||
import com.threerings.parlor.game.data.GameConfig;
|
||||
|
||||
/**
|
||||
* Extends {@link MatchConfig} with information about match-making in the table style.
|
||||
*/
|
||||
public class TableMatchConfig extends MatchConfig
|
||||
{
|
||||
/** The minimum number of seats at this table. */
|
||||
public var minSeats :int;
|
||||
|
||||
/** The starting setting for the number of seats at this table. */
|
||||
public var startSeats :int;
|
||||
|
||||
/** The maximum number of seats at this table. */
|
||||
public var maxSeats :int;
|
||||
|
||||
/** This is set to true if this is a party game. */
|
||||
public var isPartyGame :Boolean;
|
||||
|
||||
public function TableMatchConfig ()
|
||||
{
|
||||
}
|
||||
|
||||
// from MatchConfig
|
||||
override public function getMatchType () :int
|
||||
{
|
||||
return isPartyGame ? GameConfig.PARTY : GameConfig.SEATED_GAME;
|
||||
}
|
||||
|
||||
// from MatchConfig
|
||||
override public function getMinimumPlayers () :int
|
||||
{
|
||||
return minSeats;
|
||||
}
|
||||
|
||||
// from interface Streamable
|
||||
override public function readObject (ins :ObjectInputStream) :void
|
||||
{
|
||||
super.readObject(ins);
|
||||
minSeats = ins.readInt();
|
||||
startSeats = ins.readInt();
|
||||
maxSeats = ins.readInt();
|
||||
isPartyGame = ins.readBoolean();
|
||||
}
|
||||
|
||||
// from interface Streamable
|
||||
override public function writeObject (out :ObjectOutputStream) :void
|
||||
{
|
||||
super.writeObject(out);
|
||||
out.writeInt(minSeats);
|
||||
out.writeInt(startSeats);
|
||||
out.writeInt(maxSeats);
|
||||
out.writeBoolean(isPartyGame);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
//
|
||||
// $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.data {
|
||||
|
||||
import com.threerings.io.ObjectInputStream;
|
||||
import com.threerings.io.ObjectOutputStream;
|
||||
|
||||
/**
|
||||
* Models a parameter that allows the toggling of a single value.
|
||||
*/
|
||||
public class ToggleParameter extends Parameter
|
||||
{
|
||||
/** The starting state for this parameter. */
|
||||
public var start :Boolean;
|
||||
|
||||
public function ToggleParameter ()
|
||||
{
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
override public function getDefaultValue () :Object
|
||||
{
|
||||
return start;
|
||||
}
|
||||
|
||||
// from interface Streamable
|
||||
override public function readObject (ins :ObjectInputStream) :void
|
||||
{
|
||||
super.readObject(ins);
|
||||
start = ins.readBoolean();
|
||||
}
|
||||
|
||||
// from interface Streamable
|
||||
override public function writeObject (out :ObjectOutputStream) :void
|
||||
{
|
||||
super.writeObject(out);
|
||||
out.writeBoolean(start);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,16 +28,23 @@ import com.threerings.io.ObjectOutputStream;
|
||||
|
||||
import com.threerings.presents.dobj.DSet_Entry;
|
||||
|
||||
import com.threerings.ezgame.util.EZObjectMarshaller;
|
||||
|
||||
/**
|
||||
* Represents a user's game-specific cookie data.
|
||||
*/
|
||||
public class UserCookie
|
||||
implements DSet_Entry
|
||||
{
|
||||
/** The id of the player that has this cookie. */
|
||||
public var playerId :int;
|
||||
|
||||
/** The decoded cookie value. */
|
||||
public var cookie :Object;
|
||||
/** The cookie value. */
|
||||
public var cookie :ByteArray;
|
||||
|
||||
public function UserCookie (playerId :int = 0, cookie :ByteArray = null)
|
||||
{
|
||||
this.playerId = playerId;
|
||||
this.cookie = cookie;
|
||||
}
|
||||
|
||||
// from DSet_Entry
|
||||
public function getKey () :Object
|
||||
@@ -49,14 +56,14 @@ public class UserCookie
|
||||
public function readObject (ins :ObjectInputStream) :void
|
||||
{
|
||||
playerId = ins.readInt();
|
||||
var ba :ByteArray = (ins.readField(ByteArray) as ByteArray);
|
||||
cookie = EZObjectMarshaller.decode(ba);
|
||||
cookie = (ins.readField(ByteArray) as ByteArray);
|
||||
}
|
||||
|
||||
// from superinterface Streamable
|
||||
public function writeObject (out :ObjectOutputStream) :void
|
||||
{
|
||||
throw new Error();
|
||||
out.writeInt(playerId);
|
||||
out.writeField(cookie);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user