Finished nc (notification center topic style refactoring) - fixes #60

This commit is contained in:
logsol 2014-03-17 23:12:08 +01:00
parent cacd5d74c0
commit 76d9450257
9 changed files with 67 additions and 30 deletions

View file

@ -24,15 +24,18 @@
this.gameController = new GameController(this);
Nc.on('channel/controlCommand', function (message) {
Nc.on(Nc.ns.channel.events.controlCommand.channel, function (message) {
ProtocolHelper.applyCommand(message.data, self);
});
Nc.on('broadcastControlCommand', this.broadcastControlCommand, this);
Nc.on('broadcastControlCommandExcept', this.broadcastControlCommandExcept, this);
Nc.on(Nc.ns.channel.to.client.gameCommand.broadcast, this.broadcastGameCommand, this);
Nc.on('broadcastGameCommandExcept', this.broadcastGameCommandExcept, this);
// prepared - not triggered yet
//Nc.on(Nc.ns.channel.to.client.gameCommand.broadcastExcept, this.broadcastGameCommandExcept, this);
//Nc.on(Nc.ns.channel.to.client.controlCommand.broadcast, this.broadcastControlCommand, this);
//Nc.on(Nc.ns.channel.to.client.controlCommand.broadcastExcept, this.broadcastControlCommandExcept, this);
console.checkpoint('channel ' + this.name + ' created');

View file

@ -25,7 +25,7 @@ function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, N
Nc.on(Nc.ns.channel.events.user.level.reset, this.onResetLevel, this);
Nc.on(Nc.ns.channel.events.user.client.ready, this.onClientReady, this);
Nc.on('player/killed', this.onPlayerKilled, this);
Nc.on(Nc.ns.core.game.player.killed, this.onPlayerKilled, this);
console.checkpoint('starting game controller for channel ' + channel.name);

View file

@ -37,7 +37,15 @@ function (Nc, Channel) {
};
PipeToServer.prototype.onMessage = function (message) {
Nc.trigger(Nc.ns.channel.events.controlCommand + recipient, message);
switch(message.recipient) {
case 'channel':
Nc.trigger(Nc.ns.channel.events.controlCommand.channel, message);
break;
default:
Nc.trigger(Nc.ns.channel.events.controlCommand.user + message.recipient, message);
break;
}
}
PipeToServer.prototype.destroy = function() {

View file

@ -18,16 +18,18 @@ function(Parent, Nc, ProtocolHelper, ProtocolParser) {
self.sendControlCommand("joinSuccess", options);
});
Nc.on('user/' + this.id + "/controlCommand", function(message) {
Nc.on(Nc.ns.channel.events.controlCommand.user + this.id, function(message) {
ProtocolHelper.applyCommand(message.data, self);
});
/*
couldnt find trigger for this while refactoring
Nc.on('user/' + this.id + "/gameCommand", function(command, options) {
Nc.on(Nc.ns.channel.to.client.user.gameCommand.send + this.id, function(command, options) {
self.sendGameCommand(command, options);
});
*/
}
User.prototype = Object.create(Parent.prototype);
@ -60,7 +62,7 @@ function(Parent, Nc, ProtocolHelper, ProtocolParser) {
// Sending commands
User.prototype.sendControlCommand = function(command, options) {
var recipient = "user/" + this.id;
var recipient = this.id;
var data = ProtocolHelper.encodeCommand(command, options);
Nc.trigger(Nc.ns.channel.to.server.controlCommand.send, recipient, data);

View file

@ -127,7 +127,7 @@ function (Doll, Settings, Nc, Exception, SpectatorDoll, RagDoll) {
this.ragDoll = ragDoll;
Nc.trigger("player/killed", this);
Nc.trigger(Nc.ns.core.game.player.killed, this);
};
Player.prototype.update = function () {