Wait until the usercode has connected to the GameControlBackend prior

to sending a playerReady notification to the server.


git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@212 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
Ray Greenwell
2007-02-26 19:20:15 +00:00
parent 6808911f65
commit 44ad4f517d
3 changed files with 43 additions and 2 deletions
@@ -26,6 +26,7 @@ import flash.events.Event;
import com.threerings.util.Name;
import com.threerings.crowd.client.PlaceView;
import com.threerings.crowd.data.BodyObject;
import com.threerings.crowd.data.PlaceConfig;
import com.threerings.crowd.data.PlaceObject;
import com.threerings.crowd.util.CrowdContext;
@@ -50,6 +51,15 @@ public class EZGameController extends GameController
addDelegate(_turnDelegate = new TurnGameControllerDelegate(this));
}
/**
* This is called by the GameControlBackend once it has initialized
* and made contact with usercode.
*/
public function userCodeIsConnected () :void
{
playerReady();
}
override public function willEnterPlace (plobj :PlaceObject) :void
{
_ezObj = (plobj as EZGameObject);
@@ -70,6 +80,22 @@ public class EZGameController extends GameController
_panel.backend.turnDidChange();
}
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.");
}
}
override protected function gameDidStart () :void
{
super.gameDidStart();
@@ -89,7 +89,7 @@ public class EZGamePanel extends Canvas
*/
protected function createBackend () :GameControlBackend
{
return new GameControlBackend(_ctx, _ezObj);
return new GameControlBackend(_ctx, _ezObj, _ctrl);
}
protected var _ctx :CrowdContext;
@@ -89,10 +89,11 @@ public class GameControlBackend
public var log :Log = Log.getLog(this);
public function GameControlBackend (
ctx :CrowdContext, ezObj :EZGameObject)
ctx :CrowdContext, ezObj :EZGameObject, ctrl :EZGameController)
{
_ctx = ctx;
_ezObj = ezObj;
_ctrl = ctrl;
_gameData = new GameData(setProperty_v1, _ezObj.getUserProps());
_ezObj.addListener(this);
@@ -104,6 +105,14 @@ public class GameControlBackend
disp.addEventListener("ezgameQuery", handleEZQuery);
}
/**
* Are we connected to the usercode on the front-end?
*/
public function isConnected () :Boolean
{
return (_userFuncs != null);
}
public function setContainer (container :GameContainer) :void
{
_container = container;
@@ -120,6 +129,9 @@ public class GameControlBackend
setUserCodeProperties(evt.userProps);
evt.ezProps = new Object();
populateProperties(evt.ezProps);
// ok, we're now hooked-up with the game code
_ctrl.userCodeIsConnected();
}
protected function setUserCodeProperties (o :Object) :void
@@ -813,6 +825,9 @@ public class GameControlBackend
protected var _ezObj :EZGameObject;
/** Handles trusted clientside control. */
protected var _ctrl :EZGameController;
protected var _userFuncs :Object;
/** The function on the EZGameControl which we can use to directly