The way we were postponing gameDidStart() and gameDidEnd() until after the

action cleared was ungood. It really only worked for the delegates. Now we
do it in a way that works for the controllers themselves and the delegates.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3189 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2004-10-29 16:32:10 +00:00
parent 14c3a0515a
commit 78e7fd6837
@@ -1,5 +1,5 @@
// //
// $Id: PuzzleController.java,v 1.18 2004/10/28 19:20:04 mdb Exp $ // $Id: PuzzleController.java,v 1.19 2004/10/29 16:32:10 mdb Exp $
// //
// Narya library - tools for developing networked games // Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved // Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
@@ -343,37 +343,47 @@ public abstract class PuzzleController extends GameController
} }
// documentation inherited // documentation inherited
protected void gameDidStart () public void attributeChanged (AttributeChangedEvent event)
{ {
// deal with game state changes
if (event.getName().equals(PuzzleObject.STATE)) {
switch (event.getIntValue()) {
case PuzzleObject.IN_PLAY:
// we have to postpone all game starting activity until the // we have to postpone all game starting activity until the
// current action has ended; only after all the animations have // current action has ended; only after all the animations have
// been completed will everything be in a state fit for starting // been completed will everything be in a state fit for
// back up again // starting back up again
fireWhenActionCleared(new ClearPender() { fireWhenActionCleared(new ClearPender() {
public int actionCleared () { public int actionCleared () {
// do the standard game did start business // do the standard game did start business
PuzzleController.super.gameDidStart(); gameDidStart();
// we don't always start the action immediately // we don't always start the action immediately
return startActionImmediately() ? return startActionImmediately() ?
RESTART_ACTION : NO_RESTART_ACTION; RESTART_ACTION : NO_RESTART_ACTION;
} }
}); });
} break;
// documentation inherited case PuzzleObject.GAME_OVER:
protected void gameDidEnd () // similarly we haev to postpone game ending activity until
{ // the current action has ended
// clean up and clear out // clean up and clear out
clearAction(); clearAction();
// wait until the action is cleared before we roll down to our // wait until the action is cleared before we roll down to our
// delegates and do all that business // delegates and do all that business
fireWhenActionCleared(new ClearPender() { fireWhenActionCleared(new ClearPender() {
public int actionCleared () { public int actionCleared () {
PuzzleController.super.gameDidEnd(); gameDidEnd();
return CARE_NOT; return CARE_NOT;
} }
}); });
break;
default:
super.attributeChanged(event);
break;
}
}
} }
// documentation inherited // documentation inherited