mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
Finished nc (notification center topic style refactoring) - fixes #60
This commit is contained in:
parent
cacd5d74c0
commit
76d9450257
9 changed files with 67 additions and 30 deletions
|
|
@ -24,15 +24,18 @@
|
||||||
|
|
||||||
this.gameController = new GameController(this);
|
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);
|
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(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');
|
console.checkpoint('channel ' + this.name + ' created');
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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.level.reset, this.onResetLevel, this);
|
||||||
Nc.on(Nc.ns.channel.events.user.client.ready, this.onClientReady, 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);
|
console.checkpoint('starting game controller for channel ' + channel.name);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,15 @@ function (Nc, Channel) {
|
||||||
};
|
};
|
||||||
|
|
||||||
PipeToServer.prototype.onMessage = function (message) {
|
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() {
|
PipeToServer.prototype.destroy = function() {
|
||||||
|
|
|
||||||
|
|
@ -18,16 +18,18 @@ function(Parent, Nc, ProtocolHelper, ProtocolParser) {
|
||||||
self.sendControlCommand("joinSuccess", options);
|
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);
|
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);
|
self.sendGameCommand(command, options);
|
||||||
});
|
});
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
User.prototype = Object.create(Parent.prototype);
|
User.prototype = Object.create(Parent.prototype);
|
||||||
|
|
@ -60,7 +62,7 @@ function(Parent, Nc, ProtocolHelper, ProtocolParser) {
|
||||||
// Sending commands
|
// Sending commands
|
||||||
|
|
||||||
User.prototype.sendControlCommand = function(command, options) {
|
User.prototype.sendControlCommand = function(command, options) {
|
||||||
var recipient = "user/" + this.id;
|
var recipient = this.id;
|
||||||
var data = ProtocolHelper.encodeCommand(command, options);
|
var data = ProtocolHelper.encodeCommand(command, options);
|
||||||
|
|
||||||
Nc.trigger(Nc.ns.channel.to.server.controlCommand.send, recipient, data);
|
Nc.trigger(Nc.ns.channel.to.server.controlCommand.send, recipient, data);
|
||||||
|
|
|
||||||
|
|
@ -127,7 +127,7 @@ function (Doll, Settings, Nc, Exception, SpectatorDoll, RagDoll) {
|
||||||
this.ragDoll = ragDoll;
|
this.ragDoll = ragDoll;
|
||||||
|
|
||||||
|
|
||||||
Nc.trigger("player/killed", this);
|
Nc.trigger(Nc.ns.core.game.player.killed, this);
|
||||||
};
|
};
|
||||||
|
|
||||||
Player.prototype.update = function () {
|
Player.prototype.update = function () {
|
||||||
|
|
|
||||||
|
|
@ -42,15 +42,12 @@ function (Exception) {
|
||||||
preloadBar: {
|
preloadBar: {
|
||||||
update: null
|
update: null
|
||||||
},
|
},
|
||||||
fullScreen: {
|
fullscreen: {
|
||||||
change: null
|
change: null
|
||||||
},
|
},
|
||||||
debugMode: {
|
debugMode: {
|
||||||
toggle: null
|
toggle: null
|
||||||
},
|
},
|
||||||
gameInfo: {
|
|
||||||
toggle: null
|
|
||||||
},
|
|
||||||
events: {
|
events: {
|
||||||
ready: null
|
ready: null
|
||||||
}
|
}
|
||||||
|
|
@ -63,9 +60,16 @@ function (Exception) {
|
||||||
change: null
|
change: null
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
server: {
|
game: {
|
||||||
gameCommand: {
|
gameInfo: {
|
||||||
send: null
|
toggle: null
|
||||||
|
}
|
||||||
|
},
|
||||||
|
to: {
|
||||||
|
server: {
|
||||||
|
gameCommand: {
|
||||||
|
send: null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
@ -75,6 +79,9 @@ function (Exception) {
|
||||||
add: null,
|
add: null,
|
||||||
remove: null
|
remove: null
|
||||||
},
|
},
|
||||||
|
player: {
|
||||||
|
killed: null
|
||||||
|
},
|
||||||
events: {
|
events: {
|
||||||
level: {
|
level: {
|
||||||
loaded: null
|
loaded: null
|
||||||
|
|
@ -84,7 +91,10 @@ function (Exception) {
|
||||||
},
|
},
|
||||||
channel: {
|
channel: {
|
||||||
events: {
|
events: {
|
||||||
controlCommand: null,
|
controlCommand: {
|
||||||
|
channel: null,
|
||||||
|
user: null
|
||||||
|
},
|
||||||
user: {
|
user: {
|
||||||
joined: null,
|
joined: null,
|
||||||
left: null,
|
left: null,
|
||||||
|
|
@ -103,7 +113,9 @@ function (Exception) {
|
||||||
},
|
},
|
||||||
to: {
|
to: {
|
||||||
server: {
|
server: {
|
||||||
send: null
|
controlCommand: {
|
||||||
|
send: null
|
||||||
|
}
|
||||||
},
|
},
|
||||||
client: {
|
client: {
|
||||||
user: {
|
user: {
|
||||||
|
|
@ -122,7 +134,10 @@ function (Exception) {
|
||||||
},
|
},
|
||||||
server: {
|
server: {
|
||||||
events: {
|
events: {
|
||||||
controlCommand: null,
|
controlCommand: {
|
||||||
|
coordinator: null,
|
||||||
|
user: null
|
||||||
|
},
|
||||||
user: {
|
user: {
|
||||||
joined: null,
|
joined: null,
|
||||||
left: null
|
left: null
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ function (User, Channel, PipeToChannel, Nc, Settings) {
|
||||||
function Coordinator() {
|
function Coordinator() {
|
||||||
this.channelPipes = {};
|
this.channelPipes = {};
|
||||||
|
|
||||||
Nc.on(Nc.ns.server.events.controlCommand + "coordinator", this.onMessage, this);
|
Nc.on(Nc.ns.server.events.controlCommand.coordinator, this.onMessage, this);
|
||||||
|
|
||||||
console.checkpoint('create Coordinator');
|
console.checkpoint('create Coordinator');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ function (Nc, childProcess) {
|
||||||
// If user already created
|
// If user already created
|
||||||
PipeToChannel.prototype.sendToUser = function (id, data) {
|
PipeToChannel.prototype.sendToUser = function (id, data) {
|
||||||
var message = {
|
var message = {
|
||||||
recipient: "user/" + id,
|
recipient: id,
|
||||||
data: data
|
data: data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -47,7 +47,15 @@ function (Nc, childProcess) {
|
||||||
}
|
}
|
||||||
|
|
||||||
PipeToChannel.prototype.onMessage = function (message) {
|
PipeToChannel.prototype.onMessage = function (message) {
|
||||||
Nc.trigger(Nc.ns.server.events.controlCommand + message.recipient, message.data);
|
switch(message.recipient) {
|
||||||
|
case 'coordinator':
|
||||||
|
Nc.trigger(Nc.ns.server.events.controlCommand.coordinator, message.data);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Nc.trigger(Nc.ns.server.events.controlCommand.user + message.recipient, message.data);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return PipeToChannel;
|
return PipeToChannel;
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ function (Parent, ProtocolHelper, Nc) {
|
||||||
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));
|
||||||
|
|
||||||
Nc.on(Nc.ns.server.to.client.message.send + id, this.socketLink.send, this.socketLink);
|
Nc.on(Nc.ns.server.events.controlCommand.user + this.id, this.socketLink.send, this.socketLink);
|
||||||
}
|
}
|
||||||
|
|
||||||
User.prototype = Object.create(Parent.prototype);
|
User.prototype = Object.create(Parent.prototype);
|
||||||
|
|
@ -65,6 +65,7 @@ function (Parent, ProtocolHelper, Nc) {
|
||||||
this.channelPipe.send('channel', { addUser: userOptions });
|
this.channelPipe.send('channel', { addUser: userOptions });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* FIXME: watch out and check in wich direction game and control commands flow */
|
||||||
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);
|
||||||
|
|
@ -73,7 +74,7 @@ function (Parent, ProtocolHelper, Nc) {
|
||||||
|
|
||||||
User.prototype.onPing = function(timestamp) {
|
User.prototype.onPing = function(timestamp) {
|
||||||
var message = ProtocolHelper.encodeCommand("pong", timestamp);
|
var message = ProtocolHelper.encodeCommand("pong", timestamp);
|
||||||
Nc.trigger(Nc.ns.server.to.client.message.send + id, message);
|
Nc.trigger(Nc.ns.server.events.controlCommand.user + this.id, message);
|
||||||
};
|
};
|
||||||
|
|
||||||
return User;
|
return User;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue