Revamped EZGame to work over the security boundary.
Now, instead of implementing "Game" and having the EZGame object assigned to you, you create it yourself using your top-level component. You must register listeners manually, and keyboard focus is currently an issue that I'm working on. git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@137 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
@@ -2,6 +2,7 @@ package com.threerings.ezgame.client {
|
||||
|
||||
import flash.display.DisplayObject;
|
||||
import flash.display.DisplayObjectContainer;
|
||||
import flash.display.Loader;
|
||||
|
||||
import flash.events.Event;
|
||||
|
||||
@@ -26,106 +27,48 @@ import com.threerings.crowd.util.CrowdContext;
|
||||
import com.threerings.ezgame.data.EZGameConfig;
|
||||
import com.threerings.ezgame.data.EZGameObject;
|
||||
|
||||
import com.threerings.ezgame.Game;
|
||||
|
||||
public class EZGamePanel extends VBox
|
||||
implements PlaceView
|
||||
{
|
||||
/** The game object backend. */
|
||||
public var backend :GameControlBackend;
|
||||
|
||||
public function EZGamePanel (ctx :CrowdContext, ctrl :EZGameController)
|
||||
{
|
||||
_ctx = ctx;
|
||||
_ctrl = ctrl;
|
||||
|
||||
// add a listener so that we hear about all new children
|
||||
addEventListener(Event.ADDED, childAdded);
|
||||
addEventListener(Event.REMOVED, childRemoved);
|
||||
|
||||
var cfg :EZGameConfig = (ctrl.getPlaceConfig() as EZGameConfig);
|
||||
_gameView = new MediaContainer(cfg.configData); // TODO
|
||||
addChild(_gameView);
|
||||
|
||||
//addChild(new ChatDisplayBox(ctx));
|
||||
}
|
||||
|
||||
// from PlaceView
|
||||
public function willEnterPlace (plobj :PlaceObject) :void
|
||||
{
|
||||
// don't start notifying anything of the game until we've
|
||||
// notified the game manager that we're in the game
|
||||
// (done in GameController, and it uses callLater, so we do it twice!)
|
||||
_ctx.getClient().callLater(function () :void {
|
||||
_ctx.getClient().callLater(function () :void {
|
||||
_ezObj = (plobj as EZGameObject);
|
||||
var cfg :EZGameConfig = (_ctrl.getPlaceConfig() as EZGameConfig);
|
||||
|
||||
notifyOfGame(_gameView);
|
||||
});
|
||||
});
|
||||
_ezObj = (plobj as EZGameObject);
|
||||
backend = new GameControlBackend(_ctx, _ezObj);
|
||||
|
||||
_gameView = new GameContainer(cfg.configData); // TODO
|
||||
_gameView.tabEnabled = true;
|
||||
backend.setSharedEvents(
|
||||
Loader(_gameView.getMedia()).contentLoaderInfo.sharedEvents);
|
||||
addChild(_gameView);
|
||||
}
|
||||
|
||||
// from PlaceView
|
||||
public function didLeavePlace (plobj :PlaceObject) :void
|
||||
{
|
||||
removeListeners(_gameView);
|
||||
_ezObj = null;
|
||||
}
|
||||
_gameView.shutdown(true);
|
||||
removeChild(_gameView);
|
||||
|
||||
/**
|
||||
* Handle ADDED events.
|
||||
*/
|
||||
protected function childAdded (event :Event) :void
|
||||
{
|
||||
if (_ezObj != null) {
|
||||
notifyOfGame(event.target as DisplayObject);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle REMOVED events.
|
||||
*/
|
||||
protected function childRemoved (event :Event) :void
|
||||
{
|
||||
if (_ezObj != null) {
|
||||
removeListeners(event.target as DisplayObject);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Find any children of the specified object that implement
|
||||
* com.metasoy.game.Game and provide them with the GameObject.
|
||||
*/
|
||||
protected function notifyOfGame (root :DisplayObject) :void
|
||||
{
|
||||
DisplayUtil.walkDisplayObjects(root,
|
||||
function (disp :DisplayObject) :void
|
||||
{
|
||||
if (disp is Game) {
|
||||
// only notify the Game if we haven't seen it before
|
||||
if (null == _seenGames[disp]) {
|
||||
(disp as Game).setGameObject(_ctrl.gameObjImpl);
|
||||
_seenGames[disp] = true;
|
||||
}
|
||||
}
|
||||
// always check to see if it's a listener
|
||||
_ctrl.gameObjImpl.registerListener(disp);
|
||||
});
|
||||
}
|
||||
|
||||
protected function removeListeners (root :DisplayObject) :void
|
||||
{
|
||||
DisplayUtil.walkDisplayObjects(root,
|
||||
function (disp :DisplayObject) :void
|
||||
{
|
||||
_ctrl.gameObjImpl.unregisterListener(disp);
|
||||
});
|
||||
backend.shutdown();
|
||||
}
|
||||
|
||||
protected var _ctx :CrowdContext;
|
||||
protected var _ctrl :EZGameController;
|
||||
|
||||
protected var _gameView :MediaContainer;
|
||||
|
||||
/** A weak-key hash of the Game interfaces we've already seen. */
|
||||
protected var _seenGames :Dictionary = new Dictionary(true);
|
||||
protected var _gameView :GameContainer;
|
||||
|
||||
protected var _ezObj :EZGameObject;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user