EZGameControl updates:
- switched everything to be based on playerId instead of index (which doesn't make sense for a party game.) - started adding new functions - backwards compatible with all old games! git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@186 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
@@ -282,17 +282,17 @@ public class EZGameControl extends EventDispatcher
|
||||
* @param count the number of elements to pick
|
||||
* @param msgOrPropName the name of the message or property
|
||||
* that will contain the picked elements.
|
||||
* @param playerIndex if -1 (or unset), the picked elements should be
|
||||
* @param playerId if 0 (or unset), the picked elements should be
|
||||
* set on the gameObject as a property for all to see.
|
||||
* If a playerIndex is specified, only that player will receive
|
||||
* If a playerId is specified, only that player will receive
|
||||
* the elements as a message.
|
||||
*/
|
||||
// TODO: a way to specify exclusive picks vs. duplicate-OK picks?
|
||||
public function pickFromCollection (
|
||||
collName :String, count :int, msgOrPropName :String,
|
||||
playerIndex :int = -1) :void
|
||||
playerId :int = 0) :void
|
||||
{
|
||||
getFromCollection(collName, count, msgOrPropName, playerIndex,
|
||||
getFromCollection(collName, count, msgOrPropName, playerId,
|
||||
false, null);
|
||||
}
|
||||
|
||||
@@ -305,17 +305,17 @@ public class EZGameControl extends EventDispatcher
|
||||
* @param count the number of elements to pick
|
||||
* @param msgOrPropName the name of the message or property
|
||||
* that will contain the picked elements.
|
||||
* @param playerIndex if -1 (or unset), the picked elements should be
|
||||
* @param playerId if 0 (or unset), the picked elements should be
|
||||
* set on the gameObject as a property for all to see.
|
||||
* If a playerIndex is specified, only that player will receive
|
||||
* If a playerId is specified, only that player will receive
|
||||
* the elements as a message.
|
||||
*/
|
||||
// TODO: figure out the method signature of the callback
|
||||
public function dealFromCollection (
|
||||
collName :String, count :int, msgOrPropName :String,
|
||||
callback :Function = null, playerIndex :int = -1) :void
|
||||
callback :Function = null, playerId :int = 0) :void
|
||||
{
|
||||
getFromCollection(collName, count, msgOrPropName, playerIndex,
|
||||
getFromCollection(collName, count, msgOrPropName, playerId,
|
||||
true, callback);
|
||||
}
|
||||
|
||||
@@ -336,13 +336,13 @@ public class EZGameControl extends EventDispatcher
|
||||
* value will not be saved- it will merely end up coming out
|
||||
* as a MessageReceivedEvent.
|
||||
*
|
||||
* @param playerIndex if -1, sends to all players, otherwise
|
||||
* @param playerId if 0 (or unset), sends to all players, otherwise
|
||||
* the message will be private to just one player
|
||||
*/
|
||||
public function sendMessage (
|
||||
messageName :String, value :Object, playerIndex :int = -1) :void
|
||||
messageName :String, value :Object, playerId :int = 0) :void
|
||||
{
|
||||
callEZCode("sendMessage_v1", messageName, value, playerIndex);
|
||||
callEZCode("sendMessage_v2", messageName, value, playerId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -382,45 +382,52 @@ public class EZGameControl extends EventDispatcher
|
||||
callEZCode("localChat_v1", msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of players currently in the game.
|
||||
*/
|
||||
public function getPlayerCount () :int
|
||||
// TODO: NEW
|
||||
public function getOccupants () :Array /* of playerId */
|
||||
{
|
||||
return int(callEZCode("getPlayerCount_v1"));
|
||||
return (callEZCode("getOccupants_v1") as Array);
|
||||
}
|
||||
|
||||
// TODO: NEW
|
||||
/**
|
||||
* Get the player names, as an array.
|
||||
* Get the display name of the specified occupant.
|
||||
* Two players may have the same name: always use playerId to
|
||||
* purposes of identification and comparison. The name is for display
|
||||
* only.
|
||||
*/
|
||||
public function getPlayerNames () :Array
|
||||
public function getOccupantName (playerId :int) :String
|
||||
{
|
||||
return (callEZCode("getPlayerNames_v1") as Array);
|
||||
return String(callEZCode("getOccupantName_v1", playerId));
|
||||
}
|
||||
|
||||
// TODO: NEW: Table control
|
||||
/**
|
||||
* Get the index into the player names array of the current player,
|
||||
* or -1 if the user is not a player.
|
||||
* Get the player's position, or -1 if not a player.
|
||||
*/
|
||||
public function getMyIndex () :int
|
||||
public function getPlayerPosition (playerId :int) :int
|
||||
{
|
||||
return int(callEZCode("getMyIndex_v1"));
|
||||
return int(callEZCode("getPlayerPosition_v1", playerId));
|
||||
}
|
||||
|
||||
// TODO: NEW: Table control
|
||||
/**
|
||||
* Get the turn holder's index, or -1 if it's nobody's turn.
|
||||
* Get all the players at the table, in their seated position.
|
||||
* Absent players will be represented by a 0.
|
||||
*/
|
||||
public function getTurnHolderIndex () :int
|
||||
public function getPlayers () :Array /* of playerId (int) */
|
||||
{
|
||||
return int(callEZCode("getTurnHolderIndex_v1"));
|
||||
return (callEZCode("getPlayers_v1") as Array);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the indexes of the winners
|
||||
*/
|
||||
public function getWinnerIndexes () :Array /* of int */
|
||||
// TODO: NEW
|
||||
public function getMyId () :int
|
||||
{
|
||||
return (callEZCode("getWinnerIndexes_v1") as Array);
|
||||
return int(callEZCode("getMyId_v1"));
|
||||
}
|
||||
|
||||
public function getTurnHolder () :int
|
||||
{
|
||||
return int(callEZCode("getTurnHolder_v1"));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -428,9 +435,9 @@ public class EZGameControl extends EventDispatcher
|
||||
* first time this is requested per game instance it will be retrieved
|
||||
* from the database. After that, it will be returned from memory.
|
||||
*/
|
||||
public function getUserCookie (playerIndex :int, callback :Function) :void
|
||||
public function getUserCookie (playerId :int, callback :Function) :void
|
||||
{
|
||||
callEZCode("getUserCookie_v1", playerIndex, callback);
|
||||
callEZCode("getUserCookie_v1", playerId, callback);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -469,21 +476,21 @@ public class EZGameControl extends EventDispatcher
|
||||
}
|
||||
|
||||
/**
|
||||
* End the current turn. If no next player index is specified,
|
||||
* End the current turn. If no next player id is specified,
|
||||
* then the next player after the current one is used.
|
||||
*/
|
||||
public function endTurn (nextPlayerIndex :int = -1) :void
|
||||
public function endTurn (nextPlayerId :int = 0) :void
|
||||
{
|
||||
callEZCode("endTurn_v1", nextPlayerIndex);
|
||||
callEZCode("endTurn_v2", nextPlayerId);
|
||||
}
|
||||
|
||||
/**
|
||||
* End the game. The specified player indexes are winners!
|
||||
* End the game. The specified player ids are winners!
|
||||
*/
|
||||
public function endGame (... winnerIndexes) :void
|
||||
public function endGame (... winnerIds) :void
|
||||
{
|
||||
var args :Array = winnerIndexes;
|
||||
args.unshift("endGame_v1");
|
||||
var args :Array = winnerIds;
|
||||
args.unshift("endGame_v2");
|
||||
|
||||
// goddamn var-args complications in actionscript
|
||||
callEZCode.apply(null, args);
|
||||
@@ -514,11 +521,11 @@ public class EZGameControl extends EventDispatcher
|
||||
* Helper method for pickFromCollection and dealFromCollection.
|
||||
*/
|
||||
protected function getFromCollection (
|
||||
collName :String, count :int, msgOrPropName :String, playerIndex :int,
|
||||
collName :String, count :int, msgOrPropName :String, playerId :int,
|
||||
consume :Boolean, callback :Function) :void
|
||||
{
|
||||
callEZCode("getFromCollection_v1", collName, count, msgOrPropName,
|
||||
playerIndex, consume, callback);
|
||||
callEZCode("getFromCollection_v2", collName, count, msgOrPropName,
|
||||
playerId, consume, callback);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -61,11 +61,13 @@ public class PlayersDisplay extends Sprite
|
||||
maxWidth = label.textWidth;
|
||||
}
|
||||
|
||||
var players :Array = _gameCtrl.getPlayers();
|
||||
|
||||
// create a label for each player
|
||||
var playerIndex :int = 0;
|
||||
for each (var name :String in _gameCtrl.getPlayerNames()) {
|
||||
label = createPlayerLabel(playerIndex, name);
|
||||
icon = createPlayerIcon(playerIndex, name);
|
||||
for each (var playerId :int in players) {
|
||||
var name :String = _gameCtrl.getOccupantName(playerId);
|
||||
label = createPlayerLabel(playerId, name);
|
||||
icon = createPlayerIcon(playerId, name);
|
||||
var iconW :int = 0;
|
||||
var iconH :int = 0;
|
||||
if (icon != null) {
|
||||
@@ -83,7 +85,6 @@ public class PlayersDisplay extends Sprite
|
||||
maxWidth = Math.max(maxWidth, iconW + label.textWidth);
|
||||
|
||||
_playerLabels.push(label);
|
||||
playerIndex++;
|
||||
}
|
||||
|
||||
// make all the player labels the same width
|
||||
@@ -123,7 +124,7 @@ public class PlayersDisplay extends Sprite
|
||||
/**
|
||||
* Create a TextArea that will be used to display player names.
|
||||
*/
|
||||
protected function createPlayerLabel (idx :int, name :String) :TextField
|
||||
protected function createPlayerLabel (playerId :int, name :String) :TextField
|
||||
{
|
||||
var label :TextField = new TextField();
|
||||
label.autoSize = TextFieldAutoSize.LEFT;
|
||||
@@ -133,7 +134,7 @@ public class PlayersDisplay extends Sprite
|
||||
return label;
|
||||
}
|
||||
|
||||
protected function createPlayerIcon (idx :int, name :String) :DisplayObject
|
||||
protected function createPlayerIcon (playerId :int, name :String) :DisplayObject
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@@ -159,7 +160,7 @@ public class PlayersDisplay extends Sprite
|
||||
*/
|
||||
protected function displayCurrentTurn () :void
|
||||
{
|
||||
var idx :int = _gameCtrl.isInPlay() ? _gameCtrl.getTurnHolderIndex() : -1;
|
||||
var idx :int = _gameCtrl.isInPlay() ? _gameCtrl.getPlayerPosition(_gameCtrl.getTurnHolder()) : -1;
|
||||
for (var ii :int = 0; ii < _playerLabels.length; ii++) {
|
||||
var label :TextField = (_playerLabels[ii] as TextField);
|
||||
label.backgroundColor = getBackground(ii == idx);
|
||||
|
||||
@@ -19,6 +19,7 @@ import flash.utils.getQualifiedSuperclassName;
|
||||
|
||||
import com.threerings.io.TypedArray;
|
||||
|
||||
import com.threerings.util.ArrayUtil;
|
||||
import com.threerings.util.ClassUtil;
|
||||
import com.threerings.util.Integer;
|
||||
import com.threerings.util.Iterator;
|
||||
@@ -125,27 +126,40 @@ public class GameControlBackend
|
||||
// functions
|
||||
o["setProperty_v1"] = setProperty_v1;
|
||||
o["mergeCollection_v1"] = mergeCollection_v1;
|
||||
o["sendMessage_v1"] = sendMessage_v1;
|
||||
o["setTicker_v1"] = setTicker_v1;
|
||||
o["sendChat_v1"] = sendChat_v1;
|
||||
o["localChat_v1"] = localChat_v1;
|
||||
o["getPlayerCount_v1"] = getPlayerCount_v1;
|
||||
o["setUserCookie_v1"] = setUserCookie_v1;
|
||||
o["isMyTurn_v1"] = isMyTurn_v1;
|
||||
o["isInPlay_v1"] = isInPlay_v1;
|
||||
o["getDictionaryLetterSet_v1"] = getDictionaryLetterSet_v1;
|
||||
o["checkDictionaryWord_v1"] = checkDictionaryWord_v1;
|
||||
o["populateCollection_v1"] = populateCollection_v1;
|
||||
o["alterKeyEvents_v1"] = alterKeyEvents_v1;
|
||||
o["focusContainer_v1"] = focusContainer_v1;
|
||||
|
||||
// newest
|
||||
o["getFromCollection_v2"] = getFromCollection_v2;
|
||||
o["sendMessage_v2"] = sendMessage_v2;
|
||||
o["getOccupants_v1"] = getOccupants_v1;
|
||||
o["getMyId_v1"] = getMyId_v1;
|
||||
o["getUserCookie_v2"] = getUserCookie_v2;
|
||||
o["endTurn_v2"] = endTurn_v2;
|
||||
o["endGame_v2"] = endGame_v2;
|
||||
o["getTurnHolder_v1"] = getTurnHolder_v1;
|
||||
o["getPlayers_v1"] = getPlayers_v1;
|
||||
|
||||
// deprecated, will be removed soon
|
||||
o["getFromCollection_v1"] = getFromCollection_v1;
|
||||
o["sendMessage_v1"] = sendMessage_v1;
|
||||
o["getPlayerCount_v1"] = getPlayerCount_v1; // no replacement
|
||||
o["getPlayerNames_v1"] = getPlayerNames_v1;
|
||||
o["getMyIndex_v1"] = getMyIndex_v1;
|
||||
o["getTurnHolderIndex_v1"] = getTurnHolderIndex_v1;
|
||||
o["getWinnerIndexes_v1"] = getWinnerIndexes_v1;
|
||||
o["getUserCookie_v1"] = getUserCookie_v1;
|
||||
o["setUserCookie_v1"] = setUserCookie_v1;
|
||||
o["isMyTurn_v1"] = isMyTurn_v1;
|
||||
o["isInPlay_v1"] = isInPlay_v1;
|
||||
o["endTurn_v1"] = endTurn_v1;
|
||||
o["endGame_v1"] = endGame_v1;
|
||||
o["getDictionaryLetterSet_v1"] = getDictionaryLetterSet_v1;
|
||||
o["checkDictionaryWord_v1"] = checkDictionaryWord_v1;
|
||||
o["populateCollection_v1"] = populateCollection_v1;
|
||||
o["getFromCollection_v1"] = getFromCollection_v1;
|
||||
o["alterKeyEvents_v1"] = alterKeyEvents_v1;
|
||||
o["focusContainer_v1"] = focusContainer_v1;
|
||||
}
|
||||
|
||||
public function setProperty_v1 (
|
||||
@@ -171,15 +185,15 @@ public class GameControlBackend
|
||||
srcColl, intoColl, createLoggingConfirmListener("mergeCollection"));
|
||||
}
|
||||
|
||||
public function sendMessage_v1 (
|
||||
messageName :String, value :Object, playerIndex :int) :void
|
||||
public function sendMessage_v2 (
|
||||
messageName :String, value :Object, playerId :int) :void
|
||||
{
|
||||
validateName(messageName);
|
||||
validateValue(value);
|
||||
|
||||
var encoded :Object = EZObjectMarshaller.encode(value, false);
|
||||
_ezObj.ezGameService.sendMessage(_ctx.getClient(),
|
||||
messageName, encoded, playerIndex,
|
||||
messageName, encoded, playerId,
|
||||
createLoggingConfirmListener("sendMessage"));
|
||||
}
|
||||
|
||||
@@ -207,74 +221,63 @@ public class GameControlBackend
|
||||
_ctx.getChatDirector().displayInfo(null, MessageBundle.taint(msg));
|
||||
}
|
||||
|
||||
public function getPlayerCount_v1 () :int
|
||||
public function getOccupants_v1 () :Array
|
||||
{
|
||||
if (_ezObj.players.length == 0) {
|
||||
// party game
|
||||
return _ezObj.occupants.size();
|
||||
|
||||
} else {
|
||||
return _ezObj.getPlayerCount();
|
||||
}
|
||||
var occs :Array = [];
|
||||
for (var ii :int = _ezObj.occupants.size() - 1; ii >= 0; ii--) {
|
||||
occs.push(_ezObj.occupants.get(ii));
|
||||
}
|
||||
|
||||
public function getPlayerNames_v1 () :Array
|
||||
return occs;
|
||||
}
|
||||
|
||||
public function getPlayers_v1 () :Array
|
||||
{
|
||||
var names :Array = new Array();
|
||||
if (_ezObj.players.length == 0) {
|
||||
// party game, count all occupants
|
||||
var itr :Iterator = _ezObj.occupantInfo.iterator();
|
||||
while (itr.hasNext()) {
|
||||
var occInfo :OccupantInfo = (itr.next() as OccupantInfo);
|
||||
names.push(occInfo.username.toString());
|
||||
var playerIds :Array = [];
|
||||
for (var ii :int = 0; ii < _ezObj.players.length; ii++) {
|
||||
var occInfo :OccupantInfo = _ezObj.getOccupantInfo(_ezObj.players[ii] as Name);
|
||||
playerIds.push((occInfo == null) ? 0 : occInfo.bodyOid);
|
||||
}
|
||||
return playerIds;
|
||||
}
|
||||
|
||||
} else {
|
||||
for each (var name :Name in _ezObj.players) {
|
||||
names.push((name == null) ? null : name.toString());
|
||||
}
|
||||
}
|
||||
return names;
|
||||
}
|
||||
|
||||
public function getMyIndex_v1 () :int
|
||||
public function getOccupantName_v1 (playerId :int) :String
|
||||
{
|
||||
if (_ezObj.players.length == 0) {
|
||||
// party game
|
||||
// TODO: this shouldn't be based off of the String form of the name.
|
||||
var array :Array = getPlayerNames_v1();
|
||||
return array.indexOf(getUsername().toString());
|
||||
|
||||
} else {
|
||||
return _ezObj.getPlayerIndex(getUsername());
|
||||
}
|
||||
var occInfo :OccupantInfo =
|
||||
(_ezObj.occupantInfo.get(playerId) as OccupantInfo);
|
||||
return (occInfo == null) ? null : occInfo.username.toString();
|
||||
}
|
||||
|
||||
public function getTurnHolderIndex_v1 () :int
|
||||
public function getMyId_v1 () :int
|
||||
{
|
||||
return _ezObj.getPlayerIndex(_ezObj.turnHolder);
|
||||
return _ctx.getClient().getClientObject().getOid();
|
||||
}
|
||||
|
||||
public function getWinnerIndexes_v1 () :Array /* of int */
|
||||
// TODO: table games only
|
||||
public function getPlayerPosition_v1 (playerId :int) :int
|
||||
{
|
||||
var arr :Array = new Array();
|
||||
if (_ezObj.winners != null) {
|
||||
for (var ii :int = 0; ii < _ezObj.winners.length; ii++) {
|
||||
if (_ezObj.winners[ii]) {
|
||||
arr.push(ii);
|
||||
var occInfo :OccupantInfo =
|
||||
(_ezObj.occupantInfo.get(playerId) as OccupantInfo);
|
||||
if (occInfo == null) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return arr;
|
||||
return ArrayUtil.indexOf(_ezObj.players, occInfo.username);
|
||||
}
|
||||
|
||||
public function getUserCookie_v1 (
|
||||
playerIndex :int, callback :Function) :void
|
||||
// TODO: table only
|
||||
public function getTurnHolder_v1 () :int
|
||||
{
|
||||
var occInfo :OccupantInfo = _ezObj.getOccupantInfo(_ezObj.turnHolder);
|
||||
return (occInfo == null) ? 0 : occInfo.bodyOid;
|
||||
}
|
||||
|
||||
public function getUserCookie_v2 (
|
||||
playerId :int, callback :Function) :void
|
||||
{
|
||||
// see if that cookie is already published
|
||||
if (_ezObj.userCookies != null) {
|
||||
var uc :UserCookie =
|
||||
(_ezObj.userCookies.get(playerIndex) as UserCookie);
|
||||
(_ezObj.userCookies.get(playerId) as UserCookie);
|
||||
if (uc != null) {
|
||||
callback(uc.cookie);
|
||||
return;
|
||||
@@ -284,15 +287,15 @@ public class GameControlBackend
|
||||
if (_cookieCallbacks == null) {
|
||||
_cookieCallbacks = new Dictionary();
|
||||
}
|
||||
var arr :Array = (_cookieCallbacks[playerIndex] as Array);
|
||||
var arr :Array = (_cookieCallbacks[playerId] as Array);
|
||||
if (arr == null) {
|
||||
arr = [];
|
||||
_cookieCallbacks[playerIndex] = arr;
|
||||
_cookieCallbacks[playerId] = arr;
|
||||
}
|
||||
arr.push(callback);
|
||||
|
||||
// request it to be made so by the server
|
||||
_ezObj.ezGameService.getCookie(_ctx.getClient(), playerIndex,
|
||||
_ezObj.ezGameService.getCookie(_ctx.getClient(), playerId,
|
||||
createLoggingConfirmListener("getUserCookie"));
|
||||
}
|
||||
|
||||
@@ -320,17 +323,17 @@ public class GameControlBackend
|
||||
return _ezObj.isInPlay();
|
||||
}
|
||||
|
||||
public function endTurn_v1 (nextPlayerIndex :int = -1) :void
|
||||
public function endTurn_v2 (nextPlayerId :int) :void
|
||||
{
|
||||
_ezObj.ezGameService.endTurn(_ctx.getClient(), nextPlayerIndex,
|
||||
_ezObj.ezGameService.endTurn(_ctx.getClient(), nextPlayerId,
|
||||
createLoggingConfirmListener("endTurn"));
|
||||
}
|
||||
|
||||
public function endGame_v1 (... winnerDexes) :void
|
||||
public function endGame_v2 (... winnerIds) :void
|
||||
{
|
||||
var winners :TypedArray = TypedArray.create(int);
|
||||
while (winnerDexes.length > 0) {
|
||||
winners.push(int(winnerDexes.shift()));
|
||||
while (winnerIds.length > 0) {
|
||||
winners.push(int(winnerIds.shift()));
|
||||
}
|
||||
_ezObj.ezGameService.endGame(_ctx.getClient(), winners,
|
||||
createLoggingConfirmListener("endGame"));
|
||||
@@ -406,8 +409,8 @@ public class GameControlBackend
|
||||
/**
|
||||
* Helper method for pickFromCollection and dealFromCollection.
|
||||
*/
|
||||
public function getFromCollection_v1 (
|
||||
collName :String, count :int, msgOrPropName :String, playerIndex :int,
|
||||
public function getFromCollection_v2 (
|
||||
collName :String, count :int, msgOrPropName :String, playerId :int,
|
||||
consume :Boolean, callback :Function) :void
|
||||
{
|
||||
validateName(collName);
|
||||
@@ -435,7 +438,7 @@ public class GameControlBackend
|
||||
|
||||
_ezObj.ezGameService.getFromCollection(
|
||||
_ctx.getClient(), collName, consume, count, msgOrPropName,
|
||||
playerIndex, listener);
|
||||
playerId, listener);
|
||||
}
|
||||
|
||||
public function alterKeyEvents_v1 (
|
||||
@@ -675,16 +678,15 @@ public class GameControlBackend
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handle the arrival of a new UserCookie.
|
||||
*/
|
||||
protected function receivedUserCookie (cookie :UserCookie) :void
|
||||
{
|
||||
if (_cookieCallbacks != null) {
|
||||
var arr :Array = (_cookieCallbacks[cookie.playerIndex] as Array);
|
||||
var arr :Array = (_cookieCallbacks[cookie.playerId] as Array);
|
||||
if (arr != null) {
|
||||
delete _cookieCallbacks[cookie.playerIndex];
|
||||
delete _cookieCallbacks[cookie.playerId];
|
||||
for each (var fn :Function in arr) {
|
||||
try {
|
||||
fn(cookie.cookie);
|
||||
@@ -696,6 +698,131 @@ public class GameControlBackend
|
||||
}
|
||||
}
|
||||
|
||||
// Some methods included for backwards compatability.
|
||||
// Most of these were only ever used internally, so we should be able to
|
||||
// get rid of them sooner rather than later.
|
||||
|
||||
/**
|
||||
* BackCompat: turn a player index into an oid.
|
||||
*/
|
||||
protected function indexToId (index :int) :int
|
||||
{
|
||||
var name :Name = _ezObj.players[index];
|
||||
if (name != null) {
|
||||
var occInfo :OccupantInfo = _ezObj.getOccupantInfo(name);
|
||||
if (occInfo != null) {
|
||||
return occInfo.bodyOid;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// OLD
|
||||
protected function getFromCollection_v1 (
|
||||
collName :String, count :int, msgOrPropName :String,
|
||||
playerIndex :int, consume :Boolean, callback :Function) :void
|
||||
{
|
||||
getFromCollection_v2(collName, count, msgOrPropName,
|
||||
indexToId(playerIndex), consume, callback);
|
||||
}
|
||||
|
||||
// OLD
|
||||
public function sendMessage_v1 (
|
||||
messageName :String, value :Object, playerIndex :int) :void
|
||||
{
|
||||
sendMessage_v2(messageName, value, indexToId(playerIndex));
|
||||
}
|
||||
|
||||
// OLD
|
||||
public function getPlayerCount_v1 () :int
|
||||
{
|
||||
if (_ezObj.players.length == 0) {
|
||||
// party game
|
||||
return _ezObj.occupants.size();
|
||||
|
||||
} else {
|
||||
return _ezObj.getPlayerCount();
|
||||
}
|
||||
}
|
||||
|
||||
// OLD
|
||||
public function getPlayerNames_v1 () :Array
|
||||
{
|
||||
var names :Array = new Array();
|
||||
if (_ezObj.players.length == 0) {
|
||||
// party game, count all occupants
|
||||
var itr :Iterator = _ezObj.occupantInfo.iterator();
|
||||
while (itr.hasNext()) {
|
||||
var occInfo :OccupantInfo = (itr.next() as OccupantInfo);
|
||||
names.push(occInfo.username.toString());
|
||||
}
|
||||
|
||||
} else {
|
||||
for each (var name :Name in _ezObj.players) {
|
||||
names.push((name == null) ? null : name.toString());
|
||||
}
|
||||
}
|
||||
return names;
|
||||
}
|
||||
|
||||
// OLD
|
||||
public function getMyIndex_v1 () :int
|
||||
{
|
||||
if (_ezObj.players.length == 0) {
|
||||
// party game
|
||||
// TODO: this shouldn't be based off of the String form of the name.
|
||||
var array :Array = getPlayerNames_v1();
|
||||
return array.indexOf(getUsername().toString());
|
||||
|
||||
} else {
|
||||
return _ezObj.getPlayerIndex(getUsername());
|
||||
}
|
||||
}
|
||||
|
||||
// OLD
|
||||
public function getTurnHolderIndex_v1 () :int
|
||||
{
|
||||
return _ezObj.getPlayerIndex(_ezObj.turnHolder);
|
||||
}
|
||||
|
||||
// OLD
|
||||
public function getWinnerIndexes_v1 () :Array /* of int */
|
||||
{
|
||||
var arr :Array = new Array();
|
||||
if (_ezObj.winners != null) {
|
||||
for (var ii :int = 0; ii < _ezObj.winners.length; ii++) {
|
||||
if (_ezObj.winners[ii]) {
|
||||
arr.push(ii);
|
||||
}
|
||||
}
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
// OLD
|
||||
public function getUserCookie_v1 (
|
||||
playerIndex :int, callback :Function) :void
|
||||
{
|
||||
getUserCookie_v2(indexToId(playerIndex), callback);
|
||||
}
|
||||
|
||||
// OLD
|
||||
public function endTurn_v1 (nextPlayerIndex :int) :void
|
||||
{
|
||||
endTurn_v2(indexToId(nextPlayerIndex));
|
||||
}
|
||||
|
||||
// OLD
|
||||
public function endGame_v1 (... winnerDexes) :void
|
||||
{
|
||||
var winnerIds :Array = [];
|
||||
for each (var dex :int in winnerDexes) {
|
||||
winnerIds.push(indexToId(dex));
|
||||
}
|
||||
endGame_v2.apply(this, winnerIds);
|
||||
}
|
||||
|
||||
protected var _ctx :CrowdContext;
|
||||
|
||||
protected var _userListener :MessageAdapter =
|
||||
|
||||
@@ -15,8 +15,8 @@ import com.threerings.ezgame.util.EZObjectMarshaller;
|
||||
public class UserCookie
|
||||
implements DSet_Entry
|
||||
{
|
||||
/** The index of the player that has this cookie. */
|
||||
public var playerIndex :int;
|
||||
/** The id of the player that has this cookie. */
|
||||
public var playerId :int;
|
||||
|
||||
/** The decoded cookie value. */
|
||||
public var cookie :Object;
|
||||
@@ -24,13 +24,13 @@ public class UserCookie
|
||||
// from DSet_Entry
|
||||
public function getKey () :Object
|
||||
{
|
||||
return playerIndex;
|
||||
return playerId;
|
||||
}
|
||||
|
||||
// from superinterface Streamable
|
||||
public function readObject (ins :ObjectInputStream) :void
|
||||
{
|
||||
playerIndex = ins.readInt();
|
||||
playerId = ins.readInt();
|
||||
var ba :ByteArray = (ins.readField(ByteArray) as ByteArray);
|
||||
cookie = EZObjectMarshaller.decode(ba);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
The code in here is out of date and out of sync, but will not be updated
|
||||
until needed, as we're focusing on flash development.
|
||||
@@ -27,14 +27,14 @@ public interface EZGameService extends InvocationService
|
||||
* -1 is specified for the nextPlayerIndex.
|
||||
*/
|
||||
public void endTurn (
|
||||
Client client, int nextPlayerIndex, InvocationListener listener);
|
||||
Client client, int nextPlayerId, InvocationListener listener);
|
||||
|
||||
/**
|
||||
* Request to end the game, with the specified player indices assigned
|
||||
* Request to end the game, with the specified player oids assigned
|
||||
* as winners.
|
||||
*/
|
||||
public void endGame (
|
||||
Client client, int[] winners, InvocationListener listener);
|
||||
Client client, int[] winnerOids, InvocationListener listener);
|
||||
|
||||
/**
|
||||
* Request to send a private message to one other player in
|
||||
@@ -45,7 +45,7 @@ public interface EZGameService extends InvocationService
|
||||
* an array property where index is -1.
|
||||
*/
|
||||
public void sendMessage (
|
||||
Client client, String msgName, Object value, int playerIdx,
|
||||
Client client, String msgName, Object value, int playerId,
|
||||
InvocationListener listener);
|
||||
|
||||
/**
|
||||
@@ -99,7 +99,7 @@ public interface EZGameService extends InvocationService
|
||||
*/
|
||||
public void getFromCollection (
|
||||
Client client, String collName, boolean consume, int count,
|
||||
String msgOrPropName, int playerIndex, ConfirmListener listener);
|
||||
String msgOrPropName, int playerId, ConfirmListener listener);
|
||||
|
||||
/**
|
||||
* Start a ticker that will send out timestamp information at
|
||||
@@ -116,7 +116,7 @@ public interface EZGameService extends InvocationService
|
||||
* Request to get the specified user's cookie.
|
||||
*/
|
||||
public void getCookie (
|
||||
Client client, int playerIndex, InvocationListener listener);
|
||||
Client client, int playerId, InvocationListener listener);
|
||||
|
||||
/**
|
||||
* Request to set our cookie.
|
||||
|
||||
@@ -29,23 +29,23 @@ import com.threerings.presents.dobj.DSet;
|
||||
public class UserCookie
|
||||
implements DSet.Entry
|
||||
{
|
||||
/** The index of the player that has this cookie. */
|
||||
public int playerIndex;
|
||||
/** The id of the player that has this cookie. */
|
||||
public int playerId;
|
||||
|
||||
/** The cookie value. */
|
||||
public byte[] cookie;
|
||||
|
||||
/**
|
||||
*/
|
||||
public UserCookie (int playerIndex, byte[] cookie)
|
||||
public UserCookie (int playerId, byte[] cookie)
|
||||
{
|
||||
this.playerIndex = playerIndex;
|
||||
this.playerId = playerId;
|
||||
this.cookie = cookie;
|
||||
}
|
||||
|
||||
// from DSet.Entry
|
||||
public Comparable getKey ()
|
||||
{
|
||||
return playerIndex;
|
||||
return playerId;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import com.samskivert.util.ArrayUtil;
|
||||
import com.samskivert.util.CollectionUtil;
|
||||
import com.samskivert.util.HashIntMap;
|
||||
import com.samskivert.util.Interval;
|
||||
import com.samskivert.util.IntListUtil;
|
||||
import com.samskivert.util.RandomUtil;
|
||||
import com.samskivert.util.ResultListener;
|
||||
|
||||
@@ -74,17 +75,26 @@ public class EZGameManager extends GameManager
|
||||
|
||||
// from EZGameProvider
|
||||
public void endTurn (
|
||||
ClientObject caller, int nextPlayerIndex,
|
||||
ClientObject caller, int nextPlayerId,
|
||||
InvocationService.InvocationListener listener)
|
||||
throws InvocationException
|
||||
{
|
||||
validateStateModification(caller);
|
||||
_turnDelegate.endTurn(nextPlayerIndex);
|
||||
|
||||
Name nextTurnHolder = null;
|
||||
if (nextPlayerId != 0) {
|
||||
BodyObject target = getPlayerByOid(nextPlayerId);
|
||||
if (target != null) {
|
||||
nextTurnHolder = target.getVisibleName();
|
||||
}
|
||||
}
|
||||
|
||||
_turnDelegate.endTurn(nextTurnHolder);
|
||||
}
|
||||
|
||||
// from EZGameProvider
|
||||
public void endGame (
|
||||
ClientObject caller, int[] winners,
|
||||
ClientObject caller, int[] winnerOids,
|
||||
InvocationService.InvocationListener listener)
|
||||
throws InvocationException
|
||||
{
|
||||
@@ -93,24 +103,24 @@ public class EZGameManager extends GameManager
|
||||
}
|
||||
validateStateModification(caller);
|
||||
|
||||
_winnerIndexes = winners;
|
||||
_winnerIds = winnerOids;
|
||||
endGame();
|
||||
}
|
||||
|
||||
// from EZGameProvider
|
||||
public void sendMessage (
|
||||
ClientObject caller, String msg, Object data, int playerIdx,
|
||||
ClientObject caller, String msg, Object data, int playerId,
|
||||
InvocationService.InvocationListener listener)
|
||||
throws InvocationException
|
||||
{
|
||||
validateUser(caller);
|
||||
|
||||
if (playerIdx < 0 || playerIdx >= _gameObj.players.length) {
|
||||
if (playerId == 0) {
|
||||
_gameObj.postMessage(EZGameObject.USER_MESSAGE,
|
||||
new Object[] { msg, data });
|
||||
|
||||
} else {
|
||||
sendPrivateMessage(playerIdx, msg, data);
|
||||
sendPrivateMessage(playerId, msg, data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,7 +196,7 @@ public class EZGameManager extends GameManager
|
||||
// from EZGameProvider
|
||||
public void getFromCollection (
|
||||
ClientObject caller, String collName, boolean consume, int count,
|
||||
String msgOrPropName, int playerIndex,
|
||||
String msgOrPropName, int playerId,
|
||||
InvocationService.ConfirmListener listener)
|
||||
throws InvocationException
|
||||
{
|
||||
@@ -209,11 +219,11 @@ public class EZGameManager extends GameManager
|
||||
}
|
||||
}
|
||||
|
||||
if (playerIndex >= 0 && playerIndex < _gameObj.players.length) {
|
||||
sendPrivateMessage(playerIndex, msgOrPropName, result);
|
||||
if (playerId == 0) {
|
||||
setProperty(msgOrPropName, result, -1);
|
||||
|
||||
} else {
|
||||
setProperty(msgOrPropName, result, -1);
|
||||
sendPrivateMessage(playerId, msgOrPropName, result);
|
||||
}
|
||||
// SUCCESS!
|
||||
listener.requestProcessed();
|
||||
@@ -289,12 +299,12 @@ public class EZGameManager extends GameManager
|
||||
|
||||
// from EZGameProvider
|
||||
public void getCookie (
|
||||
ClientObject caller, final int playerIndex,
|
||||
ClientObject caller, final int playerId,
|
||||
InvocationService.InvocationListener listener)
|
||||
throws InvocationException
|
||||
{
|
||||
GameCookieManager gcm = getCookieManager();
|
||||
if (_gameObj.userCookies.containsKey(playerIndex)) {
|
||||
if (_gameObj.userCookies.containsKey(playerId)) {
|
||||
// already loaded: we do nothing
|
||||
return;
|
||||
}
|
||||
@@ -303,18 +313,18 @@ public class EZGameManager extends GameManager
|
||||
_cookieLookups = new ArrayIntSet();
|
||||
}
|
||||
// we only start looking up the cookie if nobody else already is
|
||||
if (!_cookieLookups.contains(playerIndex)) {
|
||||
gcm.getCookie(getPersistentGameId(), getPlayer(playerIndex),
|
||||
if (!_cookieLookups.contains(playerId)) {
|
||||
gcm.getCookie(getPersistentGameId(), getPlayerByOid(playerId),
|
||||
new ResultListener<byte[]>() {
|
||||
public void requestCompleted (byte[] result) {
|
||||
// Result may be null: that's ok, it means
|
||||
// we've looked up the user's nonexistant cookie.
|
||||
// Only set the cookie if the playerIndex is
|
||||
// still in the lookup set, otherwise they left!
|
||||
if (_cookieLookups.remove(playerIndex) &&
|
||||
if (_cookieLookups.remove(playerId) &&
|
||||
_gameObj.isActive()) {
|
||||
_gameObj.addToUserCookies(
|
||||
new UserCookie(playerIndex, result));
|
||||
new UserCookie(playerId, result));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -326,7 +336,7 @@ public class EZGameManager extends GameManager
|
||||
});
|
||||
|
||||
// indicate that we're looking up a cookie
|
||||
_cookieLookups.add(playerIndex);
|
||||
_cookieLookups.add(playerId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -336,14 +346,11 @@ public class EZGameManager extends GameManager
|
||||
InvocationService.InvocationListener listener)
|
||||
throws InvocationException
|
||||
{
|
||||
int playerIndex = getPresentPlayerIndex(caller.getOid());
|
||||
if (playerIndex == -1) {
|
||||
throw new InvocationException(ACCESS_DENIED);
|
||||
}
|
||||
validateUser(caller);
|
||||
|
||||
GameCookieManager gcm = getCookieManager();
|
||||
UserCookie cookie = new UserCookie(playerIndex, value);
|
||||
if (_gameObj.userCookies.containsKey(playerIndex)) {
|
||||
UserCookie cookie = new UserCookie(caller.getOid(), value);
|
||||
if (_gameObj.userCookies.containsKey(cookie.getKey())) {
|
||||
_gameObj.updateUserCookies(cookie);
|
||||
} else {
|
||||
_gameObj.addToUserCookies(cookie);
|
||||
@@ -372,14 +379,14 @@ public class EZGameManager extends GameManager
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to send a private message to the specified player
|
||||
* index (must already be verified).
|
||||
* Helper method to send a private message to the specified player oid
|
||||
* (must already be verified).
|
||||
*/
|
||||
protected void sendPrivateMessage (
|
||||
int playerIdx, String msg, Object data)
|
||||
int playerId, String msg, Object data)
|
||||
throws InvocationException
|
||||
{
|
||||
BodyObject target = getPlayer(playerIdx);
|
||||
BodyObject target = getPlayerByOid(playerId);
|
||||
if (target == null) {
|
||||
// TODO: this code has no corresponding translation
|
||||
throw new InvocationException("m.player_not_around");
|
||||
@@ -446,6 +453,33 @@ public class EZGameManager extends GameManager
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the specified player body by Oid.
|
||||
*/
|
||||
protected BodyObject getPlayerByOid (int oid)
|
||||
{
|
||||
// verify that they're in the room
|
||||
if (!_gameObj.occupants.contains(oid)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// verify that they're a player
|
||||
switch (getGameType()) {
|
||||
case GameConfig.PARTY:
|
||||
// all occupants are players in a party game
|
||||
break;
|
||||
|
||||
default:
|
||||
if (!IntListUtil.contains(_playerOids, oid)) {
|
||||
return null; // not a player!
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// return the body
|
||||
return (BodyObject) CrowdServer.omgr.getObject(oid);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PlaceObject createPlaceObject ()
|
||||
{
|
||||
@@ -503,13 +537,14 @@ public class EZGameManager extends GameManager
|
||||
@Override
|
||||
protected void assignWinners (boolean[] winners)
|
||||
{
|
||||
if (_winnerIndexes != null) {
|
||||
for (int index : _winnerIndexes) {
|
||||
if (_winnerIds != null) {
|
||||
for (int oid : _winnerIds) {
|
||||
int index = IntListUtil.indexOf(_playerOids, oid);
|
||||
if (index >= 0 && index < winners.length) {
|
||||
winners[index] = true;
|
||||
}
|
||||
}
|
||||
_winnerIndexes = null;
|
||||
_winnerIds = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -595,8 +630,8 @@ public class EZGameManager extends GameManager
|
||||
// /** User tokens, lazy-initialized. */
|
||||
// protected HashIntMap<HashSet<String>> _tokens;
|
||||
|
||||
/** The array of winners, after the user has filled it in. */
|
||||
protected int[] _winnerIndexes;
|
||||
/** The array of winner oids, after the user has filled it in. */
|
||||
protected int[] _winnerIds;
|
||||
|
||||
/** The minimum delay a ticker can have. */
|
||||
protected static final int MIN_TICKER_DELAY = 50;
|
||||
|
||||
@@ -3,6 +3,10 @@
|
||||
|
||||
package com.threerings.ezgame.server;
|
||||
|
||||
import com.samskivert.util.ListUtil;
|
||||
|
||||
import com.threerings.util.Name;
|
||||
|
||||
import com.threerings.parlor.turn.server.TurnGameManagerDelegate;
|
||||
|
||||
/**
|
||||
@@ -16,11 +20,11 @@ public class EZGameTurnDelegate extends TurnGameManagerDelegate
|
||||
}
|
||||
|
||||
/**
|
||||
* A form of endTurn where you can specify the next turn holder index.
|
||||
* A form of endTurn where you can specify the next turn holder oid.
|
||||
*/
|
||||
public void endTurn (int playerIndex)
|
||||
public void endTurn (Name nextPlayer)
|
||||
{
|
||||
_nextPlayerIndex = playerIndex;
|
||||
_nextPlayer = nextPlayer;
|
||||
endTurn();
|
||||
}
|
||||
|
||||
@@ -28,19 +32,22 @@ public class EZGameTurnDelegate extends TurnGameManagerDelegate
|
||||
protected void setNextTurnHolder ()
|
||||
{
|
||||
// if the user-supplied value seems to make sense, use it!
|
||||
if ((_nextPlayerIndex >= 0) &&
|
||||
(_nextPlayerIndex < _turnGame.getPlayers().length)) {
|
||||
_turnIdx = _nextPlayerIndex;
|
||||
if (_nextPlayer != null) {
|
||||
// copy the value, clear out _nextPlayer.
|
||||
Name nextPlayer = _nextPlayer;
|
||||
_nextPlayer = null;
|
||||
|
||||
int index = ListUtil.indexOf(_turnGame.getPlayers(), _nextPlayer);
|
||||
if (index != -1) {
|
||||
_turnIdx = index;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
// otherwise, do the default behavior
|
||||
super.setNextTurnHolder();
|
||||
}
|
||||
|
||||
// always clear out the override
|
||||
_nextPlayerIndex = -1;
|
||||
}
|
||||
|
||||
/** An override next turn holder, or -1. */
|
||||
protected int _nextPlayerIndex = -1;
|
||||
/** An override next turn holder, or null. */
|
||||
protected Name _nextPlayer;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user