replaced NotificationCenter with Nc

This commit is contained in:
logsol 2014-03-01 11:07:23 +01:00
parent da913c4709
commit 672a46efa8
35 changed files with 160 additions and 161 deletions

View file

@ -5,7 +5,7 @@ define([
"Lib/Utilities/NotificationCenter"
],
function (Parent, DomController, Settings, NotificationCenter) {
function (Parent, DomController, Settings, Nc) {
function MouseInput() {
Parent.call(this);
@ -37,7 +37,7 @@ function (Parent, DomController, Settings, NotificationCenter) {
var x = (((e.clientX - this.offsetLeft) / Settings.STAGE_WIDTH) * 2) - 1;
var y = (((Settings.STAGE_HEIGHT - (e.clientY - this.offsetTop)) / Settings.STAGE_HEIGHT) * 2) -1;
NotificationCenter.trigger("input/onHandActionRequest", x, y);
Nc.trigger("input/onHandActionRequest", x, y);
}
};

View file

@ -2,7 +2,7 @@ define([
"Lib/Utilities/NotificationCenter"
],
function (NotificationCenter) {
function (Nc) {
function XyInput() {
this.x = null;
@ -12,7 +12,7 @@ function (NotificationCenter) {
XyInput.prototype.onXyChange = function(x, y) {
this.x = x;
this.y = y;
NotificationCenter.trigger('input/onXyChange', x, y);
Nc.trigger('input/onXyChange', x, y);
}
return XyInput;

View file

@ -5,7 +5,7 @@ define([
"Lib/Utilities/NotificationCenter"
],
function (Parent, KeyboardInput, MouseInput, NotificationCenter) {
function (Parent, KeyboardInput, MouseInput, Nc) {
function PlayerController (me) {
@ -14,8 +14,8 @@ function (Parent, KeyboardInput, MouseInput, NotificationCenter) {
this.keyboardInput = new KeyboardInput(this);
this.xyInput = new MouseInput(this);
NotificationCenter.on("input/onXyChange", this.setXY, this);
NotificationCenter.on("input/onHandActionRequest", this.handActionRequest, this);
Nc.on("input/onXyChange", this.setXY, this);
Nc.on("input/onHandActionRequest", this.handActionRequest, this);
var keys = {
w:87,
@ -64,33 +64,33 @@ function (Parent, KeyboardInput, MouseInput, NotificationCenter) {
PlayerController.prototype.moveLeft = function () {
Parent.prototype.moveLeft.call(this);
NotificationCenter.trigger('sendGameCommand', 'moveLeft');
Nc.trigger('sendGameCommand', 'moveLeft');
}
PlayerController.prototype.moveRight = function () {
Parent.prototype.moveRight.call(this);
NotificationCenter.trigger('sendGameCommand', 'moveRight');
Nc.trigger('sendGameCommand', 'moveRight');
}
PlayerController.prototype.stop = function () {
Parent.prototype.stop.call(this);
NotificationCenter.trigger('sendGameCommand', 'stop');
Nc.trigger('sendGameCommand', 'stop');
}
PlayerController.prototype.jump = function () {
Parent.prototype.jump.call(this);
NotificationCenter.trigger('sendGameCommand', 'jump');
Nc.trigger('sendGameCommand', 'jump');
}
PlayerController.prototype.jumpStop = function () {
Parent.prototype.jumpStop.call(this);
NotificationCenter.trigger('sendGameCommand', 'jumpStop');
Nc.trigger('sendGameCommand', 'jumpStop');
}
PlayerController.prototype.setXY = function(x, y) {
var options = {x:x, y:y};
Parent.prototype.lookAt.call(this, options);
NotificationCenter.trigger('sendGameCommand', 'lookAt', options);
Nc.trigger('sendGameCommand', 'lookAt', options);
};
PlayerController.prototype.handActionLeft = function() {
@ -102,20 +102,20 @@ function (Parent, KeyboardInput, MouseInput, NotificationCenter) {
};
PlayerController.prototype.suicide = function() {
NotificationCenter.trigger("sendGameCommand", "suicide");
Nc.trigger("sendGameCommand", "suicide");
};
PlayerController.prototype.handActionRequest = function(x, y) {
var options = {x:x, y:y};
NotificationCenter.trigger("sendGameCommand", "handActionRequest", options);
Nc.trigger("sendGameCommand", "handActionRequest", options);
};
PlayerController.prototype.showInfo = function() {
NotificationCenter.trigger("game/toggleInfo", true);
Nc.trigger("game/toggleInfo", true);
};
PlayerController.prototype.hideInfo = function() {
NotificationCenter.trigger("game/toggleInfo", false);
Nc.trigger("game/toggleInfo", false);
};

View file

@ -12,13 +12,13 @@ define([
"Game/Client/View/DomController"
],
function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, NotificationCenter, requestAnimFrame, Settings, GameObject, Doll, DomController) {
function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, requestAnimFrame, Settings, GameObject, Doll, DomController) {
function GameController () {
this.view = ViewManager.createView();
this.me = null;
NotificationCenter.on("game/toggleInfo", this.toggleInfo, this);
Nc.on("game/toggleInfo", this.toggleInfo, this);
Parent.call(this);
}

View file

@ -5,7 +5,7 @@ define([
"Lib/Utilities/Exception"
],
function (Parent, Settings, NotificationCenter, Exception) {
function (Parent, Settings, Nc, Exception) {
function Doll(physicsEngine, uid, player) {
this.animationDef = {
@ -35,12 +35,12 @@ function (Parent, Settings, NotificationCenter, Exception) {
if(!state) throw new Exception("action state is undefined");
if(this.animatedMeshes[this.actionState]) {
NotificationCenter.trigger("view/updateMesh", this.animatedMeshes[this.actionState], { visible: false });
Nc.trigger("view/updateMesh", this.animatedMeshes[this.actionState], { visible: false });
}
Parent.prototype.setActionState.call(this, state);
NotificationCenter.trigger("view/updateMesh", this.animatedMeshes[this.actionState], { visible: true });
Nc.trigger("view/updateMesh", this.animatedMeshes[this.actionState], { visible: true });
}
Doll.prototype.createMesh = function() {
@ -73,10 +73,10 @@ function (Parent, Settings, NotificationCenter, Exception) {
var callback = function(mesh) {
self.animatedMeshes[key] = mesh;
NotificationCenter.trigger("view/addMesh", mesh);
Nc.trigger("view/addMesh", mesh);
};
NotificationCenter.trigger("view/createAnimatedMesh", texturePaths, callback, {
Nc.trigger("view/createAnimatedMesh", texturePaths, callback, {
visible: false,
pivot: {
x: 35/2,
@ -92,9 +92,9 @@ function (Parent, Settings, NotificationCenter, Exception) {
var texturePath = Settings.GRAPHICS_PATH + "Characters/Chuck/head.png";
var callback = function (mesh) {
self.headMesh = mesh;
NotificationCenter.trigger("view/addMesh", mesh);
Nc.trigger("view/addMesh", mesh);
}
NotificationCenter.trigger("view/createMesh", texturePath, callback, {
Nc.trigger("view/createMesh", texturePath, callback, {
pivot: {
x: 5,
y: 12
@ -112,7 +112,7 @@ function (Parent, Settings, NotificationCenter, Exception) {
if(oldLookDirection != this.lookDirection) {
for(var key in this.animatedMeshes) {
NotificationCenter.trigger("view/updateMesh",
Nc.trigger("view/updateMesh",
this.animatedMeshes[key],
{
xScale: this.lookDirection
@ -123,7 +123,7 @@ function (Parent, Settings, NotificationCenter, Exception) {
var angle = Math.atan2(this.lookAtXY.x, this.lookAtXY.y) / 2 - 0.7855 * this.lookDirection; // 0.7855 = 45°
NotificationCenter.trigger("view/updateMesh",
Nc.trigger("view/updateMesh",
this.headMesh,
{
xScale: this.lookDirection,
@ -135,17 +135,17 @@ function (Parent, Settings, NotificationCenter, Exception) {
Doll.prototype.destroy = function () {
for (var key in this.animatedMeshes) {
NotificationCenter.trigger("view/removeMesh", this.animatedMeshes[key]);
Nc.trigger("view/removeMesh", this.animatedMeshes[key]);
}
NotificationCenter.trigger("view/removeMesh", this.headMesh);
Nc.trigger("view/removeMesh", this.headMesh);
Parent.prototype.destroy.call(this);
}
Doll.prototype.render = function() {
if(this.actionState) {
NotificationCenter.trigger("view/updateMesh",
Nc.trigger("view/updateMesh",
this.animatedMeshes[this.actionState],
{
x: this.body.GetPosition().x * Settings.RATIO,
@ -154,7 +154,7 @@ function (Parent, Settings, NotificationCenter, Exception) {
}
);
NotificationCenter.trigger("view/updateMesh",
Nc.trigger("view/updateMesh",
this.headMesh,
{
x: this.body.GetPosition().x * Settings.RATIO,

View file

@ -4,7 +4,7 @@ define([
"Lib/Utilities/NotificationCenter"
],
function (Parent, Exception, NotificationCenter) {
function (Parent, Exception, Nc) {
function GameObject(physicsEngine, uid) {
Parent.call(this, physicsEngine, uid);

View file

@ -4,7 +4,7 @@ define([
"Lib/Utilities/NotificationCenter"
],
function (Parent, Settings, NotificationCenter) {
function (Parent, Settings, Nc) {
function Item(physicsEngine, uid, options) {
Parent.call(this, physicsEngine, uid, options);
@ -22,10 +22,10 @@ function (Parent, Settings, NotificationCenter) {
var callback = function(mesh) {
self.mesh = mesh;
NotificationCenter.trigger("view/addMesh", mesh);
Nc.trigger("view/addMesh", mesh);
}
NotificationCenter.trigger("view/createMesh",
Nc.trigger("view/createMesh",
texturePath,
callback,
{
@ -40,13 +40,13 @@ function (Parent, Settings, NotificationCenter) {
};
Item.prototype.destroy = function() {
NotificationCenter.trigger("view/removeMesh", this.mesh);
Nc.trigger("view/removeMesh", this.mesh);
Parent.prototype.destroy.call(this);
};
Item.prototype.render = function() {
NotificationCenter.trigger("view/updateMesh",
Nc.trigger("view/updateMesh",
this.mesh,
{
x: this.body.GetPosition().x * Settings.RATIO,
@ -62,7 +62,7 @@ function (Parent, Settings, NotificationCenter) {
Parent.prototype.flip.call(this, direction);
if(oldFlipDirection != direction) {
NotificationCenter.trigger("view/updateMesh",
Nc.trigger("view/updateMesh",
this.mesh,
{
xScale: direction

View file

@ -5,7 +5,7 @@ define([
"Lib/Utilities/NotificationCenter"
],
function (Parent, CoreItem, Settings, NotificationCenter) {
function (Parent, CoreItem, Settings, Nc) {
function RagDoll(physicsEngine, uid, options) {
this.limbMeshes = {};
@ -37,10 +37,10 @@ function (Parent, CoreItem, Settings, NotificationCenter) {
self.limbMeshes[name] = mesh;
}
NotificationCenter.trigger("view/addMesh", mesh);
Nc.trigger("view/addMesh", mesh);
}
NotificationCenter.trigger("view/createMesh",
Nc.trigger("view/createMesh",
texturePath + name + ".png",
callback,
{
@ -60,7 +60,7 @@ function (Parent, CoreItem, Settings, NotificationCenter) {
if(this.limbs) {
for(var name in this.limbMeshes) {
if(this.limbs[name]) {
NotificationCenter.trigger("view/updateMesh",
Nc.trigger("view/updateMesh",
this.limbMeshes[name],
{
x: this.limbs[name].GetPosition().x * Settings.RATIO,
@ -80,7 +80,7 @@ function (Parent, CoreItem, Settings, NotificationCenter) {
CoreItem.prototype.flip.call(this, direction);
if(oldFlipDirection != direction) {
NotificationCenter.trigger("view/updateMesh",
Nc.trigger("view/updateMesh",
this.mesh,
{
xScale: direction
@ -88,7 +88,7 @@ function (Parent, CoreItem, Settings, NotificationCenter) {
);
for (var name in this.limbMeshes) {
NotificationCenter.trigger("view/updateMesh",
Nc.trigger("view/updateMesh",
this.limbMeshes[name],
{
xScale: direction
@ -100,7 +100,7 @@ function (Parent, CoreItem, Settings, NotificationCenter) {
RagDoll.prototype.destroy = function() {
for (var name in this.limbMeshes) {
NotificationCenter.trigger("view/removeMesh", this.limbMeshes[name]);
Nc.trigger("view/removeMesh", this.limbMeshes[name]);
};
Parent.prototype.destroy.call(this);

View file

@ -4,7 +4,7 @@ define([
"Lib/Utilities/NotificationCenter"
],
function (Parent, Settings, NotificationCenter) {
function (Parent, Settings, Nc) {
function Tile(physicsEngine, uid, options) {
Parent.call(this, physicsEngine, uid, options);
@ -27,10 +27,10 @@ function (Parent, Settings, NotificationCenter) {
var callback = function(mesh) {
self.mesh = mesh;
NotificationCenter.trigger("view/addMesh", mesh);
Nc.trigger("view/addMesh", mesh);
}
NotificationCenter.trigger("view/createMesh",
Nc.trigger("view/createMesh",
texturePath,
callback,
{
@ -45,13 +45,13 @@ function (Parent, Settings, NotificationCenter) {
};
Tile.prototype.destroy = function() {
NotificationCenter.trigger("view/removeMesh", this.mesh);
Nc.trigger("view/removeMesh", this.mesh);
Parent.prototype.destroy.call(this);
};
Tile.prototype.render = function() {
NotificationCenter.trigger("view/updateMesh",
Nc.trigger("view/updateMesh",
this.mesh,
{
x: this.body.GetPosition().x * Settings.RATIO,

View file

@ -5,7 +5,7 @@ define([
"Lib/Vendor/Pixi"
],
function (Parent, Settings, NotificationCenter, PIXI) {
function (Parent, Settings, Nc, PIXI) {
function Level (uid, engine, gameObjects) {
Parent.call(this, uid, engine, gameObjects);
@ -39,7 +39,7 @@ function (Parent, Settings, NotificationCenter, PIXI) {
loader.onComplete = function() { callback(levelData); };
loader.onProgress = function() {
var progress = parseInt(100 / numPaths * ++count, 10) + 1;
NotificationCenter.trigger("view/updateLoader", progress);
Nc.trigger("view/updateLoader", progress);
}
loader.load();
};

View file

@ -7,7 +7,7 @@ define([
"Game/Client/View/DomController"
],
function (ProtocolHelper, GameController, User, NotificationCenter, Settings, DomController) {
function (ProtocolHelper, GameController, User, Nc, Settings, DomController) {
function Networker (socketLink) {
this.socketLink = socketLink;
@ -26,8 +26,8 @@ function (ProtocolHelper, GameController, User, NotificationCenter, Settings, Do
ProtocolHelper.applyCommand(message, self);
});
NotificationCenter.on("sendGameCommand", this.sendGameCommand, this);
NotificationCenter.on("game/level/loaded", this.onLevelLoaded, this);
Nc.on("sendGameCommand", this.sendGameCommand, this);
Nc.on("game/level/loaded", this.onLevelLoaded, this);
}
// Socket callbacks

View file

@ -6,14 +6,14 @@ define([
"Lib/Utilities/NotificationCenter"
],
function (Parent, Settings, DomController, Box2D, NotificationCenter) {
function (Parent, Settings, DomController, Box2D, Nc) {
function Engine () {
Parent.call(this);
this.debugMode = false;
NotificationCenter.on("view/toggleDebugMode", this.onToggleDebugMode, this);
Nc.on("view/toggleDebugMode", this.onToggleDebugMode, this);
}
Engine.prototype = Object.create(Parent.prototype);

View file

@ -4,7 +4,7 @@ define([
"Game/Config/Settings"
],
function (Parent, NotificationCenter, Settings) {
function (Parent, Nc, Settings) {
function Player(id, physicsEngine) {
Parent.call(this, id, physicsEngine);
@ -41,7 +41,7 @@ function (Parent, NotificationCenter, Settings) {
var callback = function(playerInfoView) {
self.playerInfoView = playerInfoView;
}
NotificationCenter.trigger("view/createAndAddPlayerInfo", callback, options);
Nc.trigger("view/createAndAddPlayerInfo", callback, options);
};
Player.prototype.onHealthChange = function() {
@ -69,15 +69,15 @@ function (Parent, NotificationCenter, Settings) {
healthFactor: this.stats.health / 100,
visible: this.playerInfoViewVisible
};
NotificationCenter.trigger("view/updatePlayerInfo", this.playerInfoView, options);
Nc.trigger("view/updatePlayerInfo", this.playerInfoView, options);
this.playerInfoViewVisibleTimeout = setTimeout(function() {
self.playerInfoViewVisible = false;
NotificationCenter.trigger("view/updatePlayerInfo", self.playerInfoView, {visible: self.playerInfoViewVisible});
Nc.trigger("view/updatePlayerInfo", self.playerInfoView, {visible: self.playerInfoViewVisible});
}, Settings.HEALTH_DISPLAY_TIME * 1000);
} else {
NotificationCenter.trigger("view/updatePlayerInfo", this.playerInfoView, {visible: this.playerInfoViewVisible});
Nc.trigger("view/updatePlayerInfo", this.playerInfoView, {visible: this.playerInfoViewVisible});
}
};
@ -92,13 +92,13 @@ function (Parent, NotificationCenter, Settings) {
x: position.x * Settings.RATIO,
y: position.y * Settings.RATIO,
}
NotificationCenter.trigger("view/updatePlayerInfo", this.playerInfoView, options);
Nc.trigger("view/updatePlayerInfo", this.playerInfoView, options);
}
};
Player.prototype.destroy = function() {
Parent.prototype.destroy.call(this);
NotificationCenter.trigger("view/removePlayerInfo", this.playerInfoView);
Nc.trigger("view/removePlayerInfo", this.playerInfoView);
};
return Player;

View file

@ -5,7 +5,7 @@ define([
"Lib/Vendor/Screenfull"
],
function (Settings, NotificationCenter, Stats, Screenfull) {
function (Settings, Nc, Stats, Screenfull) {
function DomController() {
this.canvas = null;
@ -13,7 +13,7 @@ function (Settings, NotificationCenter, Stats, Screenfull) {
this.stats = null;
this.ping = null;
NotificationCenter.on("view/ready", this.initDevTools, this);
Nc.on("view/ready", this.initDevTools, this);
}
DomController.prototype.initDevTools = function() {
@ -39,7 +39,7 @@ function (Settings, NotificationCenter, Stats, Screenfull) {
window.onresize = function() {
if(Screenfull.enabled) {
NotificationCenter.trigger("view/fullscreenChange", Screenfull.isFullscreen);
Nc.trigger("view/fullscreenChange", Screenfull.isFullscreen);
}
}
@ -71,7 +71,7 @@ function (Settings, NotificationCenter, Stats, Screenfull) {
var checkbox = document.createElement("input");
checkbox.type = "checkbox";
checkbox.onclick = function(e) {
NotificationCenter.trigger("view/toggleDebugMode", e.target.checked);
Nc.trigger("view/toggleDebugMode", e.target.checked);
self.getDebugCanvas().style.display = e.target.checked ? "" : "none";
}
label.appendChild(checkbox);

View file

@ -7,7 +7,7 @@ define([
"Lib/Utilities/NotificationCenter"
],
function (Settings, Exception, AbstractView, PixiView, NotificationCenter) {
function (Settings, Exception, AbstractView, PixiView, Nc) {
var ViewManager = {};
@ -36,7 +36,7 @@ function (Settings, Exception, AbstractView, PixiView, NotificationCenter) {
throw new Exception("In the view", Settings.VIEW_CONTROLLER + 'View', "this.setCanvas(canvas) has not been called with a valid HTMLCanvasElement!");
}
NotificationCenter.trigger("view/ready", view);
Nc.trigger("view/ready", view);
return view;
}

View file

@ -5,29 +5,29 @@ define([
"Lib/Utilities/NotificationCenter"
],
function (DomController, Settings, Exception, NotificationCenter) {
function (DomController, Settings, Exception, Nc) {
function AbstractView () {
this.me = null;
this.canvas = null;
this.debugMode = false;
NotificationCenter.on("view/createMesh", this.createMesh, this);
NotificationCenter.on("view/createAnimatedMesh", this.createAnimatedMesh, this);
NotificationCenter.on("view/addMesh", this.addMesh, this);
NotificationCenter.on("view/removeMesh", this.removeMesh, this);
NotificationCenter.on("view/updateMesh", this.updateMesh, this);
Nc.on("view/createMesh", this.createMesh, this);
Nc.on("view/createAnimatedMesh", this.createAnimatedMesh, this);
Nc.on("view/addMesh", this.addMesh, this);
Nc.on("view/removeMesh", this.removeMesh, this);
Nc.on("view/updateMesh", this.updateMesh, this);
NotificationCenter.on("view/fullscreenChange", this.onFullscreenChange, this);
NotificationCenter.on("view/toggleDebugMode", this.onToggleDebugMode, this);
Nc.on("view/fullscreenChange", this.onFullscreenChange, this);
Nc.on("view/toggleDebugMode", this.onToggleDebugMode, this);
NotificationCenter.on("view/toggleInfo", this.onToggleInfo, this);
Nc.on("view/toggleInfo", this.onToggleInfo, this);
NotificationCenter.on("view/createAndAddPlayerInfo", this.onCreateAndAddPlayerInfo, this);
NotificationCenter.on("view/updatePlayerInfo", this.onUpdatePlayerInfo, this);
NotificationCenter.on("view/removePlayerInfo", this.onRemovePlayerInfo, this);
Nc.on("view/createAndAddPlayerInfo", this.onCreateAndAddPlayerInfo, this);
Nc.on("view/updatePlayerInfo", this.onUpdatePlayerInfo, this);
Nc.on("view/removePlayerInfo", this.onRemovePlayerInfo, this);
NotificationCenter.on("view/updateLoader", this.onUpdateLoader, this);
Nc.on("view/updateLoader", this.onUpdateLoader, this);
}
AbstractView.prototype.isWebGlEnabled = function () {

View file

@ -6,7 +6,7 @@ define([
"Lib/Utilities/NotificationCenter"
],
function (Parent, DomController, PIXI, Settings, NotificationCenter) {
function (Parent, DomController, PIXI, Settings, Nc) {
function PixiView () {

View file

@ -5,7 +5,7 @@ define([
"Lib/Utilities/NotificationCenter"
],
function (PhysicsEngine, TiledLevel, Player, NotificationCenter) {
function (PhysicsEngine, TiledLevel, Player, Nc) {
function GameController () {
this.players = {};
@ -16,10 +16,10 @@ function (PhysicsEngine, TiledLevel, Player, NotificationCenter) {
this.physicsEngine = new PhysicsEngine();
this.physicsEngine.setCollisionDetector();
NotificationCenter.on("game/level/loaded", this.onLevelLoaded, this);
Nc.on("game/level/loaded", this.onLevelLoaded, this);
NotificationCenter.on("game/object/add", this.onGameObjectAdd, this);
NotificationCenter.on("game/object/remove", this.onGameObjectRemove, this);
Nc.on("game/object/add", this.onGameObjectAdd, this);
Nc.on("game/object/remove", this.onGameObjectRemove, this);
this.update();
}

View file

@ -5,7 +5,7 @@ define([
"Lib/Utilities/NotificationCenter"
],
function (Parent, Box2D, Settings, NotificationCenter) {
function (Parent, Box2D, Settings, Nc) {
function RagDoll(physicsEngine, uid, options) {
@ -163,7 +163,7 @@ function (Parent, Box2D, Settings, NotificationCenter) {
);
NotificationCenter.trigger("game/object/add", 'animated', this);
Nc.trigger("game/object/add", 'animated', this);
}
RagDoll.prototype = Object.create(Parent.prototype);
@ -362,7 +362,7 @@ function (Parent, Box2D, Settings, NotificationCenter) {
};
RagDoll.prototype.destroy = function() {
NotificationCenter.trigger("game/object/remove", 'animated', this);
Nc.trigger("game/object/remove", 'animated', this);
var world = this.body.GetWorld();
Parent.prototype.destroy.call(this);

View file

@ -9,7 +9,7 @@ define([
"Game/" + GLOBALS.context + "/GameObjects/Items/Skateboard",
"Game/" + GLOBALS.context + "/GameObjects/Items/RagDoll"
], function (Settings, Box2D, NotificationCenter, Exception, CollisionDetector, Tile, Item, Skateboard, RagDoll) {
], function (Settings, Box2D, Nc, Exception, CollisionDetector, Tile, Item, Skateboard, RagDoll) {
function Level (uid, engine, gameObjects) {
this.uid = uid;
@ -28,7 +28,7 @@ define([
self.createTiles();
self.createItems();
self.isLoaded = true;
NotificationCenter.trigger("game/level/loaded");
Nc.trigger("game/level/loaded");
});
}
@ -67,7 +67,7 @@ define([
var options = items[i];
var uid = "item-" + i;
var item = this.createItem(uid, options);
this.gameObjects.animated.push(item); // FIXME: use NotificationCenter
this.gameObjects.animated.push(item); // FIXME: use Nc
};
};

View file

@ -5,7 +5,7 @@ define([
"Lib/Utilities/NotificationCenter"
],
function (Settings, Box2D, CollisionDetector, NotificationCenter) {
function (Settings, Box2D, CollisionDetector, Nc) {
function Engine () {
this.world = new Box2D.Dynamics.b2World(
@ -17,7 +17,7 @@ function (Settings, Box2D, CollisionDetector, NotificationCenter) {
this.lastStep = Date.now();
this.worldQueue = [];
NotificationCenter.on("engine/addToWorldQueue", this.addToWorldQueue, this);
Nc.on("engine/addToWorldQueue", this.addToWorldQueue, this);
}
Engine.prototype.getWorld = function () {

View file

@ -8,7 +8,7 @@ define([
],
function (Doll, Settings, NotificationCenter, Exception, SpectatorDoll, RagDoll) {
function (Doll, Settings, Nc, Exception, SpectatorDoll, RagDoll) {
function Player (id, physicsEngine) {
this.stats = {
@ -39,7 +39,7 @@ function (Doll, Settings, NotificationCenter, Exception, SpectatorDoll, RagDoll)
this.doll = new Doll(this.physicsEngine, "doll-" + this.id, this);
this.doll.spawn(x, y);
this.isSpawned = true;
NotificationCenter.trigger("game/object/add", 'animated', this.doll);
Nc.trigger("game/object/add", 'animated', this.doll);
}
Player.prototype.getPosition = function () {
@ -119,14 +119,14 @@ function (Doll, Settings, NotificationCenter, Exception, SpectatorDoll, RagDoll)
this.isSpawned = false;
NotificationCenter.trigger("game/object/remove", 'animated', this.doll);
Nc.trigger("game/object/remove", 'animated', this.doll);
this.doll.destroy();
this.doll = null;
this.ragDoll = ragDoll;
NotificationCenter.trigger("player/killed", this);
Nc.trigger("player/killed", this);
};
Player.prototype.update = function () {

View file

@ -7,7 +7,7 @@
"Game/Config/Settings"
],
function (GameController, NotificationCenter, User, ProtocolHelper, Options, Settings) {
function (GameController, Nc, User, ProtocolHelper, Options, Settings) {
function Channel (pipeToLobby, name, options) {
@ -24,15 +24,15 @@
this.gameController = new GameController(this);
NotificationCenter.on('channel/controlCommand', function (message) {
Nc.on('channel/controlCommand', function (message) {
ProtocolHelper.applyCommand(message.data, self);
});
NotificationCenter.on('broadcastControlCommand', this.broadcastControlCommand, this);
NotificationCenter.on('broadcastControlCommandExcept', this.broadcastControlCommandExcept, this);
Nc.on('broadcastControlCommand', this.broadcastControlCommand, this);
Nc.on('broadcastControlCommandExcept', this.broadcastControlCommandExcept, this);
NotificationCenter.on('broadcastGameCommand', this.broadcastGameCommand, this);
NotificationCenter.on('broadcastGameCommandExcept', this.broadcastGameCommandExcept, this);
Nc.on('broadcastGameCommand', this.broadcastGameCommand, this);
Nc.on('broadcastGameCommandExcept', this.broadcastGameCommandExcept, this);
console.checkpoint('channel ' + name + ' created');
}
@ -48,9 +48,9 @@
var self = this;
if(!this.gameController.level || !this.gameController.level.isLoaded) {
var token = NotificationCenter.on("game/level/loaded", function() {
var token = Nc.on("game/level/loaded", function() {
self.sendJoinSuccess(userId);
NotificationCenter.off(token);
Nc.off(token);
});
} else {
self.sendJoinSuccess(userId);
@ -75,14 +75,14 @@
levelUid: levelUid
};
NotificationCenter.trigger('user/' + user.id + "/joinSuccess", options);
NotificationCenter.trigger('user/joined', user);
Nc.trigger('user/' + user.id + "/joinSuccess", options);
Nc.trigger('user/joined', user);
};
Channel.prototype.onReleaseUser = function (userId) {
var user = this.users[userId];
this.broadcastControlCommandExcept("userLeft", user.id, user);
NotificationCenter.trigger('user/left', user);
Nc.trigger('user/left', user);
delete this.users[user.id];
}

View file

@ -4,7 +4,7 @@ define([
"Lib/Utilities/Protocol/Parser"
],
function(Parent, NotificationCenter, Parser) {
function(Parent, Nc, Parser) {
function PlayerController(player) {

View file

@ -12,7 +12,7 @@ define([
"Game/Server/GameObjects/Items/RagDoll"
],
function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, NotificationCenter, Box2D, Player, GameObject, Doll, RagDoll) {
function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, Nc, Box2D, Player, GameObject, Doll, RagDoll) {
function GameController (channel) {
@ -20,11 +20,11 @@ function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, N
Parent.call(this);
NotificationCenter.on('user/joined', this.onUserJoined, this);
NotificationCenter.on('user/left', this.onUserLeft, this); // FIXME: refactor this.userLeft -> this.onUserLeft, even in core and client
NotificationCenter.on('user/resetLevel', this.onResetLevel, this);
NotificationCenter.on('user/clientReady', this.onClientReady, this);
NotificationCenter.on('player/killed', this.onPlayerKilled, this);
Nc.on('user/joined', this.onUserJoined, this);
Nc.on('user/left', this.onUserLeft, this); // FIXME: refactor this.userLeft -> this.onUserLeft, even in core and client
Nc.on('user/resetLevel', this.onResetLevel, this);
Nc.on('user/clientReady', this.onClientReady, this);
Nc.on('player/killed', this.onPlayerKilled, this);
console.checkpoint('starting game controller for channel ' + channel.name);
@ -84,7 +84,7 @@ function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, N
y: spawnPoint.y
};
NotificationCenter.trigger("broadcastGameCommand", "spawnPlayer", options);
Nc.trigger("broadcastGameCommand", "spawnPlayer", options);
}, respawnTime * 1000);
};
@ -102,7 +102,7 @@ function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, N
var update = this.getWorldUpdateObject(false);
if(Object.getOwnPropertyNames(update).length > 0) {
NotificationCenter.trigger("broadcastGameCommand", 'worldUpdate', update);
Nc.trigger("broadcastGameCommand", 'worldUpdate', update);
}
setTimeout(this.updateWorld.bind(this), Settings.WORLD_UPDATE_BROADCAST_INTERVAL);
@ -193,12 +193,12 @@ function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, N
userId: userId
}
NotificationCenter.trigger('user/' + userId + "/gameCommand", "clientReadyResponse", options);
Nc.trigger('user/' + userId + "/gameCommand", "clientReadyResponse", options);
};
GameController.prototype.onResetLevel = function(userId) {
Parent.prototype.onResetLevel.call(this);
NotificationCenter.trigger("broadcastGameCommand", "resetLevel", true);
Nc.trigger("broadcastGameCommand", "resetLevel", true);
for (var key in this.players) {
this.spawnPlayer(this.players[key]);
}

View file

@ -5,7 +5,7 @@ define([
"Lib/Utilities/NotificationCenter"
],
function (Parent, Item, Box2D, NotificationCenter) {
function (Parent, Item, Box2D, Nc) {
function Doll(physicsEngine, uid, player) {
Parent.call(this, physicsEngine, uid, player);
@ -63,7 +63,7 @@ function (Parent, Item, Box2D, NotificationCenter) {
self.player.addDamage(damage.Length() * 2, player);
}
NotificationCenter.trigger("engine/addToWorldQueue", callback)
Nc.trigger("engine/addToWorldQueue", callback)
}
}

View file

@ -4,7 +4,7 @@ define([
"Lib/Utilities/NotificationCenter"
],
function (Parent, Settings, NotificationCenter) {
function (Parent, Settings, Nc) {
function RagDoll(physicsEngine, uid, options) {
this.scheduledForDestruction = false;
@ -35,7 +35,7 @@ function (Parent, Settings, NotificationCenter) {
};
RagDoll.prototype.destroy = function() {
NotificationCenter.trigger("broadcastGameCommand", 'removeGameObject', {
Nc.trigger("broadcastGameCommand", 'removeGameObject', {
type: 'animated',
uid: this.uid
});

View file

@ -3,7 +3,7 @@ define([
"Game/Server/Channel"
],
function (NotificationCenter, Channel) {
function (Nc, Channel) {
function PipeToLobby (process) {
@ -12,7 +12,7 @@ function (NotificationCenter, Channel) {
this.channel = null;
this.process = process;
NotificationCenter.on('process/message', this.send, this);
Nc.on('process/message', this.send, this);
process.on('message', function (message, handle) {
@ -38,7 +38,7 @@ function (NotificationCenter, Channel) {
};
PipeToLobby.prototype.onMessage = function (message) {
NotificationCenter.trigger(message.recipient + '/controlCommand', message);
Nc.trigger(message.recipient + '/controlCommand', message);
}
return PipeToLobby;

View file

@ -3,7 +3,7 @@ define([
"Lib/Utilities/NotificationCenter"
],
function (Parent, NotificationCenter) {
function (Parent, Nc) {
function Player(id, physicsEngine) {
Parent.call(this, id, physicsEngine);
@ -43,7 +43,7 @@ function (Parent, NotificationCenter) {
options.action = "throw";
options.x = x;
options.y = y;
NotificationCenter.trigger("broadcastGameCommand", "handActionResponse", options);
Nc.trigger("broadcastGameCommand", "handActionResponse", options);
}
} else {
// grab
@ -51,7 +51,7 @@ function (Parent, NotificationCenter) {
this.grab(item);
options.action = "grab";
NotificationCenter.trigger("broadcastGameCommand", "handActionResponse", options);
Nc.trigger("broadcastGameCommand", "handActionResponse", options);
}
}
};
@ -85,7 +85,7 @@ function (Parent, NotificationCenter) {
Parent.prototype.kill.call(this, killedByPlayer, ragDollId);
this.broadcastStats();
NotificationCenter.trigger("broadcastGameCommand", "playerKill", {
Nc.trigger("broadcastGameCommand", "playerKill", {
playerId: this.id,
killedByPlayerId: killedByPlayer.id,
ragDollId: ragDollId
@ -102,7 +102,7 @@ function (Parent, NotificationCenter) {
};
Player.prototype.broadcastStats = function() {
NotificationCenter.trigger("broadcastGameCommand", "updateStats", {
Nc.trigger("broadcastGameCommand", "updateStats", {
playerId: this.id,
stats: this.stats
});

View file

@ -5,7 +5,7 @@ define([
"Lib/Utilities/Protocol/Parser",
],
function(Parent, NotificationCenter, ProtocolHelper, ProtocolParser) {
function(Parent, Nc, ProtocolHelper, ProtocolParser) {
function User(id, channel) {
Parent.call(this, id);
@ -15,21 +15,21 @@ function(Parent, NotificationCenter, ProtocolHelper, ProtocolParser) {
this.isReady = false;
var self = this;
NotificationCenter.on('user/joined', function(user) { // FIXME: use sendToAllUsersExcept instead
Nc.on('user/joined', function(user) { // FIXME: use sendToAllUsersExcept instead
if(user.id != self.id) {
self.sendControlCommand("userJoined", user.id);
}
});
NotificationCenter.on('user/' + this.id + "/joinSuccess", function(options) {
Nc.on('user/' + this.id + "/joinSuccess", function(options) {
self.sendControlCommand("joinSuccess", options);
});
NotificationCenter.on('user/' + this.id + "/controlCommand", function(message) {
Nc.on('user/' + this.id + "/controlCommand", function(message) {
ProtocolHelper.applyCommand(message.data, self);
});
NotificationCenter.on('user/' + this.id + "/gameCommand", function(command, options) {
Nc.on('user/' + this.id + "/gameCommand", function(command, options) {
self.sendGameCommand(command, options);
});
}
@ -50,10 +50,10 @@ function(Parent, NotificationCenter, ProtocolHelper, ProtocolParser) {
} // FIXME: move this to Protocol helper as a function
if(command.hasOwnProperty("resetLevel")) {
NotificationCenter.trigger("user/resetLevel", this.id);
Nc.trigger("user/resetLevel", this.id);
} else if(command.hasOwnProperty("clientReady")) {
this.isReady = true;
NotificationCenter.trigger("user/clientReady", this.id);
Nc.trigger("user/clientReady", this.id);
} else {
this.player.playerController.applyCommand(command);
}
@ -67,7 +67,7 @@ function(Parent, NotificationCenter, ProtocolHelper, ProtocolParser) {
var recipient = "user/" + this.id;
var data = ProtocolHelper.encodeCommand(command, options);
NotificationCenter.trigger("process/message", recipient, data);
Nc.trigger("process/message", recipient, data);
};
User.prototype.sendGameCommand = function(command, options) {