Added a server managed notion of which client is controlling the game.
Doing this on the client, while theoretically possible, is more complex. We have a server, we use it to provide commonly needed services, the assignment of a single client to control the game is a commonly needed service. This also matches the way other services like turn change and game start and end are implemented. A side note: the client-side code was not properly handling disconnected players, which the server code properly handles. git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@224 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
@@ -25,6 +25,8 @@ import flash.events.Event;
|
||||
|
||||
import com.threerings.util.Name;
|
||||
|
||||
import com.threerings.presents.dobj.AttributeChangedEvent;
|
||||
|
||||
import com.threerings.crowd.client.PlaceView;
|
||||
import com.threerings.crowd.data.BodyObject;
|
||||
import com.threerings.crowd.data.PlaceConfig;
|
||||
@@ -44,22 +46,21 @@ import com.threerings.ezgame.data.EZGameObject;
|
||||
public class EZGameController extends GameController
|
||||
implements TurnGameController
|
||||
{
|
||||
/**
|
||||
*/
|
||||
public function EZGameController ()
|
||||
{
|
||||
addDelegate(_turnDelegate = new TurnGameControllerDelegate(this));
|
||||
}
|
||||
|
||||
/**
|
||||
* This is called by the GameControlBackend once it has initialized
|
||||
* and made contact with usercode.
|
||||
* This is called by the GameControlBackend once it has initialized and made contact with
|
||||
* usercode.
|
||||
*/
|
||||
public function userCodeIsConnected () :void
|
||||
{
|
||||
playerReady();
|
||||
}
|
||||
|
||||
// from PlaceController
|
||||
override public function willEnterPlace (plobj :PlaceObject) :void
|
||||
{
|
||||
_ezObj = (plobj as EZGameObject);
|
||||
@@ -67,6 +68,7 @@ public class EZGameController extends GameController
|
||||
super.willEnterPlace(plobj);
|
||||
}
|
||||
|
||||
// from PlaceController
|
||||
override public function didLeavePlace (plobj :PlaceObject) :void
|
||||
{
|
||||
super.didLeavePlace(plobj);
|
||||
@@ -80,13 +82,24 @@ public class EZGameController extends GameController
|
||||
_panel.backend.turnDidChange();
|
||||
}
|
||||
|
||||
// from GameController
|
||||
override public function attributeChanged (event :AttributeChangedEvent) :void
|
||||
{
|
||||
var name :String = event.getName();
|
||||
if (EZGameObject.CONTROLLER_OID == name) {
|
||||
_panel.backend.controlDidChange();
|
||||
} else {
|
||||
super.attributeChanged(event);
|
||||
}
|
||||
}
|
||||
|
||||
// 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
|
||||
// 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);
|
||||
var bobj :BodyObject = (_ctx.getClient().getClientObject() as BodyObject);
|
||||
if (_gobj.getPlayerIndex(bobj.getVisibleName()) != -1) {
|
||||
super.playerReady();
|
||||
}
|
||||
@@ -96,36 +109,28 @@ public class EZGameController extends GameController
|
||||
}
|
||||
}
|
||||
|
||||
// from GameController
|
||||
override protected function gameDidStart () :void
|
||||
{
|
||||
super.gameDidStart();
|
||||
|
||||
_panel.backend.gameDidStart();
|
||||
}
|
||||
|
||||
// from GameController
|
||||
override protected function gameDidEnd () :void
|
||||
{
|
||||
super.gameDidEnd();
|
||||
|
||||
_panel.backend.gameDidEnd();
|
||||
}
|
||||
|
||||
// from PlaceController
|
||||
override protected function createPlaceView (ctx :CrowdContext) :PlaceView
|
||||
{
|
||||
return new EZGamePanel(ctx, this);
|
||||
}
|
||||
|
||||
override protected function didInit () :void
|
||||
{
|
||||
super.didInit();
|
||||
// retain a casted reference to our panel
|
||||
_panel = (_view as EZGamePanel);
|
||||
return _panel = new EZGamePanel(ctx, this);
|
||||
}
|
||||
|
||||
protected var _ezObj :EZGameObject;
|
||||
|
||||
protected var _turnDelegate :TurnGameControllerDelegate;
|
||||
|
||||
protected var _panel :EZGamePanel;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user