Slight change to playerReady() handling. For party games all occupants will

call playerReady() rather than none of them. Also tidied up the way
EZGameController delays playerReady() until the game backend is connected.


git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@520 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
Michael Bayne
2007-12-07 21:21:09 +00:00
parent ddba842c5c
commit b6b8b39c9f
3 changed files with 33 additions and 23 deletions
@@ -34,6 +34,7 @@ import com.threerings.crowd.data.PlaceObject;
import com.threerings.crowd.util.CrowdContext;
import com.threerings.parlor.game.client.GameController;
import com.threerings.parlor.game.data.GameConfig;
import com.threerings.parlor.game.data.GameObject;
import com.threerings.parlor.turn.client.TurnGameController;
@@ -58,6 +59,13 @@ public class EZGameController extends GameController
*/
public function userCodeIsConnected (autoReady :Boolean) :void
{
// if we're not a player, we don't need to report anything to the server
var bobj :BodyObject = (_ctx.getClient().getClientObject() as BodyObject);
if (_gconfig.getMatchType() != GameConfig.PARTY &&
_gobj.getPlayerIndex(bobj.getVisibleName()) != -1) {
return;
}
if (autoReady) {
// let the game manager know that we're here and we want to start the game now
playerIsReady();
@@ -99,6 +107,14 @@ public class EZGameController extends GameController
_panel.backend.turnDidChange();
}
// from GameController
override protected function shouldAutoPlayerReady (bobj :BodyObject) :Boolean
{
// we don't want to auto-player ready in willEnterPlace(), we'll do it ourselves after the
// client code has connected
return false;
}
// from GameController
override public function attributeChanged (event :AttributeChangedEvent) :void
{
@@ -116,22 +132,6 @@ public class EZGameController extends GameController
}
}
// from GameController
override protected function playerReady () :void
{
// we require the user to be connected, and we redundantly only do this if the user is in
// the players array
if (_panel.backend.isConnected()) {
var bobj :BodyObject = (_ctx.getClient().getClientObject() as BodyObject);
if (_gobj.getPlayerIndex(bobj.getVisibleName()) != -1) {
super.playerReady();
}
} else {
log.debug("Waiting to call playerReady, userCode not yet connected.");
}
}
// from GameController
override protected function gameDidStart () :void
{
@@ -540,7 +540,8 @@ public class GameControlBackend
}
/**
* Called by the client code when it is ready for the game to be started.
* Called by the client code when it is ready for the game to be started (if called before the
* game ever starts) or rematched (if called after the game has ended).
*/
protected function playerReady_v1 () :void
{
@@ -95,14 +95,15 @@ public /*abstract*/ class GameController extends PlaceController
// and add ourselves as a listener
_gobj.addListener(this);
// we don't want to claim to be finished until any derived classes that overrode this
// method have executed, so we'll queue up a runnable here that will let the game manager
// know that we're ready on the next pass through the distributed event loop
log.info("Entering game " + _gobj.which() + ".");
if (_gobj.getPlayerIndex(bobj.getVisibleName()) != -1) {
// finally let the game manager know that we're ready to roll
// potentially let the game manager know that we're ready to roll
if (shouldAutoPlayerReady(bobj)) {
// we don't want to claim to be finished until any derived classes that overrode this
// method have executed, so we'll queue up a runnable here that will let the game
// manager know that we're ready on the next pass through the distributed event loop
_ctx.getClient().callLater(playerReady);
}
log.info("Entered game " + _gobj.which() + ".");
}
/**
@@ -222,6 +223,14 @@ public /*abstract*/ class GameController extends PlaceController
return false;
}
/**
* Returns true if we should automatically call playerReady() in willEnterPlace().
*/
protected function shouldAutoPlayerReady (bobj :BodyObject) :Boolean
{
return (_gobj.getPlayerIndex(bobj.getVisibleName()) != -1);
}
/**
* Called after we've entered the game and everything has initialized
* to notify the server that we, as a player, are ready to play.