diff --git a/src/java/com/threerings/parlor/game/client/GameController.java b/src/java/com/threerings/parlor/game/client/GameController.java index a543e206..85da607e 100644 --- a/src/java/com/threerings/parlor/game/client/GameController.java +++ b/src/java/com/threerings/parlor/game/client/GameController.java @@ -248,7 +248,7 @@ public abstract class GameController extends PlaceController setGameOver(false); // let our delegates do their business - applyToDelegates(new DelegateOp() { + applyToDelegates(new DelegateOp(GameControllerDelegate.class) { public void apply (PlaceControllerDelegate delegate) { ((GameControllerDelegate)delegate).gameDidStart(); } @@ -262,7 +262,7 @@ public abstract class GameController extends PlaceController protected void gameDidEnd () { // let our delegates do their business - applyToDelegates(new DelegateOp() { + applyToDelegates(new DelegateOp(GameControllerDelegate.class) { public void apply (PlaceControllerDelegate delegate) { ((GameControllerDelegate)delegate).gameDidEnd(); } @@ -275,7 +275,7 @@ public abstract class GameController extends PlaceController protected void gameWasCancelled () { // let our delegates do their business - applyToDelegates(new DelegateOp() { + applyToDelegates(new DelegateOp(GameControllerDelegate.class) { public void apply (PlaceControllerDelegate delegate) { ((GameControllerDelegate)delegate).gameWasCancelled(); } @@ -289,23 +289,13 @@ public abstract class GameController extends PlaceController protected void gameWillReset () { // let our delegates do their business - applyToDelegates(new DelegateOp() { + applyToDelegates(new DelegateOp(GameControllerDelegate.class) { public void apply (PlaceControllerDelegate delegate) { ((GameControllerDelegate)delegate).gameWillReset(); } }); } - @Override // from PlaceController - protected void ratifyDelegate (PlaceControllerDelegate delegate) - { - super.ratifyDelegate(delegate); - if (!(delegate instanceof GameControllerDelegate)) { - throw new IllegalArgumentException( - "Must provide GameController with GameControllerDelegate"); - } - } - /** A reference to the active parlor context. */ protected ParlorContext _ctx; diff --git a/src/java/com/threerings/parlor/game/server/GameManager.java b/src/java/com/threerings/parlor/game/server/GameManager.java index c1c66498..ba25ca8f 100644 --- a/src/java/com/threerings/parlor/game/server/GameManager.java +++ b/src/java/com/threerings/parlor/game/server/GameManager.java @@ -242,7 +242,7 @@ public class GameManager extends PlaceManager playerWasReplaced(pidx, oplayer, player); // notify our delegates - applyToDelegates(new DelegateOp() { + applyToDelegates(new DelegateOp(GameManagerDelegate.class) { public void apply (PlaceManagerDelegate delegate) { ((GameManagerDelegate)delegate).playerWasReplaced(pidx, oplayer, player); } @@ -284,7 +284,7 @@ public class GameManager extends PlaceManager _AIs[pidx] = ai; // let the delegates know that the player's been made an AI - applyToDelegates(new DelegateOp() { + applyToDelegates(new DelegateOp(GameManagerDelegate.class) { public void apply (PlaceManagerDelegate delegate) { ((GameManagerDelegate)delegate).setAI(pidx, ai); } @@ -974,7 +974,7 @@ public class GameManager extends PlaceManager _gameobj.setSessionId(_gameobj.sessionId + 1); // let our delegates do their business - applyToDelegates(new DelegateOp() { + applyToDelegates(new DelegateOp(GameManagerDelegate.class) { public void apply (PlaceManagerDelegate delegate) { ((GameManagerDelegate)delegate).gameWillStart(); } @@ -1034,7 +1034,7 @@ public class GameManager extends PlaceManager } // let our delegates do their business - applyToDelegates(new DelegateOp() { + applyToDelegates(new DelegateOp(GameManagerDelegate.class) { public void apply (PlaceManagerDelegate delegate) { ((GameManagerDelegate)delegate).gameDidStart(); } @@ -1107,7 +1107,7 @@ public class GameManager extends PlaceManager */ protected void tickAI (final int pidx, final GameAI ai) { - applyToDelegates(new DelegateOp() { + applyToDelegates(new DelegateOp(GameManagerDelegate.class) { public void apply (PlaceManagerDelegate delegate) { ((GameManagerDelegate) delegate).tickAI(pidx, ai); } @@ -1173,7 +1173,7 @@ public class GameManager extends PlaceManager protected void gameWillEnd () { // let our delegates do their business - applyToDelegates(new DelegateOp() { + applyToDelegates(new DelegateOp(GameManagerDelegate.class) { public void apply (PlaceManagerDelegate delegate) { ((GameManagerDelegate)delegate).gameWillEnd(); } @@ -1191,7 +1191,7 @@ public class GameManager extends PlaceManager stopAITicker(); // let our delegates do their business - applyToDelegates(new DelegateOp() { + applyToDelegates(new DelegateOp(GameManagerDelegate.class) { public void apply (PlaceManagerDelegate delegate) { ((GameManagerDelegate)delegate).gameDidEnd(); } @@ -1267,7 +1267,7 @@ public class GameManager extends PlaceManager _gameobj.setPlayerStatus(new int[getPlayerSlots()]); // let our delegates do their business - applyToDelegates(new DelegateOp() { + applyToDelegates(new DelegateOp(GameManagerDelegate.class) { public void apply (PlaceManagerDelegate delegate) { ((GameManagerDelegate)delegate).gameWillReset(); } @@ -1283,15 +1283,6 @@ public class GameManager extends PlaceManager // nothing for now } - @Override // from PlaceManager - protected void ratifyDelegate (PlaceManagerDelegate delegate) - { - super.ratifyDelegate(delegate); - if (!(delegate instanceof GameManagerDelegate)) { - throw new IllegalArgumentException("Must provide GameManager with GameManagerDelegate"); - } - } - /** Listens for game state changes. */ protected AttributeChangeListener _stateListener = new AttributeChangeListener() { public void attributeChanged (AttributeChangedEvent event) { diff --git a/src/java/com/threerings/puzzle/client/PuzzleController.java b/src/java/com/threerings/puzzle/client/PuzzleController.java index 8945b130..959f80e5 100644 --- a/src/java/com/threerings/puzzle/client/PuzzleController.java +++ b/src/java/com/threerings/puzzle/client/PuzzleController.java @@ -29,8 +29,9 @@ import java.awt.event.KeyAdapter; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; -import java.util.ArrayList; +import java.util.List; +import com.google.common.collect.Lists; import com.samskivert.swing.util.MouseHijacker; import com.samskivert.util.CollectionUtil; @@ -180,7 +181,7 @@ public abstract class PuzzleController extends GameController _chatting = chatting; // dispatch the change to our delegates - applyToDelegates(PuzzleControllerDelegate.class, new DelegateOp() { + applyToDelegates(new DelegateOp(PuzzleControllerDelegate.class) { public void apply (PlaceControllerDelegate delegate) { ((PuzzleControllerDelegate)delegate).setChatting(_chatting); } @@ -224,7 +225,7 @@ public abstract class PuzzleController extends GameController { // check with the delegates final boolean[] canChatNow = new boolean[] { true }; - applyToDelegates(PuzzleControllerDelegate.class, new DelegateOp() { + applyToDelegates(new DelegateOp(PuzzleControllerDelegate.class) { public void apply (PlaceControllerDelegate delegate) { canChatNow[0] = ((PuzzleControllerDelegate)delegate).canStartChatting() && @@ -447,7 +448,7 @@ public abstract class PuzzleController extends GameController } // let our delegates do their business - applyToDelegates(PuzzleControllerDelegate.class, new DelegateOp() { + applyToDelegates(new DelegateOp(PuzzleControllerDelegate.class) { public void apply (PlaceControllerDelegate delegate) { ((PuzzleControllerDelegate)delegate).startAction(); } @@ -557,7 +558,7 @@ public abstract class PuzzleController extends GameController // } // let our delegates do their business - applyToDelegates(PuzzleControllerDelegate.class, new DelegateOp() { + applyToDelegates(new DelegateOp(PuzzleControllerDelegate.class) { public void apply (PlaceControllerDelegate delegate) { canClear[0] = canClear[0] && ((PuzzleControllerDelegate)delegate).canClearAction(); @@ -599,7 +600,7 @@ public abstract class PuzzleController extends GameController // PuzzleBoardView.DEBUG_ACTION = false; // let our delegates do their business - applyToDelegates(PuzzleControllerDelegate.class, new DelegateOp() { + applyToDelegates(new DelegateOp(PuzzleControllerDelegate.class) { public void apply (PlaceControllerDelegate delegate) { ((PuzzleControllerDelegate)delegate).clearAction(); } @@ -693,12 +694,11 @@ public abstract class PuzzleController extends GameController _pview.repaint(); // let our delegates do their business - DelegateOp dop = new DelegateOp() { + applyToDelegates(new DelegateOp(PuzzleControllerDelegate.class) { public void apply (PlaceControllerDelegate delegate) { ((PuzzleControllerDelegate)delegate).setBoard(_pboard); } - }; - applyToDelegates(PuzzleControllerDelegate.class, dop); + }); return CARE_NOT; } @@ -740,7 +740,7 @@ public abstract class PuzzleController extends GameController _events.add(Integer.valueOf(event)); if (isSyncingBoards()) { - _states.add((board == null) ? null : board.clone()); + _states.add((board == null) ? null : (Board)board.clone()); if (board == null) { log.warning("Added progress event with no associated board " + "state, server will not be able to ensure " + @@ -795,7 +795,7 @@ public abstract class PuzzleController extends GameController protected void playerKnockedOut (final int pidx) { // dispatch this to our delegates - applyToDelegates(PuzzleControllerDelegate.class, new DelegateOp() { + applyToDelegates(new DelegateOp(PuzzleControllerDelegate.class) { public void apply (PlaceControllerDelegate delegate) { ((PuzzleControllerDelegate)delegate).playerKnockedOut(pidx); } @@ -922,11 +922,10 @@ public abstract class PuzzleController extends GameController protected Board _pboard; /** The list of relevant game events since the last progress update. */ - protected ArrayList _events = new ArrayList(); + protected List _events = Lists.newArrayList(); - /** Board snapshots that correspond to our board state after each of - * our events has been applied. */ - protected ArrayList _states = new ArrayList(); + /** Board snapshots that correspond to board state after each event has been applied. */ + protected List _states = Lists.newArrayList(); /** A flag indicating that we're in chatting mode. */ protected boolean _chatting = false; @@ -935,8 +934,7 @@ public abstract class PuzzleController extends GameController protected int _astate = ACTION_CLEARED; /** The action cleared penders. */ - protected ObserverList _clearPenders = new ObserverList( - ObserverList.SAFE_IN_ORDER_NOTIFY); + protected ObserverList _clearPenders = ObserverList.newSafeInOrder(); /** A key listener that currently just toggles pause in the puzzle. */ protected KeyListener _globalKeyListener = new KeyAdapter() {