Type our delegate ops instead of restricting our delegates.

git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@655 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
Michael Bayne
2008-07-10 13:37:10 +00:00
parent 17ffca41e7
commit 7b945dd674
3 changed files with 27 additions and 48 deletions
@@ -248,7 +248,7 @@ public abstract class GameController extends PlaceController
setGameOver(false); setGameOver(false);
// let our delegates do their business // let our delegates do their business
applyToDelegates(new DelegateOp() { applyToDelegates(new DelegateOp(GameControllerDelegate.class) {
public void apply (PlaceControllerDelegate delegate) { public void apply (PlaceControllerDelegate delegate) {
((GameControllerDelegate)delegate).gameDidStart(); ((GameControllerDelegate)delegate).gameDidStart();
} }
@@ -262,7 +262,7 @@ public abstract class GameController extends PlaceController
protected void gameDidEnd () protected void gameDidEnd ()
{ {
// let our delegates do their business // let our delegates do their business
applyToDelegates(new DelegateOp() { applyToDelegates(new DelegateOp(GameControllerDelegate.class) {
public void apply (PlaceControllerDelegate delegate) { public void apply (PlaceControllerDelegate delegate) {
((GameControllerDelegate)delegate).gameDidEnd(); ((GameControllerDelegate)delegate).gameDidEnd();
} }
@@ -275,7 +275,7 @@ public abstract class GameController extends PlaceController
protected void gameWasCancelled () protected void gameWasCancelled ()
{ {
// let our delegates do their business // let our delegates do their business
applyToDelegates(new DelegateOp() { applyToDelegates(new DelegateOp(GameControllerDelegate.class) {
public void apply (PlaceControllerDelegate delegate) { public void apply (PlaceControllerDelegate delegate) {
((GameControllerDelegate)delegate).gameWasCancelled(); ((GameControllerDelegate)delegate).gameWasCancelled();
} }
@@ -289,23 +289,13 @@ public abstract class GameController extends PlaceController
protected void gameWillReset () protected void gameWillReset ()
{ {
// let our delegates do their business // let our delegates do their business
applyToDelegates(new DelegateOp() { applyToDelegates(new DelegateOp(GameControllerDelegate.class) {
public void apply (PlaceControllerDelegate delegate) { public void apply (PlaceControllerDelegate delegate) {
((GameControllerDelegate)delegate).gameWillReset(); ((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. */ /** A reference to the active parlor context. */
protected ParlorContext _ctx; protected ParlorContext _ctx;
@@ -242,7 +242,7 @@ public class GameManager extends PlaceManager
playerWasReplaced(pidx, oplayer, player); playerWasReplaced(pidx, oplayer, player);
// notify our delegates // notify our delegates
applyToDelegates(new DelegateOp() { applyToDelegates(new DelegateOp(GameManagerDelegate.class) {
public void apply (PlaceManagerDelegate delegate) { public void apply (PlaceManagerDelegate delegate) {
((GameManagerDelegate)delegate).playerWasReplaced(pidx, oplayer, player); ((GameManagerDelegate)delegate).playerWasReplaced(pidx, oplayer, player);
} }
@@ -284,7 +284,7 @@ public class GameManager extends PlaceManager
_AIs[pidx] = ai; _AIs[pidx] = ai;
// let the delegates know that the player's been made an 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) { public void apply (PlaceManagerDelegate delegate) {
((GameManagerDelegate)delegate).setAI(pidx, ai); ((GameManagerDelegate)delegate).setAI(pidx, ai);
} }
@@ -974,7 +974,7 @@ public class GameManager extends PlaceManager
_gameobj.setSessionId(_gameobj.sessionId + 1); _gameobj.setSessionId(_gameobj.sessionId + 1);
// let our delegates do their business // let our delegates do their business
applyToDelegates(new DelegateOp() { applyToDelegates(new DelegateOp(GameManagerDelegate.class) {
public void apply (PlaceManagerDelegate delegate) { public void apply (PlaceManagerDelegate delegate) {
((GameManagerDelegate)delegate).gameWillStart(); ((GameManagerDelegate)delegate).gameWillStart();
} }
@@ -1034,7 +1034,7 @@ public class GameManager extends PlaceManager
} }
// let our delegates do their business // let our delegates do their business
applyToDelegates(new DelegateOp() { applyToDelegates(new DelegateOp(GameManagerDelegate.class) {
public void apply (PlaceManagerDelegate delegate) { public void apply (PlaceManagerDelegate delegate) {
((GameManagerDelegate)delegate).gameDidStart(); ((GameManagerDelegate)delegate).gameDidStart();
} }
@@ -1107,7 +1107,7 @@ public class GameManager extends PlaceManager
*/ */
protected void tickAI (final int pidx, final GameAI ai) protected void tickAI (final int pidx, final GameAI ai)
{ {
applyToDelegates(new DelegateOp() { applyToDelegates(new DelegateOp(GameManagerDelegate.class) {
public void apply (PlaceManagerDelegate delegate) { public void apply (PlaceManagerDelegate delegate) {
((GameManagerDelegate) delegate).tickAI(pidx, ai); ((GameManagerDelegate) delegate).tickAI(pidx, ai);
} }
@@ -1173,7 +1173,7 @@ public class GameManager extends PlaceManager
protected void gameWillEnd () protected void gameWillEnd ()
{ {
// let our delegates do their business // let our delegates do their business
applyToDelegates(new DelegateOp() { applyToDelegates(new DelegateOp(GameManagerDelegate.class) {
public void apply (PlaceManagerDelegate delegate) { public void apply (PlaceManagerDelegate delegate) {
((GameManagerDelegate)delegate).gameWillEnd(); ((GameManagerDelegate)delegate).gameWillEnd();
} }
@@ -1191,7 +1191,7 @@ public class GameManager extends PlaceManager
stopAITicker(); stopAITicker();
// let our delegates do their business // let our delegates do their business
applyToDelegates(new DelegateOp() { applyToDelegates(new DelegateOp(GameManagerDelegate.class) {
public void apply (PlaceManagerDelegate delegate) { public void apply (PlaceManagerDelegate delegate) {
((GameManagerDelegate)delegate).gameDidEnd(); ((GameManagerDelegate)delegate).gameDidEnd();
} }
@@ -1267,7 +1267,7 @@ public class GameManager extends PlaceManager
_gameobj.setPlayerStatus(new int[getPlayerSlots()]); _gameobj.setPlayerStatus(new int[getPlayerSlots()]);
// let our delegates do their business // let our delegates do their business
applyToDelegates(new DelegateOp() { applyToDelegates(new DelegateOp(GameManagerDelegate.class) {
public void apply (PlaceManagerDelegate delegate) { public void apply (PlaceManagerDelegate delegate) {
((GameManagerDelegate)delegate).gameWillReset(); ((GameManagerDelegate)delegate).gameWillReset();
} }
@@ -1283,15 +1283,6 @@ public class GameManager extends PlaceManager
// nothing for now // 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. */ /** Listens for game state changes. */
protected AttributeChangeListener _stateListener = new AttributeChangeListener() { protected AttributeChangeListener _stateListener = new AttributeChangeListener() {
public void attributeChanged (AttributeChangedEvent event) { public void attributeChanged (AttributeChangedEvent event) {
@@ -29,8 +29,9 @@ import java.awt.event.KeyAdapter;
import java.awt.event.MouseAdapter; import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent; 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.swing.util.MouseHijacker;
import com.samskivert.util.CollectionUtil; import com.samskivert.util.CollectionUtil;
@@ -180,7 +181,7 @@ public abstract class PuzzleController extends GameController
_chatting = chatting; _chatting = chatting;
// dispatch the change to our delegates // dispatch the change to our delegates
applyToDelegates(PuzzleControllerDelegate.class, new DelegateOp() { applyToDelegates(new DelegateOp(PuzzleControllerDelegate.class) {
public void apply (PlaceControllerDelegate delegate) { public void apply (PlaceControllerDelegate delegate) {
((PuzzleControllerDelegate)delegate).setChatting(_chatting); ((PuzzleControllerDelegate)delegate).setChatting(_chatting);
} }
@@ -224,7 +225,7 @@ public abstract class PuzzleController extends GameController
{ {
// check with the delegates // check with the delegates
final boolean[] canChatNow = new boolean[] { true }; final boolean[] canChatNow = new boolean[] { true };
applyToDelegates(PuzzleControllerDelegate.class, new DelegateOp() { applyToDelegates(new DelegateOp(PuzzleControllerDelegate.class) {
public void apply (PlaceControllerDelegate delegate) { public void apply (PlaceControllerDelegate delegate) {
canChatNow[0] = canChatNow[0] =
((PuzzleControllerDelegate)delegate).canStartChatting() && ((PuzzleControllerDelegate)delegate).canStartChatting() &&
@@ -447,7 +448,7 @@ public abstract class PuzzleController extends GameController
} }
// let our delegates do their business // let our delegates do their business
applyToDelegates(PuzzleControllerDelegate.class, new DelegateOp() { applyToDelegates(new DelegateOp(PuzzleControllerDelegate.class) {
public void apply (PlaceControllerDelegate delegate) { public void apply (PlaceControllerDelegate delegate) {
((PuzzleControllerDelegate)delegate).startAction(); ((PuzzleControllerDelegate)delegate).startAction();
} }
@@ -557,7 +558,7 @@ public abstract class PuzzleController extends GameController
// } // }
// let our delegates do their business // let our delegates do their business
applyToDelegates(PuzzleControllerDelegate.class, new DelegateOp() { applyToDelegates(new DelegateOp(PuzzleControllerDelegate.class) {
public void apply (PlaceControllerDelegate delegate) { public void apply (PlaceControllerDelegate delegate) {
canClear[0] = canClear[0] && canClear[0] = canClear[0] &&
((PuzzleControllerDelegate)delegate).canClearAction(); ((PuzzleControllerDelegate)delegate).canClearAction();
@@ -599,7 +600,7 @@ public abstract class PuzzleController extends GameController
// PuzzleBoardView.DEBUG_ACTION = false; // PuzzleBoardView.DEBUG_ACTION = false;
// let our delegates do their business // let our delegates do their business
applyToDelegates(PuzzleControllerDelegate.class, new DelegateOp() { applyToDelegates(new DelegateOp(PuzzleControllerDelegate.class) {
public void apply (PlaceControllerDelegate delegate) { public void apply (PlaceControllerDelegate delegate) {
((PuzzleControllerDelegate)delegate).clearAction(); ((PuzzleControllerDelegate)delegate).clearAction();
} }
@@ -693,12 +694,11 @@ public abstract class PuzzleController extends GameController
_pview.repaint(); _pview.repaint();
// let our delegates do their business // let our delegates do their business
DelegateOp dop = new DelegateOp() { applyToDelegates(new DelegateOp(PuzzleControllerDelegate.class) {
public void apply (PlaceControllerDelegate delegate) { public void apply (PlaceControllerDelegate delegate) {
((PuzzleControllerDelegate)delegate).setBoard(_pboard); ((PuzzleControllerDelegate)delegate).setBoard(_pboard);
} }
}; });
applyToDelegates(PuzzleControllerDelegate.class, dop);
return CARE_NOT; return CARE_NOT;
} }
@@ -740,7 +740,7 @@ public abstract class PuzzleController extends GameController
_events.add(Integer.valueOf(event)); _events.add(Integer.valueOf(event));
if (isSyncingBoards()) { if (isSyncingBoards()) {
_states.add((board == null) ? null : board.clone()); _states.add((board == null) ? null : (Board)board.clone());
if (board == null) { if (board == null) {
log.warning("Added progress event with no associated board " + log.warning("Added progress event with no associated board " +
"state, server will not be able to ensure " + "state, server will not be able to ensure " +
@@ -795,7 +795,7 @@ public abstract class PuzzleController extends GameController
protected void playerKnockedOut (final int pidx) protected void playerKnockedOut (final int pidx)
{ {
// dispatch this to our delegates // dispatch this to our delegates
applyToDelegates(PuzzleControllerDelegate.class, new DelegateOp() { applyToDelegates(new DelegateOp(PuzzleControllerDelegate.class) {
public void apply (PlaceControllerDelegate delegate) { public void apply (PlaceControllerDelegate delegate) {
((PuzzleControllerDelegate)delegate).playerKnockedOut(pidx); ((PuzzleControllerDelegate)delegate).playerKnockedOut(pidx);
} }
@@ -922,11 +922,10 @@ public abstract class PuzzleController extends GameController
protected Board _pboard; protected Board _pboard;
/** The list of relevant game events since the last progress update. */ /** The list of relevant game events since the last progress update. */
protected ArrayList _events = new ArrayList(); protected List<Integer> _events = Lists.newArrayList();
/** Board snapshots that correspond to our board state after each of /** Board snapshots that correspond to board state after each event has been applied. */
* our events has been applied. */ protected List<Board> _states = Lists.newArrayList();
protected ArrayList _states = new ArrayList();
/** A flag indicating that we're in chatting mode. */ /** A flag indicating that we're in chatting mode. */
protected boolean _chatting = false; protected boolean _chatting = false;
@@ -935,8 +934,7 @@ public abstract class PuzzleController extends GameController
protected int _astate = ACTION_CLEARED; protected int _astate = ACTION_CLEARED;
/** The action cleared penders. */ /** The action cleared penders. */
protected ObserverList _clearPenders = new ObserverList( protected ObserverList _clearPenders = ObserverList.newSafeInOrder();
ObserverList.SAFE_IN_ORDER_NOTIFY);
/** A key listener that currently just toggles pause in the puzzle. */ /** A key listener that currently just toggles pause in the puzzle. */
protected KeyListener _globalKeyListener = new KeyAdapter() { protected KeyListener _globalKeyListener = new KeyAdapter() {