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" "Lib/Utilities/NotificationCenter"
], ],
function (Parent, DomController, Settings, NotificationCenter) { function (Parent, DomController, Settings, Nc) {
function MouseInput() { function MouseInput() {
Parent.call(this); Parent.call(this);
@ -37,7 +37,7 @@ function (Parent, DomController, Settings, NotificationCenter) {
var x = (((e.clientX - this.offsetLeft) / Settings.STAGE_WIDTH) * 2) - 1; 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; 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" "Lib/Utilities/NotificationCenter"
], ],
function (NotificationCenter) { function (Nc) {
function XyInput() { function XyInput() {
this.x = null; this.x = null;
@ -12,7 +12,7 @@ function (NotificationCenter) {
XyInput.prototype.onXyChange = function(x, y) { XyInput.prototype.onXyChange = function(x, y) {
this.x = x; this.x = x;
this.y = y; this.y = y;
NotificationCenter.trigger('input/onXyChange', x, y); Nc.trigger('input/onXyChange', x, y);
} }
return XyInput; return XyInput;

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -7,7 +7,7 @@ define([
"Lib/Utilities/NotificationCenter" "Lib/Utilities/NotificationCenter"
], ],
function (Settings, Exception, AbstractView, PixiView, NotificationCenter) { function (Settings, Exception, AbstractView, PixiView, Nc) {
var ViewManager = {}; 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!"); 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; return view;
} }

View file

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

View file

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

View file

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

View file

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

View file

@ -9,7 +9,7 @@ define([
"Game/" + GLOBALS.context + "/GameObjects/Items/Skateboard", "Game/" + GLOBALS.context + "/GameObjects/Items/Skateboard",
"Game/" + GLOBALS.context + "/GameObjects/Items/RagDoll" "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) { function Level (uid, engine, gameObjects) {
this.uid = uid; this.uid = uid;
@ -28,7 +28,7 @@ define([
self.createTiles(); self.createTiles();
self.createItems(); self.createItems();
self.isLoaded = true; self.isLoaded = true;
NotificationCenter.trigger("game/level/loaded"); Nc.trigger("game/level/loaded");
}); });
} }
@ -67,7 +67,7 @@ define([
var options = items[i]; var options = items[i];
var uid = "item-" + i; var uid = "item-" + i;
var item = this.createItem(uid, options); 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" "Lib/Utilities/NotificationCenter"
], ],
function (Settings, Box2D, CollisionDetector, NotificationCenter) { function (Settings, Box2D, CollisionDetector, Nc) {
function Engine () { function Engine () {
this.world = new Box2D.Dynamics.b2World( this.world = new Box2D.Dynamics.b2World(
@ -17,7 +17,7 @@ function (Settings, Box2D, CollisionDetector, NotificationCenter) {
this.lastStep = Date.now(); this.lastStep = Date.now();
this.worldQueue = []; this.worldQueue = [];
NotificationCenter.on("engine/addToWorldQueue", this.addToWorldQueue, this); Nc.on("engine/addToWorldQueue", this.addToWorldQueue, this);
} }
Engine.prototype.getWorld = function () { 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) { function Player (id, physicsEngine) {
this.stats = { 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 = new Doll(this.physicsEngine, "doll-" + this.id, this);
this.doll.spawn(x, y); this.doll.spawn(x, y);
this.isSpawned = true; this.isSpawned = true;
NotificationCenter.trigger("game/object/add", 'animated', this.doll); Nc.trigger("game/object/add", 'animated', this.doll);
} }
Player.prototype.getPosition = function () { Player.prototype.getPosition = function () {
@ -119,14 +119,14 @@ function (Doll, Settings, NotificationCenter, Exception, SpectatorDoll, RagDoll)
this.isSpawned = false; this.isSpawned = false;
NotificationCenter.trigger("game/object/remove", 'animated', this.doll); Nc.trigger("game/object/remove", 'animated', this.doll);
this.doll.destroy(); this.doll.destroy();
this.doll = null; this.doll = null;
this.ragDoll = ragDoll; this.ragDoll = ragDoll;
NotificationCenter.trigger("player/killed", this); Nc.trigger("player/killed", this);
}; };
Player.prototype.update = function () { Player.prototype.update = function () {

View file

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

View file

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

View file

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

View file

@ -5,7 +5,7 @@ define([
"Lib/Utilities/NotificationCenter" "Lib/Utilities/NotificationCenter"
], ],
function (Parent, Item, Box2D, NotificationCenter) { function (Parent, Item, Box2D, Nc) {
function Doll(physicsEngine, uid, player) { function Doll(physicsEngine, uid, player) {
Parent.call(this, 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); 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" "Lib/Utilities/NotificationCenter"
], ],
function (Parent, Settings, NotificationCenter) { function (Parent, Settings, Nc) {
function RagDoll(physicsEngine, uid, options) { function RagDoll(physicsEngine, uid, options) {
this.scheduledForDestruction = false; this.scheduledForDestruction = false;
@ -35,7 +35,7 @@ function (Parent, Settings, NotificationCenter) {
}; };
RagDoll.prototype.destroy = function() { RagDoll.prototype.destroy = function() {
NotificationCenter.trigger("broadcastGameCommand", 'removeGameObject', { Nc.trigger("broadcastGameCommand", 'removeGameObject', {
type: 'animated', type: 'animated',
uid: this.uid uid: this.uid
}); });

View file

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

View file

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

View file

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

View file

@ -3,7 +3,7 @@ define([
"Lib/Utilities/Protocol/Helper" "Lib/Utilities/Protocol/Helper"
], ],
function (NotificationCenter, ProtocolHelper) { function (Nc, ProtocolHelper) {
function Api(coordinator) { function Api(coordinator) {
this.coordinator = coordinator; this.coordinator = coordinator;

View file

@ -5,7 +5,7 @@ define([
"Lib/Utilities/NotificationCenter" "Lib/Utilities/NotificationCenter"
], ],
function (User, Channel, PipeToChannel, NotificationCenter) { function (User, Channel, PipeToChannel, Nc) {
function Coordinator () { function Coordinator () {
this.channelPipes = {}; this.channelPipes = {};
@ -46,14 +46,14 @@ function (User, Channel, PipeToChannel, NotificationCenter) {
//channel.addUser(user); //channel.addUser(user);
//user.setChannel(channel); //user.setChannel(channel);
NotificationCenter.trigger('user/joined', user); Nc.trigger('user/joined', user);
delete this.lobbyUsers[user.id]; delete this.lobbyUsers[user.id];
} }
Coordinator.prototype.removeUser = function (user) { Coordinator.prototype.removeUser = function (user) {
NotificationCenter.trigger('user/left', user); Nc.trigger('user/left', user);
//NotificationCenter.off('channel/' + user.channel.channelName + '/user/' + user.id); //NotificationCenter.off('channel/' + user.channel.channelName + '/user/' + user.id);
delete this.lobbyUsers[user.id]; delete this.lobbyUsers[user.id];
@ -65,14 +65,14 @@ function (User, Channel, PipeToChannel, NotificationCenter) {
this.channelPipes[channelName] = channelPipe; this.channelPipes[channelName] = channelPipe;
NotificationCenter.on('channel/' + channelName + '/message', function (data) { Nc.on('channel/' + channelName + '/message', function (data) {
channelPipe.send('channel', data); channelPipe.send('channel', data);
}, this); }, this);
// sending info to user // sending info to user
NotificationCenter.on('user/joined', function (user) { Nc.on('user/joined', function (user) {
/* /*
NotificationCenter.on('channel/' + channelName + '/user/' + user.id, function (recipient, data) { Nc.on('channel/' + channelName + '/user/' + user.id, function (recipient, data) {
channelPipe.send(recipient, data); channelPipe.send(recipient, data);
}, this); }, this);
*/ */
@ -81,11 +81,11 @@ function (User, Channel, PipeToChannel, NotificationCenter) {
}, this); }, this);
NotificationCenter.on('user/left', function (user) { Nc.on('user/left', function (user) {
channelPipe.send('channel', { releaseUser: user.id }); channelPipe.send('channel', { releaseUser: user.id });
}, this); }, this);
NotificationCenter.on('user/controlCommand', function (userId, data) { Nc.on('user/controlCommand', function (userId, data) {
channelPipe.sendToUser(userId, data); channelPipe.sendToUser(userId, data);
}, this); }, this);

View file

@ -3,7 +3,7 @@ define([
"child_process" "child_process"
], ],
function (NotificationCenter, childProcess) { function (Nc, childProcess) {
var fork = childProcess.fork; var fork = childProcess.fork;
@ -13,7 +13,6 @@ function (NotificationCenter, childProcess) {
try { try {
this.channelPipe = fork('channel.js'); this.channelPipe = fork('channel.js');
console.log(this.channelPipe)
} catch (err) { } catch (err) {
throw 'Failed to fork channel! (' + err + ')'; throw 'Failed to fork channel! (' + err + ')';
} }
@ -48,7 +47,7 @@ function (NotificationCenter, childProcess) {
} }
PipeToChannel.prototype.onMessage = function (message) { PipeToChannel.prototype.onMessage = function (message) {
NotificationCenter.trigger(message.recipient + '/message', message.data); Nc.trigger(message.recipient + '/message', message.data);
} }
return PipeToChannel; return PipeToChannel;

View file

@ -4,7 +4,7 @@ define([
"Lib/Utilities/NotificationCenter" "Lib/Utilities/NotificationCenter"
], ],
function (Parent, ProtocolHelper, NotificationCenter) { function (Parent, ProtocolHelper, Nc) {
function User (socketLink, coordinator) { function User (socketLink, coordinator) {
Parent.call(this, socketLink.id); Parent.call(this, socketLink.id);
@ -16,7 +16,7 @@ function (Parent, ProtocolHelper, NotificationCenter) {
socketLink.on('message', this.onMessage.bind(this)); socketLink.on('message', this.onMessage.bind(this));
socketLink.on('disconnect', this.onDisconnect.bind(this)); socketLink.on('disconnect', this.onDisconnect.bind(this));
NotificationCenter.on("user/" + this.socketLink.id + "/message", this.socketLink.send, this.socketLink); Nc.on("user/" + this.socketLink.id + "/message", this.socketLink.send, this.socketLink);
} }
User.prototype = Object.create(Parent.prototype); User.prototype = Object.create(Parent.prototype);
@ -47,12 +47,12 @@ function (Parent, ProtocolHelper, NotificationCenter) {
User.prototype.onGameCommand = function(options) { User.prototype.onGameCommand = function(options) {
// repacking for transport via pipe // repacking for transport via pipe
var message = ProtocolHelper.encodeCommand("gameCommand", options); var message = ProtocolHelper.encodeCommand("gameCommand", options);
NotificationCenter.trigger("user/controlCommand", this.id, message); Nc.trigger("user/controlCommand", this.id, message);
}; };
User.prototype.onPing = function(timestamp) { User.prototype.onPing = function(timestamp) {
var message = ProtocolHelper.encodeCommand("pong", timestamp); var message = ProtocolHelper.encodeCommand("pong", timestamp);
NotificationCenter.trigger("user/" + this.socketLink.id + "/message", message); Nc.trigger("user/" + this.socketLink.id + "/message", message);
}; };
return User; return User;

View file

@ -6,7 +6,7 @@ define([
"Lib/Utilities/NotificationCenter" "Lib/Utilities/NotificationCenter"
], ],
function (Parent, ProtocolHelper, GameController, User, NotificationCenter) { function (Parent, ProtocolHelper, GameController, User, Nc) {
function Worker () { function Worker () {
//this.socketLink = socketLink; //this.socketLink = socketLink;
@ -40,7 +40,7 @@ function (Parent, ProtocolHelper, GameController, User, NotificationCenter) {
} }
}, this); }, this);
NotificationCenter.on("sendGameCommand", this.sendGameCommand, this); Nc.on("sendGameCommand", this.sendGameCommand, this);
} }
Worker.prototype.sendCommand = function (command, options) { Worker.prototype.sendCommand = function (command, options) {