mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 18:47:35 +00:00
added automatic method calling
This commit is contained in:
parent
b5b10ba0b9
commit
ebb400a289
1 changed files with 14 additions and 13 deletions
|
|
@ -28,7 +28,7 @@ function(GameController, NotificationCenter) {
|
|||
}
|
||||
|
||||
// Messages look like:
|
||||
// {chanel: {setName: 'foo'}}
|
||||
// {channel: {setName: 'foo'}}
|
||||
// {user: {jupm: null}, id: 12}
|
||||
Channel.prototype.onMessage = function(message) {
|
||||
|
||||
|
|
@ -37,12 +37,12 @@ function(GameController, NotificationCenter) {
|
|||
switch(recipient) {
|
||||
|
||||
case 'user':
|
||||
this.users[message.id].onMessage(message.user);
|
||||
this.forward(this.users[message.id], message.user);
|
||||
break;
|
||||
case 'id': // Do nothing, it is needed by the user
|
||||
break;
|
||||
case 'channel':
|
||||
this.onCommand(message.channel);
|
||||
this.forward(this, message.channel);
|
||||
break;
|
||||
default:
|
||||
throw 'unknown recipient';
|
||||
|
|
@ -51,20 +51,21 @@ function(GameController, NotificationCenter) {
|
|||
}
|
||||
};
|
||||
|
||||
Channel.prototype.onCommand = function(message) {
|
||||
Channel.prototype.forward = function(target, message) {
|
||||
for(var command in message) {
|
||||
switch(command) {
|
||||
|
||||
case 'setName':
|
||||
this.name = message[command];
|
||||
console.log("Chanel name set to '" + this.name + "'");
|
||||
break;
|
||||
default:
|
||||
throw 'unknown command';
|
||||
break;
|
||||
if(typeof target[command] == 'function'){
|
||||
target[command].call(target, message[command]);
|
||||
} else {
|
||||
throw 'trying to call undefined function ' + target[command];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Channel.prototype.setName = function(name) {
|
||||
this.name = name;
|
||||
console.log(' created channel ' + name);
|
||||
}
|
||||
|
||||
/*
|
||||
Channel.prototype.addUser = function(user){
|
||||
var userIds = Object.keys(this.users);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue