Remove trailing whitespace throughout, and then widen/vararg/foreachize some

card game stuff that we were looking at.


git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@804 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
Dave Hoover
2009-03-17 17:46:50 +00:00
parent d05664f649
commit 20657dbaff
31 changed files with 271 additions and 301 deletions
@@ -34,8 +34,7 @@ import com.threerings.parlor.turn.client.TurnGameController;
import static com.threerings.parlor.card.Log.log; import static com.threerings.parlor.card.Log.log;
/** /**
* A controller class for card games. Handles common functions like * A controller class for card games. Handles common functions like accepting dealt hands.
* accepting dealt hands.
*/ */
public abstract class CardGameController extends GameController public abstract class CardGameController extends GameController
implements TurnGameController, CardCodes, CardGameReceiver implements TurnGameController, CardCodes, CardGameReceiver
@@ -50,8 +49,7 @@ public abstract class CardGameController extends GameController
Thread.dumpStack(); Thread.dumpStack();
} }
_ctx.getClient().getInvocationDirector().registerReceiver( _ctx.getClient().getInvocationDirector().registerReceiver(new CardGameDecoder(this));
new CardGameDecoder(this));
super.willEnterPlace(plobj); super.willEnterPlace(plobj);
} }
@@ -61,8 +59,7 @@ public abstract class CardGameController extends GameController
{ {
super.didLeavePlace(plobj); super.didLeavePlace(plobj);
_ctx.getClient().getInvocationDirector().unregisterReceiver( _ctx.getClient().getInvocationDirector().unregisterReceiver(CardGameDecoder.RECEIVER_CODE);
CardGameDecoder.RECEIVER_CODE);
} }
// Documentation inherited. // Documentation inherited.
@@ -80,8 +77,8 @@ public abstract class CardGameController extends GameController
} }
/** /**
* Called when the server deals the client a new hand of cards. Default * Called when the server deals the client a new hand of cards. Default implementation does
* implementation does nothing. * nothing.
* *
* @param hand the hand dealt to the user * @param hand the hand dealt to the user
*/ */
@@ -89,8 +86,8 @@ public abstract class CardGameController extends GameController
{} {}
/** /**
* Dispatched to the client when it has received a set of cards * Dispatched to the client when it has received a set of cards from another player. Default
* from another player. Default implementation does nothing. * implementation does nothing.
* *
* @param plidx the index of the player providing the cards * @param plidx the index of the player providing the cards
* @param cards the cards received * @param cards the cards received
@@ -99,9 +96,8 @@ public abstract class CardGameController extends GameController
{} {}
/** /**
* Dispatched to the client when the server has forced it to send * Dispatched to the client when the server has forced it to send a set of cards to another
* a set of cards to another player. Default implementation does * player. Default implementation does nothing.
* nothing.
* *
* @param plidx the index of the player to which the cards were sent * @param plidx the index of the player to which the cards were sent
* @param cards the cards sent * @param cards the cards sent
@@ -110,8 +106,8 @@ public abstract class CardGameController extends GameController
{} {}
/** /**
* Dispatched to the client when a set of cards is transferred between * Dispatched to the client when a set of cards is transferred between two other players in
* two other players in the game. Default implementation does nothing. * the game. Default implementation does nothing.
* *
* @param fromidx the index of the player sending the cards * @param fromidx the index of the player sending the cards
* @param toidx the index of the player receiving the cards * @param toidx the index of the player receiving the cards
@@ -39,7 +39,7 @@ public interface CardGameReceiver extends InvocationReceiver
* @param hand the received hand * @param hand the received hand
*/ */
public void receivedHand (int oid, Hand hand); public void receivedHand (int oid, Hand hand);
/** /**
* Dispatched to the client when it has received a set of cards * Dispatched to the client when it has received a set of cards
* from another player. * from another player.
@@ -48,7 +48,7 @@ public interface CardGameReceiver extends InvocationReceiver
* @param cards the cards received * @param cards the cards received
*/ */
public void receivedCardsFromPlayer (int plidx, Card[] cards); public void receivedCardsFromPlayer (int plidx, Card[] cards);
/** /**
* Dispatched to the client when the server has forced it to send * Dispatched to the client when the server has forced it to send
* a set of cards to another player. * a set of cards to another player.
@@ -57,7 +57,7 @@ public interface CardGameReceiver extends InvocationReceiver
* @param cards the cards sent * @param cards the cards sent
*/ */
public void sentCardsToPlayer (int plidx, Card[] cards); public void sentCardsToPlayer (int plidx, Card[] cards);
/** /**
* Dispatched to the client when a set of cards is transferred between * Dispatched to the client when a set of cards is transferred between
* two other players in the game. * two other players in the game.
@@ -35,7 +35,7 @@ public interface CardSpriteObserver
* @param me the mouse event associated with the drag * @param me the mouse event associated with the drag
*/ */
public void cardSpriteClicked (CardSprite sprite, MouseEvent me); public void cardSpriteClicked (CardSprite sprite, MouseEvent me);
/** /**
* Notifies the observer that the user moved the mouse pointer onto * Notifies the observer that the user moved the mouse pointer onto
* a card sprite. * a card sprite.
@@ -44,7 +44,7 @@ public interface CardSpriteObserver
* @param me the mouse event associated with the entrance * @param me the mouse event associated with the entrance
*/ */
public void cardSpriteEntered (CardSprite sprite, MouseEvent me); public void cardSpriteEntered (CardSprite sprite, MouseEvent me);
/** /**
* Notifies the observer that the user moved the mouse pointer off of * Notifies the observer that the user moved the mouse pointer off of
* a card sprite. * a card sprite.
@@ -53,7 +53,7 @@ public interface CardSpriteObserver
* @param me the mouse event associated with the exit * @param me the mouse event associated with the exit
*/ */
public void cardSpriteExited (CardSprite sprite, MouseEvent me); public void cardSpriteExited (CardSprite sprite, MouseEvent me);
/** /**
* Notifies the observer that the user dragged a card sprite to a new * Notifies the observer that the user dragged a card sprite to a new
* location. * location.
@@ -35,7 +35,7 @@ public class Card implements DSet.Entry, Comparable<Card>, CardCodes
*/ */
public Card () public Card ()
{} {}
/** /**
* Creates a new card. * Creates a new card.
* *
@@ -46,10 +46,10 @@ public class Card implements DSet.Entry, Comparable<Card>, CardCodes
{ {
_value = (byte)((suit << 5) | number); _value = (byte)((suit << 5) | number);
} }
/** /**
* Returns the value of the card, either from 2 to 11 or * Returns the value of the card, either from 2 to 11 or KING, QUEEN, JACK, ACE, RED_JOKER, or
* KING, QUEEN, JACK, ACE, RED_JOKER, or BLACK_JOKER. * BLACK_JOKER.
* *
* @return the value of the card * @return the value of the card
*/ */
@@ -57,10 +57,10 @@ public class Card implements DSet.Entry, Comparable<Card>, CardCodes
{ {
return (_value & 0x1F); return (_value & 0x1F);
} }
/** /**
* Returns the suit of the card: SPADES, HEARTS, DIAMONDS, or * Returns the suit of the card: SPADES, HEARTS, DIAMONDS, or CLUBS. If the card is the joker,
* CLUBS. If the card is the joker, the suit is undefined. * the suit is undefined.
* *
* @return the suit of the card * @return the suit of the card
*/ */
@@ -68,7 +68,7 @@ public class Card implements DSet.Entry, Comparable<Card>, CardCodes
{ {
return (_value >> 5); return (_value >> 5);
} }
/** /**
* Checks whether the card is a number card (2 to 10). * Checks whether the card is a number card (2 to 10).
* *
@@ -77,10 +77,10 @@ public class Card implements DSet.Entry, Comparable<Card>, CardCodes
public boolean isNumber () public boolean isNumber ()
{ {
int number = getNumber(); int number = getNumber();
return number >= 2 && number <= 10; return number >= 2 && number <= 10;
} }
/** /**
* Checks whether the card is a face card (KING, QUEEN, or JACK). * Checks whether the card is a face card (KING, QUEEN, or JACK).
* *
@@ -89,10 +89,10 @@ public class Card implements DSet.Entry, Comparable<Card>, CardCodes
public boolean isFace () public boolean isFace ()
{ {
int number = getNumber(); int number = getNumber();
return number == KING || number == QUEEN || number == JACK; return number == KING || number == QUEEN || number == JACK;
} }
/** /**
* Checks whether the card is an ace. * Checks whether the card is an ace.
* *
@@ -102,7 +102,7 @@ public class Card implements DSet.Entry, Comparable<Card>, CardCodes
{ {
return getNumber() == ACE; return getNumber() == ACE;
} }
/** /**
* Checks whether the card is a joker. * Checks whether the card is a joker.
* *
@@ -111,41 +111,41 @@ public class Card implements DSet.Entry, Comparable<Card>, CardCodes
public boolean isJoker () public boolean isJoker ()
{ {
int number = getNumber(); int number = getNumber();
return number == RED_JOKER || number == BLACK_JOKER; return number == RED_JOKER || number == BLACK_JOKER;
} }
/** /**
* Checks whether or not this card is valid. The no-arg public * Checks whether or not this card is valid. The no-arg public constructor for deserialization
* constructor for deserialization creates an invalid card. * creates an invalid card.
* *
* @return true if this card is valid, false if not * @return true if this card is valid, false if not
*/ */
public boolean isValid () public boolean isValid ()
{ {
int number = getNumber(), suit = getSuit(); int number = getNumber(), suit = getSuit();
return number == RED_JOKER || number == BLACK_JOKER || return number == RED_JOKER || number == BLACK_JOKER ||
(number >= 2 && number <= ACE && (number >= 2 && number <= ACE &&
suit >= SPADES && suit <= DIAMONDS); suit >= SPADES && suit <= DIAMONDS);
} }
// Documentation inherited. // Documentation inherited.
public Comparable<?> getKey () public Comparable<?> getKey ()
{ {
if (_key == null) { if (_key == null) {
_key = Byte.valueOf(_value); _key = Byte.valueOf(_value);
} }
return _key; return _key;
} }
@Override @Override
public int hashCode () public int hashCode ()
{ {
return _value; return _value;
} }
@Override @Override
public boolean equals (Object other) public boolean equals (Object other)
{ {
@@ -156,21 +156,20 @@ public class Card implements DSet.Entry, Comparable<Card>, CardCodes
return false; return false;
} }
} }
/** /**
* Compares this card to another. The card order is the same as the * Compares this card to another. The card order is the same as the initial deck ordering: two
* initial deck ordering: two through ten, jack, queen, king, ace for * through ten, jack, queen, king, ace for spades, hearts, clubs, and diamonds, then the red
* spades, hearts, clubs, and diamonds, then the red joker and the * joker and the black joker.
* black joker.
* *
* @param other the other card to compare this to * @param other the other card to compare this to
* @return -1, 0, or +1, depending on whether this card is less than, * @return -1, 0, or +1, depending on whether this card is less than, equal to, or greater
* equal to, or greater than the other card * than the other card
*/ */
public int compareTo (Card other) public int compareTo (Card other)
{ {
int otherValue = other._value; int otherValue = other._value;
if (_value > otherValue) { if (_value > otherValue) {
return +1; return +1;
} else if(_value < otherValue) { } else if(_value < otherValue) {
@@ -179,12 +178,12 @@ public class Card implements DSet.Entry, Comparable<Card>, CardCodes
return 0; return 0;
} }
} }
@Override @Override
public String toString () public String toString ()
{ {
int number = getNumber(); int number = getNumber();
if (number == RED_JOKER) { if (number == RED_JOKER) {
return "RJ"; return "RJ";
} }
@@ -193,7 +192,7 @@ public class Card implements DSet.Entry, Comparable<Card>, CardCodes
} }
else { else {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
if (number >= 2 && number <= 9) { if (number >= 2 && number <= 9) {
sb.append(Integer.toString(number)); sb.append(Integer.toString(number));
} }
@@ -207,7 +206,7 @@ public class Card implements DSet.Entry, Comparable<Card>, CardCodes
default: sb.append('?'); break; default: sb.append('?'); break;
} }
} }
switch (getSuit()) { switch (getSuit()) {
case SPADES: sb.append('s'); break; case SPADES: sb.append('s'); break;
case HEARTS: sb.append('h'); break; case HEARTS: sb.append('h'); break;
@@ -215,14 +214,14 @@ public class Card implements DSet.Entry, Comparable<Card>, CardCodes
case DIAMONDS: sb.append('d'); break; case DIAMONDS: sb.append('d'); break;
default: sb.append('?'); break; default: sb.append('?'); break;
} }
return sb.toString(); return sb.toString();
} }
} }
/** The number of the card. */ /** The number of the card. */
protected byte _value; protected byte _value;
/** The comparison key. */ /** The comparison key. */
@ActionScript(omit=true) @ActionScript(omit=true)
protected transient Byte _key; protected transient Byte _key;
@@ -30,31 +30,31 @@ public interface CardCodes extends InvocationCodes
{ {
/** The suit of spades. */ /** The suit of spades. */
public static final int SPADES = 0; public static final int SPADES = 0;
/** The suit of hearts. */ /** The suit of hearts. */
public static final int HEARTS = 1; public static final int HEARTS = 1;
/** The suit of clubs. */ /** The suit of clubs. */
public static final int CLUBS = 2; public static final int CLUBS = 2;
/** The suit of diamonds. */ /** The suit of diamonds. */
public static final int DIAMONDS = 3; public static final int DIAMONDS = 3;
/** The number of the jack. */ /** The number of the jack. */
public static final int JACK = 11; public static final int JACK = 11;
/** The number of the queen. */ /** The number of the queen. */
public static final int QUEEN = 12; public static final int QUEEN = 12;
/** The number of the king. */ /** The number of the king. */
public static final int KING = 13; public static final int KING = 13;
/** The number of the ace. */ /** The number of the ace. */
public static final int ACE = 14; public static final int ACE = 14;
/** The number of the red joker. */ /** The number of the red joker. */
public static final int RED_JOKER = 15; public static final int RED_JOKER = 15;
/** The number of the black joker. */ /** The number of the black joker. */
public static final int BLACK_JOKER = 16; public static final int BLACK_JOKER = 16;
} }
@@ -30,16 +30,16 @@ public class PlayerCard implements Streamable
{ {
/** The index of the player. */ /** The index of the player. */
public int pidx; public int pidx;
/** The card that the player played. */ /** The card that the player played. */
public Card card; public Card card;
/** /**
* No-argument constructor for deserialization. * No-argument constructor for deserialization.
*/ */
public PlayerCard () public PlayerCard ()
{} {}
/** /**
* Creates a new player card. * Creates a new player card.
* *
@@ -36,8 +36,8 @@ import com.threerings.parlor.game.server.GameManager;
import com.threerings.parlor.turn.server.TurnGameManager; import com.threerings.parlor.turn.server.TurnGameManager;
/** /**
* A manager class for card games. Handles common functions like dealing * A manager class for card games. Handles common functions like dealing hands of cards to all
* hands of cards to all players. * players.
*/ */
public class CardGameManager extends GameManager public class CardGameManager extends GameManager
implements TurnGameManager, CardCodes implements TurnGameManager, CardCodes
@@ -48,15 +48,15 @@ public class CardGameManager extends GameManager
super.didStartup(); super.didStartup();
_cardgameobj = (CardGameObject)_gameobj; _cardgameobj = (CardGameObject)_gameobj;
} }
// Documentation inherited. // Documentation inherited.
public void turnWillStart () public void turnWillStart ()
{} {}
// Documentation inherited. // Documentation inherited.
public void turnDidStart () public void turnDidStart ()
{} {}
// Documentation inherited. // Documentation inherited.
public void turnDidEnd () public void turnDidEnd ()
{} {}
@@ -72,9 +72,8 @@ public class CardGameManager extends GameManager
} }
/** /**
* This should be called to start a rematched game. It just starts the * This should be called to start a rematched game. It just starts the current game anew, but
* current game anew, but provides a mechanism for derived classes to * provides a mechanism for derived classes to do special things when there is a rematch.
* do special things when there is a rematch.
*/ */
public void rematchGame () public void rematchGame ()
{ {
@@ -86,10 +85,9 @@ public class CardGameManager extends GameManager
} }
/** /**
* Derived classes can override this method and take any action needed * Derived classes can override this method and take any action needed prior to a game
* prior to a game rematch. If the rematch needs to be vetoed for any * rematch. If the rematch needs to be vetoed for any reason, they can return false from this
* reason, they can return false from this method and the rematch will * method and the rematch will be aborted.
* be aborted.
*/ */
protected boolean gameWillRematch () protected boolean gameWillRematch ()
{ {
@@ -97,14 +95,13 @@ public class CardGameManager extends GameManager
} }
/** /**
* Deals a hand of cards to the player at the specified index from * Deals a hand of cards to the player at the specified index from the given Deck.
* the given Deck.
* *
* @param deck the deck from which to deal * @param deck the deck from which to deal
* @param size the size of the hand to deal * @param size the size of the hand to deal
* @param playerIndex the index of the target player * @param playerIndex the index of the target player
* @return the hand dealt to the player, or null if the deal * @return the hand dealt to the player, or null if the deal was canceled because the deck did
* was canceled because the deck did not contain enough cards * not contain enough cards
*/ */
public Hand dealHand (Deck deck, int size, int playerIndex) public Hand dealHand (Deck deck, int size, int playerIndex)
{ {
@@ -122,16 +119,14 @@ public class CardGameManager extends GameManager
return hand; return hand;
} }
} }
/** /**
* Deals a hand of cards to each player from the specified * Deals a hand of cards to each player from the specified Deck.
* Deck.
* *
* @param deck the deck from which to deal * @param deck the deck from which to deal
* @param size the size of the hands to deal * @param size the size of the hands to deal
* @return the array of hands dealt to each player, or null if * @return the array of hands dealt to each player, or null if the deal was canceled because
* the deal was canceled because the deck did not contain enough * the deck did not contain enough cards
* cards
*/ */
public Hand[] dealHands (Deck deck, int size) public Hand[] dealHands (Deck deck, int size)
{ {
@@ -140,20 +135,18 @@ public class CardGameManager extends GameManager
} else { } else {
Hand[] hands = new Hand[_playerCount]; Hand[] hands = new Hand[_playerCount];
for (int i=0;i<_playerCount;i++) { for (int i=0;i<_playerCount;i++) {
hands[i] = dealHand(deck, size, i); hands[i] = dealHand(deck, size, i);
} }
return hands; return hands;
} }
} }
/** /**
* Gets the player index of the specified client object, or -1 * Gets the player index of the specified client object, or -1 if the client object does not
* if the client object does not represent a player. If the game has ended, * represent a player. If the game has ended, looks through the players of the now-ended game.
* looks through the players of the now-ended game.
*
*/ */
public int getPlayerIndex (ClientObject client) public int getPlayerIndex (ClientObject client)
{ {
@@ -167,21 +160,21 @@ public class CardGameManager extends GameManager
} }
return -1; return -1;
} }
/** /**
* Returns the client object corresponding to the specified player index, * Returns the client object corresponding to the specified player index, or null if the
* or null if the position is not occupied by a player. * position is not occupied by a player.
*/ */
public ClientObject getClientObject (int pidx) public ClientObject getClientObject (int pidx)
{ {
if (_playerOids[pidx] != 0) { if (_playerOids[pidx] != 0) {
return (ClientObject)_omgr.getObject(_playerOids[pidx]); return (ClientObject)_omgr.getObject(_playerOids[pidx]);
} else { } else {
return null; return null;
} }
} }
/** /**
* Sends a set of cards from one player to another. * Sends a set of cards from one player to another.
* *
@@ -197,51 +190,47 @@ public class CardGameManager extends GameManager
if (fromClient != null) { if (fromClient != null) {
CardGameSender.sentCardsToPlayer(fromClient, toPlayerIdx, cards); CardGameSender.sentCardsToPlayer(fromClient, toPlayerIdx, cards);
} }
// Notify the receiver with the cards // Notify the receiver with the cards
ClientObject toClient = getClientObject(toPlayerIdx); ClientObject toClient = getClientObject(toPlayerIdx);
if (toClient != null) { if (toClient != null) {
CardGameSender.sendCardsFromPlayer(toClient, fromPlayerIdx, CardGameSender.sendCardsFromPlayer(toClient, fromPlayerIdx,
cards); cards);
} }
// and everybody else in the room other than the sender and the // and everybody else in the room other than the sender and the
// receiver with the number of cards sent // receiver with the number of cards sent
notifyCardsTransferred(fromPlayerIdx, toPlayerIdx, cards.length); notifyCardsTransferred(fromPlayerIdx, toPlayerIdx, cards.length);
} }
/** /**
* Sends sets of cards between players simultaneously. Each player is * Sends sets of cards between players simultaneously. Each player is guaranteed to receive
* guaranteed to receive the notification of cards received after the * the notification of cards received after the notification of cards sent. The length of the
* notification of cards sent. The length of the arrays passed must * arrays passed must be equal to the player count.
* be equal to the player count.
* *
* @param toPlayerIndices for each player, the index of the player to * @param toPlayerIndices for each player, the index of the player to transfer cards to
* transfer cards to
* @param cards for each player, the cards to transfer * @param cards for each player, the cards to transfer
*/ */
public void transferCardsBetweenPlayers (int[] toPlayerIndices, public void transferCardsBetweenPlayers (int[] toPlayerIndices, Card[][] cards)
Card[][] cards)
{ {
// Send all removal notices // Send all removal notices
for (int i = 0; i < _playerCount; i++) { for (int ii = 0; ii < _playerCount; ii++) {
ClientObject fromClient = getClientObject(i); ClientObject fromClient = getClientObject(ii);
if (fromClient != null) { if (fromClient != null) {
CardGameSender.sentCardsToPlayer(fromClient, CardGameSender.sentCardsToPlayer(fromClient, toPlayerIndices[ii], cards[ii]);
toPlayerIndices[i], cards[i]);
} }
} }
// Send all addition notices and notify everyone else // Send all addition notices and notify everyone else
for (int i = 0; i < _playerCount; i++) { for (int ii = 0; ii < _playerCount; ii++) {
ClientObject toClient = getClientObject(toPlayerIndices[i]); ClientObject toClient = getClientObject(toPlayerIndices[ii]);
if (toClient != null) { if (toClient != null) {
CardGameSender.sendCardsFromPlayer(toClient, i, cards[i]); CardGameSender.sendCardsFromPlayer(toClient, ii, cards[ii]);
} }
notifyCardsTransferred(i, toPlayerIndices[i], cards[i].length); notifyCardsTransferred(ii, toPlayerIndices[ii], cards[ii].length);
} }
} }
/** /**
* Notifies everyone in the room (other than the sender and the receiver) that a set of cards * Notifies everyone in the room (other than the sender and the receiver) that a set of cards
* have been transferred. * have been transferred.
@@ -250,8 +239,8 @@ public class CardGameManager extends GameManager
* @param toPlayerIdx the index of the player receiving the cards * @param toPlayerIdx the index of the player receiving the cards
* @param cards the number of cards sent * @param cards the number of cards sent
*/ */
protected void notifyCardsTransferred (final int fromPlayerIdx, protected void notifyCardsTransferred (
final int toPlayerIdx, final int cards) final int fromPlayerIdx, final int toPlayerIdx, final int cards)
{ {
final int senderOid = _playerOids[fromPlayerIdx], final int senderOid = _playerOids[fromPlayerIdx],
receiverOid = _playerOids[toPlayerIdx]; receiverOid = _playerOids[toPlayerIdx];
@@ -269,7 +258,7 @@ public class CardGameManager extends GameManager
}; };
applyToOccupants(op); applyToOccupants(op);
} }
/** The card game object. */ /** The card game object. */
protected CardGameObject _cardgameobj; protected CardGameObject _cardgameobj;
@@ -25,8 +25,7 @@ import com.threerings.parlor.card.client.CardGameController;
import com.threerings.parlor.turn.client.TurnGameControllerDelegate; import com.threerings.parlor.turn.client.TurnGameControllerDelegate;
/** /**
* A card game controller delegate for trick-based card games, such as * A card game controller delegate for trick-based card games, such as Spades and Hearts.
* Spades and Hearts.
*/ */
public class TrickCardGameControllerDelegate public class TrickCardGameControllerDelegate
extends TurnGameControllerDelegate extends TurnGameControllerDelegate
@@ -36,13 +35,12 @@ public class TrickCardGameControllerDelegate
* *
* @param controller the game controller * @param controller the game controller
*/ */
public TrickCardGameControllerDelegate (CardGameController public TrickCardGameControllerDelegate (CardGameController controller)
controller)
{ {
super(controller); super(controller);
_cgctrl = controller; _cgctrl = controller;
} }
/** The card game controller. */ /** The card game controller. */
protected CardGameController _cgctrl; protected CardGameController _cgctrl;
} }
@@ -39,7 +39,7 @@ public interface TrickCardGameService extends InvocationService
* @param cards the cards to send * @param cards the cards to send
*/ */
public void sendCardsToPlayer (Client client, int toidx, Card[] cards); public void sendCardsToPlayer (Client client, int toidx, Card[] cards);
/** /**
* Plays a card in the trick. * Plays a card in the trick.
* *
@@ -49,7 +49,7 @@ public interface TrickCardGameService extends InvocationService
* that the request is for the current trick * that the request is for the current trick
*/ */
public void playCard (Client client, Card card, int handSize); public void playCard (Client client, Card card, int handSize);
/** /**
* A request for a rematch. * A request for a rematch.
* *
@@ -30,13 +30,13 @@ public interface TrickCardCodes extends CardCodes
{ {
/** For four-player games, the bottom (own) player. */ /** For four-player games, the bottom (own) player. */
public static final int BOTTOM = 0; public static final int BOTTOM = 0;
/** For four-player games, the player on the left. */ /** For four-player games, the player on the left. */
public static final int LEFT = 1; public static final int LEFT = 1;
/** For four-player games, the top (opposite) player. */ /** For four-player games, the top (opposite) player. */
public static final int TOP = 2; public static final int TOP = 2;
/** For four-player games, the player on the right. */ /** For four-player games, the player on the right. */
public static final int RIGHT = 3; public static final int RIGHT = 3;
} }
@@ -33,25 +33,25 @@ public interface TrickCardGameObject extends TurnGameObject
{ {
/** The state that indicates the game is currently between hands. */ /** The state that indicates the game is currently between hands. */
public static final int BETWEEN_HANDS = 0; public static final int BETWEEN_HANDS = 0;
/** The state that indicates the game is currently playing a hand. */ /** The state that indicates the game is currently playing a hand. */
public static final int PLAYING_HAND = 1; public static final int PLAYING_HAND = 1;
/** The state that indicates the game is currently playing a trick. */ /** The state that indicates the game is currently playing a trick. */
public static final int PLAYING_TRICK = 2; public static final int PLAYING_TRICK = 2;
/** The number of states defined for the base trick card game object. */ /** The number of states defined for the base trick card game object. */
public static final int TRICK_STATE_COUNT = 3; public static final int TRICK_STATE_COUNT = 3;
/** Indicates that the player has not requested or accepted a rematch. */ /** Indicates that the player has not requested or accepted a rematch. */
public static final int NO_REQUEST = 0; public static final int NO_REQUEST = 0;
/** Indicates that the player has requested a rematch. */ /** Indicates that the player has requested a rematch. */
public static final int REQUESTS_REMATCH = 1; public static final int REQUESTS_REMATCH = 1;
/** Indicates that the player has accepted the rematch request. */ /** Indicates that the player has accepted the rematch request. */
public static final int ACCEPTS_REMATCH = 2; public static final int ACCEPTS_REMATCH = 2;
/** /**
* Returns a reference to the trick card game service used to make * Returns a reference to the trick card game service used to make
* requests to the server. * requests to the server.
@@ -59,7 +59,7 @@ public interface TrickCardGameObject extends TurnGameObject
* @return a reference to the trick card game service * @return a reference to the trick card game service
*/ */
public TrickCardGameMarshaller getTrickCardGameService (); public TrickCardGameMarshaller getTrickCardGameService ();
/** /**
* Sets the reference to the trick card game service. * Sets the reference to the trick card game service.
* *
@@ -67,7 +67,7 @@ public interface TrickCardGameObject extends TurnGameObject
*/ */
public void setTrickCardGameService (TrickCardGameMarshaller public void setTrickCardGameService (TrickCardGameMarshaller
trickCardGameService); trickCardGameService);
/** /**
* Returns the name of the field that contains the trick state: between * Returns the name of the field that contains the trick state: between
* hands, playing a hand, or playing a trick. * hands, playing a hand, or playing a trick.
@@ -75,7 +75,7 @@ public interface TrickCardGameObject extends TurnGameObject
* @return the name of the trickState field * @return the name of the trickState field
*/ */
public String getTrickStateFieldName (); public String getTrickStateFieldName ();
/** /**
* Returns the trick state: between hands, playing a hand, or playing a * Returns the trick state: between hands, playing a hand, or playing a
* trick. * trick.
@@ -88,9 +88,9 @@ public interface TrickCardGameObject extends TurnGameObject
* Sets the trick state. * Sets the trick state.
* *
* @param trickState the trick state * @param trickState the trick state
*/ */
public void setTrickState (int trickState); public void setTrickState (int trickState);
/** /**
* Returns an array containing the turn duration scales for each player. * Returns an array containing the turn duration scales for each player.
* Turn duration scales decrease each time players time out. * Turn duration scales decrease each time players time out.
@@ -98,14 +98,14 @@ public interface TrickCardGameObject extends TurnGameObject
* @return the array of turn duration scales * @return the array of turn duration scales
*/ */
public float[] getTurnDurationScales (); public float[] getTurnDurationScales ();
/** /**
* Sets the array of turn duration scales. * Sets the array of turn duration scales.
* *
* @param turnDurationScales the array of turn duration scales * @param turnDurationScales the array of turn duration scales
*/ */
public void setTurnDurationScales (float[] turnDurationScales); public void setTurnDurationScales (float[] turnDurationScales);
/** /**
* Sets an element of the array of turn duration scales. * Sets an element of the array of turn duration scales.
* *
@@ -113,13 +113,13 @@ public interface TrickCardGameObject extends TurnGameObject
* @param index the index of the turn duration scale * @param index the index of the turn duration scale
*/ */
public void setTurnDurationScalesAt (float turnDurationScale, int index); public void setTurnDurationScalesAt (float turnDurationScale, int index);
/** /**
* Returns the duration of the current turn, which may depend on the state * Returns the duration of the current turn, which may depend on the state
* of the game as well as the duration scale of the active player. * of the game as well as the duration scale of the active player.
*/ */
public long getTurnDuration (); public long getTurnDuration ();
/** /**
* Returns the name of the field that contains the history of the trick * Returns the name of the field that contains the history of the trick
* in terms of the cards played by each player. * in terms of the cards played by each player.
@@ -127,7 +127,7 @@ public interface TrickCardGameObject extends TurnGameObject
* @return the name of the cardsPlayed field * @return the name of the cardsPlayed field
*/ */
public String getCardsPlayedFieldName (); public String getCardsPlayedFieldName ();
/** /**
* Returns an array containing the history of the trick in terms of the * Returns an array containing the history of the trick in terms of the
* cards played by each player. * cards played by each player.
@@ -135,7 +135,7 @@ public interface TrickCardGameObject extends TurnGameObject
* @return the cards played so far in the trick * @return the cards played so far in the trick
*/ */
public PlayerCard[] getCardsPlayed (); public PlayerCard[] getCardsPlayed ();
/** /**
* Sets the array of cards played by each player. * Sets the array of cards played by each player.
* *
@@ -150,7 +150,7 @@ public interface TrickCardGameObject extends TurnGameObject
* @return the name of the lastCardsPlayed field * @return the name of the lastCardsPlayed field
*/ */
public String getLastCardsPlayedFieldName (); public String getLastCardsPlayedFieldName ();
/** /**
* Returns an array containing the history of the last trick in terms of * Returns an array containing the history of the last trick in terms of
* the cards played by each player. * the cards played by each player.
@@ -158,35 +158,35 @@ public interface TrickCardGameObject extends TurnGameObject
* @return the cards played in the last trick * @return the cards played in the last trick
*/ */
public PlayerCard[] getLastCardsPlayed (); public PlayerCard[] getLastCardsPlayed ();
/** /**
* Sets the last array of cards played by each player. * Sets the last array of cards played by each player.
* *
* @param lastCardsPlayed the last array of cards played * @param lastCardsPlayed the last array of cards played
*/ */
public void setLastCardsPlayed (PlayerCard[] lastCardsPlayed); public void setLastCardsPlayed (PlayerCard[] lastCardsPlayed);
/** /**
* Returns the name of the field that contains the rematch requests. * Returns the name of the field that contains the rematch requests.
* *
* @return the name of the rematchRequests field * @return the name of the rematchRequests field
*/ */
public String getRematchRequestsFieldName (); public String getRematchRequestsFieldName ();
/** /**
* Returns the array of rematch requests. * Returns the array of rematch requests.
* *
* @return the array of rematch requests * @return the array of rematch requests
*/ */
public int[] getRematchRequests (); public int[] getRematchRequests ();
/** /**
* Sets the array of rematch requests. * Sets the array of rematch requests.
* *
* @param rematchRequests the array of rematch requests * @param rematchRequests the array of rematch requests
*/ */
public void setRematchRequests (int[] rematchRequests); public void setRematchRequests (int[] rematchRequests);
/** /**
* Sets an element of the rematch request array. * Sets an element of the rematch request array.
* *
@@ -194,7 +194,7 @@ public interface TrickCardGameObject extends TurnGameObject
* @param index the index at which to set the value * @param index the index at which to set the value
*/ */
public void setRematchRequestsAt (int rematchRequest, int index); public void setRematchRequestsAt (int rematchRequest, int index);
/** /**
* Checks whether a user can play the specified card at this time. * Checks whether a user can play the specified card at this time.
* *
@@ -202,7 +202,7 @@ public interface TrickCardGameObject extends TurnGameObject
* @param card the card that the user would like to play * @param card the card that the user would like to play
*/ */
public boolean isCardPlayable (Hand hand, Card card); public boolean isCardPlayable (Hand hand, Card card);
/** /**
* Returns the card of the player who took the current trick. * Returns the card of the player who took the current trick.
*/ */
@@ -28,8 +28,6 @@ import java.util.List;
import com.samskivert.util.ArrayUtil; import com.samskivert.util.ArrayUtil;
import com.samskivert.util.Interval; import com.samskivert.util.Interval;
import com.samskivert.util.RandomUtil; import com.samskivert.util.RandomUtil;
import com.samskivert.util.StringUtil;
import com.threerings.util.Name; import com.threerings.util.Name;
import com.threerings.presents.data.ClientObject; import com.threerings.presents.data.ClientObject;
@@ -215,15 +213,15 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate
// make sure they're actually a player // make sure they're actually a player
int fromidx = _cgmgr.getPlayerIndex(client); int fromidx = _cgmgr.getPlayerIndex(client);
if (fromidx == -1) { if (fromidx == -1) {
log.warning("Send request from non-player [username=" + log.warning("Send request from non-player",
((BodyObject)client).who() + ", cards=" + StringUtil.toString(cards) + "]."); "username", ((BodyObject)client).who(), "cards", cards);
return; return;
} }
// make sure they have the cards // make sure they have the cards
if (!_hands[fromidx].containsAll(cards)) { if (!_hands[fromidx].containsAll(cards)) {
log.warning("Tried to send cards not held [username=" + log.warning("Tried to send cards not held",
((BodyObject)client).who() + ", cards=" + StringUtil.toString(cards) + "]."); "username", ((BodyObject)client).who(), "cards", cards);
return; return;
} }
@@ -253,15 +251,13 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate
// make sure their hand contains the specified card // make sure their hand contains the specified card
if (!_hands[pidx].contains(card)) { if (!_hands[pidx].contains(card)) {
log.warning("Tried to play card not held [username=" + username + log.warning("Tried to play card not held", "username", username, "card", card);
", card=" + card + "].");
return; return;
} }
// make sure the card is legal to play // make sure the card is legal to play
if (!_trickCardGame.isCardPlayable(_hands[pidx], card)) { if (!_trickCardGame.isCardPlayable(_hands[pidx], card)) {
log.warning("Tried to play illegal card [username=" + username + log.warning("Tried to play illegal card", "username", username, "card", card);
", card=" + card + "].");
return; return;
} }
@@ -281,14 +277,13 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate
// make sure the requester is one of the players // make sure the requester is one of the players
int pidx = _cgmgr.getPlayerIndex(client); int pidx = _cgmgr.getPlayerIndex(client);
if (pidx == -1) { if (pidx == -1) {
log.warning("Rematch request from non-player [username=" + log.warning("Rematch request from non-player", "username", ((BodyObject)client).who());
((BodyObject)client).who() + "].");
return; return;
} }
// make sure the player hasn't already requested // make sure the player hasn't already requested
if (_trickCardGame.getRematchRequests()[pidx] != TrickCardGameObject.NO_REQUEST) { if (_trickCardGame.getRematchRequests()[pidx] != TrickCardGameObject.NO_REQUEST) {
log.warning("Repeated rematch request [username=" + ((BodyObject)client).who() + "]."); log.warning("Repeated rematch request", "username", ((BodyObject)client).who());
return; return;
} }
@@ -361,8 +356,8 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate
{ {
int[] rematchRequests = _trickCardGame.getRematchRequests(); int[] rematchRequests = _trickCardGame.getRematchRequests();
int count = 0; int count = 0;
for (int i = 0; i < rematchRequests.length; i++) { for (int rematchRequest : rematchRequests) {
if (rematchRequests[i] != TrickCardGameObject.NO_REQUEST) { if (rematchRequest != TrickCardGameObject.NO_REQUEST) {
count++; count++;
} }
} }
@@ -562,8 +557,8 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate
*/ */
protected boolean anyHandsEmpty () protected boolean anyHandsEmpty ()
{ {
for (int i = 0; i < _hands.length; i++) { for (Hand _hand : _hands) {
if (_hands[i].isEmpty()) { if (_hand.isEmpty()) {
return true; return true;
} }
} }
@@ -33,8 +33,7 @@ public class TrickCardGameUtil
implements TrickCardCodes implements TrickCardCodes
{ {
/** /**
* For four-player games with fixed partnerships, this returns the index * For four-player games with fixed partnerships, this returns the index of the player's team.
* of the player's team.
* *
* @param pidx the player index * @param pidx the player index
*/ */
@@ -42,10 +41,9 @@ public class TrickCardGameUtil
{ {
return pidx & 1; return pidx & 1;
} }
/** /**
* For four-player games with fixed partnerships, this returns the index * For four-player games with fixed partnerships, this returns the index of the other team.
* of the other team.
* *
* @param tidx the index of the team * @param tidx the index of the team
*/ */
@@ -53,19 +51,19 @@ public class TrickCardGameUtil
{ {
return tidx ^ 1; return tidx ^ 1;
} }
/** /**
* For four-player games with fixed partnerships, this returns the index * For four-player games with fixed partnerships, this returns the index of the player's
* of the player's partner. * partner.
*/ */
public static int getPartnerIndex (int pidx) public static int getPartnerIndex (int pidx)
{ {
return pidx ^ 2; return pidx ^ 2;
} }
/** /**
* For four-player games with fixed partnerships, this returns the index * For four-player games with fixed partnerships, this returns the index of one of the members
* of one of the members of a team. * of a team.
* *
* @param tidx the index of the team * @param tidx the index of the team
* @param midx the index of the player within the team * @param midx the index of the player within the team
@@ -74,10 +72,10 @@ public class TrickCardGameUtil
{ {
return (midx << 1) | tidx; return (midx << 1) | tidx;
} }
/** /**
* For four-player games, this returns the index of the player after the * For four-player games, this returns the index of the player after the specified player
* specified player going clockwise around the table. * going clockwise around the table.
*/ */
public static int getNextInClockwiseSequence (int pidx) public static int getNextInClockwiseSequence (int pidx)
{ {
@@ -86,10 +84,10 @@ public class TrickCardGameUtil
// 0 // 0
return (pidx + 1) & 3; return (pidx + 1) & 3;
} }
/** /**
* For four-player games with fixed partnerships, this returns the * For four-player games with fixed partnerships, this returns the relative location of one
* relative location of one player from the point of view of another. * player from the point of view of another.
* *
* @param pidx1 the index of the player to whom the location is relative * @param pidx1 the index of the player to whom the location is relative
* @param pidx2 the index of the player whose location is desired * @param pidx2 the index of the player whose location is desired
@@ -99,34 +97,32 @@ public class TrickCardGameUtil
{ {
return (pidx2 - pidx1) & 3; return (pidx2 - pidx1) & 3;
} }
/** /**
* For four-player games, returns the index of the player to the left of * For four-player games, returns the index of the player to the left of the specified player.
* the specified player.
*/ */
public static int getLeftIndex (int pidx) public static int getLeftIndex (int pidx)
{ {
return (pidx + 1) & 3; return (pidx + 1) & 3;
} }
/** /**
* For four-player games, returns the index of the player to the right of * For four-player games, returns the index of the player to the right of the specified
* the specified player. * player.
*/ */
public static int getRightIndex (int pidx) public static int getRightIndex (int pidx)
{ {
return (pidx + 3) & 3; return (pidx + 3) & 3;
} }
/** /**
* For four-player games, returns the index of the player across from the * For four-player games, returns the index of the player across from the specified player.
* specified player.
*/ */
public static int getOppositeIndex (int pidx) public static int getOppositeIndex (int pidx)
{ {
return pidx ^ 2; return pidx ^ 2;
} }
/** /**
* Checks whether the player can follow the suit lead with the hand given. * Checks whether the player can follow the suit lead with the hand given.
*/ */
@@ -134,35 +130,34 @@ public class TrickCardGameUtil
{ {
return hand.getSuitMemberCount(cardsPlayed[0].card.getSuit()) > 0; return hand.getSuitMemberCount(cardsPlayed[0].card.getSuit()) > 0;
} }
/** /**
* Checks whether the specified array contains the given card. * Checks whether the specified array contains the given card.
*/ */
public static boolean containsCard (PlayerCard[] cards, Card card) public static boolean containsCard (PlayerCard[] cards, Card card)
{ {
for (int i = 0; i < cards.length; i++) { for (PlayerCard pc : cards) {
if (cards[i].card.equals(card)) { if (pc.card.equals(card)) {
return true; return true;
} }
} }
return false; return false;
} }
/** /**
* Determines the number of cards that belong to the specified suit within * Determines the number of cards that belong to the specified suit within the array given.
* the array given.
*/ */
public static int countSuitMembers (PlayerCard[] cards, int suit) public static int countSuitMembers (PlayerCard[] cards, int suit)
{ {
int count = 0; int count = 0;
for (int i = 0; i < cards.length; i++) { for (PlayerCard pc : cards) {
if (cards[i].card.getSuit() == suit) { if (pc.card.getSuit() == suit) {
count++; count++;
} }
} }
return count; return count;
} }
/** /**
* Checks whether the proposed card follows the suit lead. * Checks whether the proposed card follows the suit lead.
*/ */
@@ -170,23 +165,21 @@ public class TrickCardGameUtil
{ {
return cardsPlayed[0].card.getSuit() == card.getSuit(); return cardsPlayed[0].card.getSuit() == card.getSuit();
} }
/** /**
* Returns the highest card (according to the standard A,K,...,2 ordering) * Returns the highest card (according to the standard A,K,...,2 ordering) in the suit lead,
* in the suit lead, with an optional trump suit. * with an optional trump suit.
* *
* @param trumpSuit the trump suit, or -1 for none * @param trumpSuit the trump suit, or -1 for none
*/ */
public static PlayerCard getHighestInLeadSuit (PlayerCard[] cardsPlayed, public static PlayerCard getHighestInLeadSuit (PlayerCard[] cardsPlayed, int trumpSuit)
int trumpSuit)
{ {
PlayerCard highest = cardsPlayed[0]; PlayerCard highest = cardsPlayed[0];
for (int i = 1; i < cardsPlayed.length; i++) { for (int i = 1; i < cardsPlayed.length; i++) {
PlayerCard other = cardsPlayed[i]; PlayerCard other = cardsPlayed[i];
if ((other.card.getSuit() == highest.card.getSuit() && if ((other.card.getSuit() == highest.card.getSuit() &&
other.card.compareTo(highest.card) > 0) || other.card.compareTo(highest.card) > 0) ||
(other.card.getSuit() == trumpSuit && (other.card.getSuit() == trumpSuit && highest.card.getSuit() != trumpSuit)) {
highest.card.getSuit() != trumpSuit)) {
highest = other; highest = other;
} }
} }
@@ -81,7 +81,7 @@ public abstract class TableConfigurator
} }
/** /**
* If true, the TableConfigurator is empty, which doesn't mean that * If true, the TableConfigurator is empty, which doesn't mean that
* it will not return a TableConfig object (for it must), but rather * it will not return a TableConfig object (for it must), but rather
* that there are no user-editable options being presented in the * that there are no user-editable options being presented in the
* config interface. * config interface.
@@ -303,7 +303,7 @@ public class TableManager
} else if ( ! _allowBooting) { } else if ( ! _allowBooting) {
throw new InvocationException(INTERNAL_ERROR); throw new InvocationException(INTERNAL_ERROR);
} }
int position = ListUtil.indexOf(table.players, target); int position = ListUtil.indexOf(table.players, target);
if (position < 0) { if (position < 0) {
throw new InvocationException(NOT_AT_TABLE); throw new InvocationException(NOT_AT_TABLE);
@@ -24,7 +24,7 @@ package com.threerings.parlor.tourney.data;
import com.threerings.io.SimpleStreamableObject; import com.threerings.io.SimpleStreamableObject;
/** /**
* Extensible class that specifies the prize for a tourney. * Extensible class that specifies the prize for a tourney.
*/ */
public abstract class Prize extends SimpleStreamableObject public abstract class Prize extends SimpleStreamableObject
{ {
@@ -26,7 +26,7 @@ import com.threerings.io.SimpleStreamableObject;
import com.threerings.util.Name; import com.threerings.util.Name;
/** /**
* Stores tournament configuration data. * Stores tournament configuration data.
*/ */
public class TourneyConfig extends SimpleStreamableObject public class TourneyConfig extends SimpleStreamableObject
{ {
@@ -73,7 +73,7 @@ public abstract class TourniesManager
} }
// from interface TourniesService // from interface TourniesService
public void createTourney (ClientObject caller, TourneyConfig config, public void createTourney (ClientObject caller, TourneyConfig config,
final InvocationService.ResultListener listener) final InvocationService.ResultListener listener)
throws InvocationException throws InvocationException
{ {
@@ -36,7 +36,7 @@ public interface StageSceneService extends InvocationService
*/ */
public void addObject (Client client, ObjectInfo info, public void addObject (Client client, ObjectInfo info,
ConfirmListener listener); ConfirmListener listener);
/** /**
* Requests to remove the supplied objects from the current scene. * Requests to remove the supplied objects from the current scene.
*/ */
@@ -34,10 +34,10 @@ public class ModifyObjectsUpdate extends SceneUpdate
{ {
/** The objects added to the scene (or <code>null</code> for none). */ /** The objects added to the scene (or <code>null</code> for none). */
public ObjectInfo[] added; public ObjectInfo[] added;
/** The objects removed from the scene (or <code>null</code> for none). */ /** The objects removed from the scene (or <code>null</code> for none). */
public ObjectInfo[] removed; public ObjectInfo[] removed;
/** /**
* Initializes this update with all necessary data. * Initializes this update with all necessary data.
* *
@@ -82,7 +82,7 @@ public class DirectionButton extends AbstractButton
repaint(); repaint();
} }
}); });
} }
@@ -180,7 +180,7 @@ public class DirectionButton extends AbstractButton
double rads = Math.PI * 2 * ii / num; double rads = Math.PI * 2 * ii / num;
// 0 radians specifies EAST, so we offset // 0 radians specifies EAST, so we offset
int dir = (ii + DirectionCodes.EAST) % num; int dir = (ii + DirectionCodes.EAST) % num;
_coords[dir][0] = mid + ((int) (mid * Math.cos(rads))); _coords[dir][0] = mid + ((int) (mid * Math.cos(rads)));
_coords[dir][1] = mid + ((int) (mid * Math.sin(rads))); _coords[dir][1] = mid + ((int) (mid * Math.sin(rads)));
@@ -87,7 +87,7 @@ public class ObjectEditorDialog extends EditorDialog
/** /**
* Prepare the dialog for display. This method should be called before <code>display()</code> * Prepare the dialog for display. This method should be called before <code>display()</code>
* is called. * is called.
* *
* @param scobj the object to edit. * @param scobj the object to edit.
*/ */
public void prepare (SceneObject scobj) public void prepare (SceneObject scobj)
@@ -55,7 +55,7 @@ public class PortalDialog extends EditorDialog
{ {
super("Edit Portal", ctx, panel); super("Edit Portal", ctx, panel);
} }
@Override @Override
public void addComponents(JComponent top){ public void addComponents(JComponent top){
// add the dialog instruction text // add the dialog instruction text
@@ -102,7 +102,7 @@ public class PreferencesDialog extends JInternalFrame
{ {
JFileChooser chooser; JFileChooser chooser;
// figure out which // figure out which
File f = new File(button.getText()); File f = new File(button.getText());
if (!f.exists()) { if (!f.exists()) {
chooser = new JFileChooser(); chooser = new JFileChooser();
@@ -91,7 +91,7 @@ public class EditorDialogUtil
center(parent, dialog); center(parent, dialog);
parent.getLayeredPane().add(dialog, JLayeredPane.POPUP_LAYER); parent.getLayeredPane().add(dialog, JLayeredPane.POPUP_LAYER);
dialog.setVisible(true); dialog.setVisible(true);
} }
/** /**
* Removes the supplied dialog from its parent container, but does not * Removes the supplied dialog from its parent container, but does not
@@ -167,7 +167,7 @@ public class ViewerApp
public KeyDispatcher getKeyDispatcher () { public KeyDispatcher getKeyDispatcher () {
return null; return null;
} }
// documentation inherited from interface // documentation inherited from interface
public String xlate (String message) { public String xlate (String message) {
return message; return message;
@@ -65,7 +65,7 @@ public class PlacementConstraints
_tilemgr = tilemgr; _tilemgr = tilemgr;
_scene = scene; _scene = scene;
_mmodel = StageMisoSceneModel.getSceneModel(scene.getSceneModel()); _mmodel = StageMisoSceneModel.getSceneModel(scene.getSceneModel());
// add all the objects in the scene // add all the objects in the scene
StageMisoSceneModel.ObjectVisitor visitor = StageMisoSceneModel.ObjectVisitor visitor =
new StageMisoSceneModel.ObjectVisitor() { new StageMisoSceneModel.ObjectVisitor() {
@@ -81,7 +81,7 @@ public class PlacementConstraints
}; };
_mmodel.visitObjects(visitor); _mmodel.visitObjects(visitor);
} }
/** /**
* Determines whether the constraints allow the specified object to be * Determines whether the constraints allow the specified object to be
* added to the scene. * added to the scene.
@@ -95,7 +95,7 @@ public class PlacementConstraints
return allowModifyObjects(new ObjectInfo[] { info }, return allowModifyObjects(new ObjectInfo[] { info },
new ObjectInfo[0]); new ObjectInfo[0]);
} }
/** /**
* Adds the specified object through the constraints. * Adds the specified object through the constraints.
*/ */
@@ -107,7 +107,7 @@ public class PlacementConstraints
_objectData.put(info, data); _objectData.put(info, data);
} }
} }
/** /**
* Determines whether the constraints allow the specified object to be * Determines whether the constraints allow the specified object to be
* removed from the scene. * removed from the scene.
@@ -121,7 +121,7 @@ public class PlacementConstraints
return allowModifyObjects(new ObjectInfo[0], return allowModifyObjects(new ObjectInfo[0],
new ObjectInfo[] { info }); new ObjectInfo[] { info });
} }
/** /**
* Removes the specified object through the constraints. * Removes the specified object through the constraints.
*/ */
@@ -130,7 +130,7 @@ public class PlacementConstraints
_scene.removeObject(info); _scene.removeObject(info);
_objectData.remove(info); _objectData.remove(info);
} }
/** /**
* Determines whether the constraints allow the specified objects to be * Determines whether the constraints allow the specified objects to be
* added and removed simultaneously. * added and removed simultaneously.
@@ -149,12 +149,12 @@ public class PlacementConstraints
return INTERNAL_ERROR; return INTERNAL_ERROR;
} }
} }
ObjectData[] removedData = getObjectDataFromInfo(removed); ObjectData[] removedData = getObjectDataFromInfo(removed);
if (removedData == null) { if (removedData == null) {
return INTERNAL_ERROR; return INTERNAL_ERROR;
} }
return allowModifyObjects(addedData, removedData); return allowModifyObjects(addedData, removedData);
} }
@@ -178,7 +178,7 @@ public class PlacementConstraints
} }
return data; return data;
} }
/** /**
* Determines whether the constraints allow the specified objects to be * Determines whether the constraints allow the specified objects to be
* added and removed simultaneously. Subclasses that wish to define * added and removed simultaneously. Subclasses that wish to define
@@ -192,62 +192,62 @@ public class PlacementConstraints
ObjectData[] removed) ObjectData[] removed)
{ {
DirectionHeight dirheight = new DirectionHeight(); DirectionHeight dirheight = new DirectionHeight();
for (int i = 0; i < added.length; i++) { for (int i = 0; i < added.length; i++) {
if (added[i].tile.hasConstraint(ObjectTileSet.ON_SURFACE) && if (added[i].tile.hasConstraint(ObjectTileSet.ON_SURFACE) &&
!isOnSurface(added[i], added, removed)) { !isOnSurface(added[i], added, removed)) {
return MessageBundle.qualify(STAGE_MESSAGE_BUNDLE, return MessageBundle.qualify(STAGE_MESSAGE_BUNDLE,
"m.not_on_surface"); "m.not_on_surface");
} }
int dir = getConstraintDirection(added[i], ObjectTileSet.ON_WALL); int dir = getConstraintDirection(added[i], ObjectTileSet.ON_WALL);
if (dir != NONE && !isOnWall(added[i], added, removed, dir)) { if (dir != NONE && !isOnWall(added[i], added, removed, dir)) {
return MessageBundle.qualify(STAGE_MESSAGE_BUNDLE, return MessageBundle.qualify(STAGE_MESSAGE_BUNDLE,
"m.not_on_wall"); "m.not_on_wall");
} }
if (getConstraintDirectionHeight(added[i], ObjectTileSet.ATTACH, if (getConstraintDirectionHeight(added[i], ObjectTileSet.ATTACH,
dirheight) && !isAttached(added[i], added, removed, dirheight) && !isAttached(added[i], added, removed,
dirheight.dir, dirheight.low)) { dirheight.dir, dirheight.low)) {
return MessageBundle.qualify(STAGE_MESSAGE_BUNDLE, return MessageBundle.qualify(STAGE_MESSAGE_BUNDLE,
"m.not_attached"); "m.not_attached");
} }
dir = getConstraintDirection(added[i], ObjectTileSet.SPACE); dir = getConstraintDirection(added[i], ObjectTileSet.SPACE);
if (dir != NONE && !hasSpace(added[i], added, removed, dir)) { if (dir != NONE && !hasSpace(added[i], added, removed, dir)) {
return MessageBundle.qualify(STAGE_MESSAGE_BUNDLE, return MessageBundle.qualify(STAGE_MESSAGE_BUNDLE,
"m.no_space"); "m.no_space");
} }
if (hasSpaceConstrainedAdjacent(added[i], added, removed)) { if (hasSpaceConstrainedAdjacent(added[i], added, removed)) {
return MessageBundle.qualify(STAGE_MESSAGE_BUNDLE, return MessageBundle.qualify(STAGE_MESSAGE_BUNDLE,
"m.no_space_adj"); "m.no_space_adj");
} }
} }
for (int i = 0; i < removed.length; i++) { for (int i = 0; i < removed.length; i++) {
if (removed[i].tile.hasConstraint(ObjectTileSet.SURFACE) && if (removed[i].tile.hasConstraint(ObjectTileSet.SURFACE) &&
hasOnSurface(removed[i], added, removed)) { hasOnSurface(removed[i], added, removed)) {
return MessageBundle.qualify(STAGE_MESSAGE_BUNDLE, return MessageBundle.qualify(STAGE_MESSAGE_BUNDLE,
"m.has_on_surface"); "m.has_on_surface");
} }
int dir = getConstraintDirection(removed[i], ObjectTileSet.WALL); int dir = getConstraintDirection(removed[i], ObjectTileSet.WALL);
if (dir != NONE) { if (dir != NONE) {
if (hasOnWall(removed[i], added, removed, dir)) { if (hasOnWall(removed[i], added, removed, dir)) {
return MessageBundle.qualify(STAGE_MESSAGE_BUNDLE, return MessageBundle.qualify(STAGE_MESSAGE_BUNDLE,
"m.has_on_wall"); "m.has_on_wall");
} else if (hasAttached(removed[i], added, removed, dir)) { } else if (hasAttached(removed[i], added, removed, dir)) {
return MessageBundle.qualify(STAGE_MESSAGE_BUNDLE, return MessageBundle.qualify(STAGE_MESSAGE_BUNDLE,
"m.has_attached"); "m.has_attached");
} }
} }
} }
return null; return null;
} }
/** /**
* Determines whether the specified surface has anything on it that won't * Determines whether the specified surface has anything on it that won't
* be held up if the surface is removed. * be held up if the surface is removed.
@@ -265,7 +265,7 @@ public class PlacementConstraints
} }
return false; return false;
} }
/** /**
* Determines whether the specified wall has anything on it that won't be * Determines whether the specified wall has anything on it that won't be
* held up if the wall is removed. * held up if the wall is removed.
@@ -283,7 +283,7 @@ public class PlacementConstraints
} }
return false; return false;
} }
/** /**
* Determines whether the specified wall has anything attached to it that * Determines whether the specified wall has anything attached to it that
* won't be held up if the wall is removed. * won't be held up if the wall is removed.
@@ -292,7 +292,7 @@ public class PlacementConstraints
ObjectData[] removed, int dir) ObjectData[] removed, int dir)
{ {
DirectionHeight dirheight = new DirectionHeight(); DirectionHeight dirheight = new DirectionHeight();
List<ObjectData> objects = getObjectData(getAdjacentEdge(data.bounds, List<ObjectData> objects = getObjectData(getAdjacentEdge(data.bounds,
DirectionUtil.getOpposite(dir)), added, removed); DirectionUtil.getOpposite(dir)), added, removed);
for (int i = 0, size = objects.size(); i < size; i++) { for (int i = 0, size = objects.size(); i < size; i++) {
@@ -305,7 +305,7 @@ public class PlacementConstraints
} }
return false; return false;
} }
/** /**
* Verifies that the objects adjacent to the given object will still have * Verifies that the objects adjacent to the given object will still have
* their space constraints met if the object is added. * their space constraints met if the object is added.
@@ -316,7 +316,7 @@ public class PlacementConstraints
Rectangle r = data.bounds; Rectangle r = data.bounds;
// grow the ObjectData bounds 1 square in each direction // grow the ObjectData bounds 1 square in each direction
_constrainRect.setBounds(r.x - 1, r.y - 1, r.width + 2, r.height + 2); _constrainRect.setBounds(r.x - 1, r.y - 1, r.width + 2, r.height + 2);
List<ObjectData> objects = getObjectData(_constrainRect, added, removed); List<ObjectData> objects = getObjectData(_constrainRect, added, removed);
for (int i = 0, size = objects.size(); i < size; i++) { for (int i = 0, size = objects.size(); i < size; i++) {
ObjectData odata = objects.get(i); ObjectData odata = objects.get(i);
@@ -327,7 +327,7 @@ public class PlacementConstraints
} }
return false; return false;
} }
/** /**
* Determines whether the specified object has empty space in the specified * Determines whether the specified object has empty space in the specified
* direction. * direction.
@@ -338,7 +338,7 @@ public class PlacementConstraints
return getObjectData(getAdjacentEdge(data.bounds, dir), added, return getObjectData(getAdjacentEdge(data.bounds, dir), added,
removed).size() == 0; removed).size() == 0;
} }
/** /**
* Determines whether the specified object is on a surface. * Determines whether the specified object is on a surface.
*/ */
@@ -348,7 +348,7 @@ public class PlacementConstraints
return isCovered(data.bounds, added, removed, ObjectTileSet.SURFACE, return isCovered(data.bounds, added, removed, ObjectTileSet.SURFACE,
null); null);
} }
/** /**
* Determines whether the specified object is on a wall facing the * Determines whether the specified object is on a wall facing the
* specified direction. * specified direction.
@@ -359,7 +359,7 @@ public class PlacementConstraints
return isCovered(data.bounds, added, removed, return isCovered(data.bounds, added, removed,
getDirectionalConstraint(ObjectTileSet.WALL, dir), null); getDirectionalConstraint(ObjectTileSet.WALL, dir), null);
} }
/** /**
* Determines whether the specified object is attached to another object in * Determines whether the specified object is attached to another object in
* the specified direction and at the specified height. * the specified direction and at the specified height.
@@ -371,7 +371,7 @@ public class PlacementConstraints
getDirectionalConstraint(ObjectTileSet.WALL, dir), low ? getDirectionalConstraint(ObjectTileSet.WALL, dir), low ?
getDirectionalConstraint(ObjectTileSet.WALL, dir, true) : null); getDirectionalConstraint(ObjectTileSet.WALL, dir, true) : null);
} }
/** /**
* Given a rectangle, determines whether all of the tiles within * Given a rectangle, determines whether all of the tiles within
* the rectangle intersect an object. If the constraint parameter is * the rectangle intersect an object. If the constraint parameter is
@@ -402,7 +402,7 @@ public class PlacementConstraints
} }
return true; return true;
} }
/** /**
* Creates and returns a rectangle that covers the specified rectangle's * Creates and returns a rectangle that covers the specified rectangle's
* adjacent edge (the squares one tile beyond the bounds) in the specified * adjacent edge (the squares one tile beyond the bounds) in the specified
@@ -413,23 +413,23 @@ public class PlacementConstraints
switch (dir) { switch (dir) {
case NORTH: case NORTH:
return new Rectangle(rect.x - 1, rect.y, 1, rect.height); return new Rectangle(rect.x - 1, rect.y, 1, rect.height);
case EAST: case EAST:
return new Rectangle(rect.x, rect.y - 1, rect.width, 1); return new Rectangle(rect.x, rect.y - 1, rect.width, 1);
case SOUTH: case SOUTH:
return new Rectangle(rect.x + rect.width, rect.y, 1, return new Rectangle(rect.x + rect.width, rect.y, 1,
rect.height); rect.height);
case WEST: case WEST:
return new Rectangle(rect.x, rect.y + rect.height, return new Rectangle(rect.x, rect.y + rect.height,
rect.width, 1); rect.width, 1);
default: default:
return null; return null;
} }
} }
/** /**
* Returns the direction in which the specified object is constrained by * Returns the direction in which the specified object is constrained by
* appending "[NESW]" to the given constraint prefix. Returns * appending "[NESW]" to the given constraint prefix. Returns
@@ -441,7 +441,7 @@ public class PlacementConstraints
return getConstraintDirectionHeight(data, prefix, dirheight) ? return getConstraintDirectionHeight(data, prefix, dirheight) ?
dirheight.dir : NONE; dirheight.dir : NONE;
} }
/** /**
* Populates the supplied {@link DirectionHeight} object with the direction * Populates the supplied {@link DirectionHeight} object with the direction
* and height of the constraint identified by the given prefix. * and height of the constraint identified by the given prefix.
@@ -456,7 +456,7 @@ public class PlacementConstraints
if (constraints == null) { if (constraints == null) {
return false; return false;
} }
for (int i = 0; i < constraints.length; i++) { for (int i = 0; i < constraints.length; i++) {
if (constraints[i].startsWith(prefix)) { if (constraints[i].startsWith(prefix)) {
int fromidx = prefix.length(), int fromidx = prefix.length(),
@@ -470,7 +470,7 @@ public class PlacementConstraints
} }
return false; return false;
} }
/** /**
* Given a constraint prefix and a direction, returns the directional * Given a constraint prefix and a direction, returns the directional
* constraint. * constraint.
@@ -479,7 +479,7 @@ public class PlacementConstraints
{ {
return getDirectionalConstraint(prefix, dir, false); return getDirectionalConstraint(prefix, dir, false);
} }
/** /**
* Given a constraint prefix, direction, and height, returns the * Given a constraint prefix, direction, and height, returns the
* directional constraint. * directional constraint.
@@ -490,7 +490,7 @@ public class PlacementConstraints
return prefix + DirectionUtil.toShortString(dir) + return prefix + DirectionUtil.toShortString(dir) +
(low ? ObjectTileSet.LOW : ""); (low ? ObjectTileSet.LOW : "");
} }
/** /**
* Finds all objects whose bounds intersect the given rectangle and * Finds all objects whose bounds intersect the given rectangle and
* returns a list containing their {@link ObjectData} elements. * returns a list containing their {@link ObjectData} elements.
@@ -502,7 +502,7 @@ public class PlacementConstraints
ObjectData[] removed) ObjectData[] removed)
{ {
List<ObjectData> list = Lists.newArrayList(); List<ObjectData> list = Lists.newArrayList();
for (Iterator<ObjectData> it = _objectData.values().iterator(); it.hasNext(); ) { for (Iterator<ObjectData> it = _objectData.values().iterator(); it.hasNext(); ) {
ObjectData data = it.next(); ObjectData data = it.next();
if (rect.intersects(data.bounds) && !ListUtil.contains(removed, if (rect.intersects(data.bounds) && !ListUtil.contains(removed,
@@ -510,16 +510,16 @@ public class PlacementConstraints
list.add(data); list.add(data);
} }
} }
for (int i = 0; i < added.length; i++) { for (int i = 0; i < added.length; i++) {
if (rect.intersects(added[i].bounds)) { if (rect.intersects(added[i].bounds)) {
list.add(added[i]); list.add(added[i]);
} }
} }
return list; return list;
} }
/** /**
* Using the tile manager, computes and returns the specified object's * Using the tile manager, computes and returns the specified object's
* data. * data.
@@ -532,42 +532,42 @@ public class PlacementConstraints
tile.getBaseHeight()); tile.getBaseHeight());
bounds.translate(1 - bounds.width, 1 - bounds.height); bounds.translate(1 - bounds.width, 1 - bounds.height);
return new ObjectData(bounds, tile); return new ObjectData(bounds, tile);
} catch (Exception e) { } catch (Exception e) {
log.warning("Error retrieving tile for object [info=" + info + "].", e); log.warning("Error retrieving tile for object [info=" + info + "].", e);
return null; return null;
} }
} }
/** Contains information about an object used in checking constraints. */ /** Contains information about an object used in checking constraints. */
protected class ObjectData protected class ObjectData
{ {
public Rectangle bounds; public Rectangle bounds;
public ObjectTile tile; public ObjectTile tile;
public ObjectData (Rectangle bounds, ObjectTile tile) public ObjectData (Rectangle bounds, ObjectTile tile)
{ {
this.bounds = bounds; this.bounds = bounds;
this.tile = tile; this.tile = tile;
} }
} }
/** Contains the direction and height of a constraint. */ /** Contains the direction and height of a constraint. */
protected class DirectionHeight protected class DirectionHeight
{ {
public int dir; public int dir;
public boolean low; public boolean low;
} }
/** The tile manager to use for object dimensions and constraints. */ /** The tile manager to use for object dimensions and constraints. */
protected TileManager _tilemgr; protected TileManager _tilemgr;
/** The scene being checked for constraints. */ /** The scene being checked for constraints. */
protected StageScene _scene; protected StageScene _scene;
/** The Miso scene model. */ /** The Miso scene model. */
protected StageMisoSceneModel _mmodel; protected StageMisoSceneModel _mmodel;
/** For all objects in the scene, maps {@link ObjectInfo}s to /** For all objects in the scene, maps {@link ObjectInfo}s to
* {@link ObjectData}s. */ * {@link ObjectData}s. */
protected HashMap<ObjectInfo,ObjectData> _objectData = new HashMap<ObjectInfo,ObjectData>(); protected HashMap<ObjectInfo,ObjectData> _objectData = new HashMap<ObjectInfo,ObjectData>();
@@ -82,7 +82,7 @@ public interface StageContext
* Returns a reference to the colorization repository. * Returns a reference to the colorization repository.
*/ */
public ColorPository getColorPository (); public ColorPository getColorPository ();
/** /**
* Translates the specified message using the default bundle. * Translates the specified message using the default bundle.
*/ */
@@ -66,7 +66,7 @@ public class StageSceneUtil
* should use the object's orientation. * should use the object's orientation.
*/ */
public static final int OBJECT_ORIENTATION = -1; public static final int OBJECT_ORIENTATION = -1;
/** /**
* Returns the scene metrics we use to do our calculations. * Returns the scene metrics we use to do our calculations.
*/ */
@@ -87,7 +87,7 @@ public class StageSceneUtil
/** /**
* Does the necessary jiggery pokery to figure out where the specified object's associated * Does the necessary jiggery pokery to figure out where the specified object's associated
* location is. * location is.
* *
* @param orient - the orientation to use in the returned location, or * @param orient - the orientation to use in the returned location, or
* {@link #OBJECT_ORIENTATION} if the object's orientation should be used * {@link #OBJECT_ORIENTATION} if the object's orientation should be used
*/ */
@@ -100,7 +100,7 @@ public class StageSceneUtil
/** /**
* Does the necessary jiggery pokery to figure out where the specified object's associated * Does the necessary jiggery pokery to figure out where the specified object's associated
* location is. * location is.
* *
* @param tilemgr a tile manager that can be used to look up the tile information. * @param tilemgr a tile manager that can be used to look up the tile information.
* @param tileId the fully qualified tile id of the object tile. * @param tileId the fully qualified tile id of the object tile.
* @param tx the object's x tile coordinate. * @param tx the object's x tile coordinate.
@@ -114,7 +114,7 @@ public class StageSceneUtil
/** /**
* Does the necessary jiggery pokery to figure out where the specified object's associated * Does the necessary jiggery pokery to figure out where the specified object's associated
* location is. * location is.
* *
* @param tilemgr a tile manager that can be used to look up the tile information. * @param tilemgr a tile manager that can be used to look up the tile information.
* @param tileId the fully qualified tile id of the object tile. * @param tileId the fully qualified tile id of the object tile.
* @param tx the object's x tile coordinate. * @param tx the object's x tile coordinate.
@@ -335,7 +335,7 @@ public class StageSceneUtil
* will be used to override the "natural" orientation of the spot * will be used to override the "natural" orientation of the spot
* which is facing toward the footprint. * which is facing toward the footprint.
* *
* @return the closest spot to the * @return the closest spot to the
*/ */
public static StageLocation findStandingSpot ( public static StageLocation findStandingSpot (
Rectangle foot, int dist, AStarPathUtil.TraversalPred pred, Rectangle foot, int dist, AStarPathUtil.TraversalPred pred,
@@ -208,7 +208,7 @@ public class SpotSceneManager extends SceneManager
{ {
return new SceneLocation(entry.getOppLocation(), body.getOid()); return new SceneLocation(entry.getOppLocation(), body.getOid());
} }
/** /**
* Move the specified body to the default portal, if possible. * Move the specified body to the default portal, if possible.
*/ */
@@ -400,11 +400,11 @@ public class SpotSceneManager extends SceneManager
{ {
handleClusterMessageRequest(sourceOid, new UserMessage(source, bundle, message, mode)); handleClusterMessageRequest(sourceOid, new UserMessage(source, bundle, message, mode));
} }
/** /**
* Called by the {@link SpotProvider} when we receive a cluster message request. * Called by the {@link SpotProvider} when we receive a cluster message request.
*/ */
protected void handleClusterMessageRequest (int sourceOid, UserMessage message) protected void handleClusterMessageRequest (int sourceOid, UserMessage message)
{ {
ClusterRecord clrec = getCluster(sourceOid); ClusterRecord clrec = getCluster(sourceOid);
if (clrec == null) { if (clrec == null) {
@@ -78,7 +78,7 @@ public class UpdateList
if (_updates.size() == 0 || _updates.get(0).getSceneVersion() > fromVersion) { if (_updates.size() == 0 || _updates.get(0).getSceneVersion() > fromVersion) {
return null; return null;
} }
List<SceneUpdate> updates = Lists.newArrayList(); List<SceneUpdate> updates = Lists.newArrayList();
for (SceneUpdate update : _updates) { for (SceneUpdate update : _updates) {
if (update.getSceneVersion() >= fromVersion) { if (update.getSceneVersion() >= fromVersion) {