added checkpoint output, setting up a channel

This commit is contained in:
logsol 2012-08-31 19:23:51 +02:00
parent dd154aa576
commit c2ed00cb9b
10 changed files with 115 additions and 79 deletions

View file

@ -5,56 +5,56 @@
function (GameController, NotificationCenter) {
function Channel (pipeToLobby) {
function Channel (pipeToLobby, name) {
var self = this;
this.pipeToLobby = pipeToLobby;
this.name = name;
this.users = {};
this.pipeToLobby = pipeToLobby;
this.gameController = new GameController(this);
this.gameController.loadLevel("default.json");
//this.pipeToLobby.receive = function (message) { self.onMessage(message) };
// !!! This should be done differently - use NotificationCenter.on('channel/dungeon/message') instead
this.users = {};
this.gameController = new GameController();
this.gameController.loadLevel("default.json");
/*
var self = this;
NotificationCenter.on("processGameCommandFromUser", function (topic, args) {
self.processGameCommandFromUser.apply(self, args);
});
*/
}
Channel.validateName = function (name) {
return true;
}
// Messages look like:
// {channel: {setName: 'foo'}}
// {user: {jupm: null}, id: 12}
Channel.prototype.onMessage = function (message) {
for(var recipient in message) {
switch(recipient) {
// Messages look like:
// {channel: {setName: 'foo'}}
// {user: {jupm: null}, id: 12}
NotificationCenter.on('channel/message', function (message){
switch(message.recipient) {
case 'user':
this.forward(this.users[message.id], message.user);
self.forward(self.users[message.id], message.user);
break;
case 'id': // Do nothing, it is needed by the user
break;
case 'channel':
this.forward(this, message.channel);
self.forward(self, message.channel);
break;
default:
throw 'unknown recipient';
break;
}
}
};
});
console.checkpoint('channel ' + name + ' created');
}
Channel.validateName = function (name) {
return true;
}
Channel.prototype.forward = function (target, message) {
for(var command in message) {
@ -65,24 +65,19 @@
}
}
};
Channel.prototype.setName = function (name) {
this.name = name;
console.log(' created channel ' + name);
}
/*
Channel.prototype.addUser = function (user) {
var userIds = Object.keys(this.users);
//var userIds = Object.keys(this.users);
console.log('addUser', user);
this.users[user.id] = user;
user.sendCommand('joinSuccess', {channelName: this.name, id: user.id, userIds: userIds});
this.sendCommandToAllUsersExcept('userJoined', user.id, user);
//user.sendCommand('joinSuccess', {channelName: this.name, id: user.id, userIds: userIds});
//this.sendCommandToAllUsersExcept('userJoined', user.id, user);
NotificationCenter.trigger('user/joined', user);
//NotificationCenter.trigger('user/joined', user);
}
/*
Channel.prototype.releaseUser = function (user) {
this.gameController.userIdLeft(user.id);