mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
working towards usable new structure
This commit is contained in:
parent
3afc2fa66e
commit
815c63009f
15 changed files with 223 additions and 84 deletions
|
|
@ -1,12 +1,13 @@
|
|||
define([
|
||||
"Game/Core/User",
|
||||
"Game/Core/Protocol/Helper",
|
||||
"Game/Server/NotificationCenter"
|
||||
"Game/Core/NotificationCenter"
|
||||
],
|
||||
|
||||
function(ProtocolHelper, NotificationCenter) {
|
||||
|
||||
function User(socketLink, coordinator) {
|
||||
function(Parent, ProtocolHelper, NotificationCenter) {
|
||||
|
||||
function User(id, coordinator) {
|
||||
Parent.call(this, id);
|
||||
this.id = socketLink.id;
|
||||
this.socketLink = socketLink;
|
||||
this.coordinator = coordinator;
|
||||
|
|
@ -15,19 +16,14 @@ function(ProtocolHelper, NotificationCenter) {
|
|||
this.init(socketLink);
|
||||
}
|
||||
|
||||
User.prototype = Object.create(Parent.prototype);
|
||||
|
||||
User.prototype.init = function(socketLink){
|
||||
|
||||
var self = this;
|
||||
|
||||
socketLink.on('message', function(message){
|
||||
self.onMessage(message);
|
||||
});
|
||||
|
||||
socketLink.on('disconnect', function(){
|
||||
self.onDisconnect();
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
User.prototype.setChannel = function(channel) {
|
||||
this.channel = channel;
|
||||
}
|
||||
|
|
@ -38,44 +34,12 @@ function(ProtocolHelper, NotificationCenter) {
|
|||
this.socketLink.send(message);
|
||||
}
|
||||
|
||||
User.prototype.onMessage = function(message){
|
||||
var self = this;
|
||||
ProtocolHelper.runCommands(message, function(command, options){
|
||||
self.processControlCommand(command, options);
|
||||
});
|
||||
}
|
||||
|
||||
User.prototype.onDisconnect = function(){
|
||||
this.coordinator.removeUser(this);
|
||||
}
|
||||
|
||||
User.prototype.processControlCommand = function(command, options){
|
||||
switch(command) {
|
||||
|
||||
case 'join':
|
||||
this.coordinator.assignUserToChannel(this, options);
|
||||
break;
|
||||
|
||||
case 'leave':
|
||||
this.coordinator.assignUserToLobby(this);
|
||||
break;
|
||||
|
||||
case 'gameCommand':
|
||||
for(var gameCommand in options) {
|
||||
//NotificationCenter.trigger("processGameCommandFromUser", [gameCommand, options[gameCommand], this]);
|
||||
//this.channel.processGameCommandFromUser(gameCommand, options[gameCommand], this);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
User.prototype.toString = function() {
|
||||
return "[User " + this.id + "]";
|
||||
};
|
||||
|
||||
*/
|
||||
return User;
|
||||
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue