mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 18:47:35 +00:00
replaced NotificationCenter with Nc
This commit is contained in:
parent
da913c4709
commit
672a46efa8
35 changed files with 160 additions and 161 deletions
|
|
@ -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];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ define([
|
|||
"Lib/Utilities/Protocol/Parser"
|
||||
],
|
||||
|
||||
function(Parent, NotificationCenter, Parser) {
|
||||
function(Parent, Nc, Parser) {
|
||||
|
||||
function PlayerController(player) {
|
||||
|
||||
|
|
|
|||
|
|
@ -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]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue