working towards usable new structure

This commit is contained in:
logsol 2012-07-22 17:54:27 +02:00
parent 3afc2fa66e
commit 815c63009f
15 changed files with 223 additions and 84 deletions

View file

@ -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;
});