mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
added checkpoint output, setting up a channel
This commit is contained in:
parent
dd154aa576
commit
c2ed00cb9b
10 changed files with 115 additions and 79 deletions
|
|
@ -39,6 +39,7 @@ function (ProtocolHelper, GameController) {
|
|||
if(this.gameController) this.gameController.destruct();
|
||||
this.gameController = null;
|
||||
console.log('disconnected. game destroyed. no auto-reconnect');
|
||||
document.body.style.backgroundColor = '#aaaaaa';
|
||||
}
|
||||
|
||||
Networker.prototype.join = function (channelName) {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -9,16 +9,19 @@ define([
|
|||
|
||||
function (Parent, PhysicsEngine, Settings, InputController, requestAnimFrame, NotificationCenter) {
|
||||
|
||||
function GameController () {
|
||||
function GameController (channel) {
|
||||
Parent.call(this, new PhysicsEngine());
|
||||
|
||||
this.inputControllers = {};
|
||||
this.channel = channel;
|
||||
|
||||
//this.update();
|
||||
//this.updateWorld();
|
||||
|
||||
//NotificationCenter.on('user/joined', this.userJoined, this);
|
||||
//NotificationCenter.on('user/left', this.userLeft, this);
|
||||
|
||||
console.checkpoint('starting game controller for channel ' + channel.name);
|
||||
}
|
||||
|
||||
GameController.prototype = Object.create(Parent.prototype);
|
||||
|
|
|
|||
|
|
@ -16,19 +16,21 @@ function (NotificationCenter, Channel) {
|
|||
|
||||
process.on('message', function (message, handle) {
|
||||
|
||||
switch(message.data) {
|
||||
case 'CREATE':
|
||||
self.channel = new Channel(self);
|
||||
break;
|
||||
for(var method in message.data) {
|
||||
switch(method) {
|
||||
case 'CREATE':
|
||||
self.channel = new Channel(this, message.data[method]);
|
||||
break;
|
||||
|
||||
case 'KILL':
|
||||
self.channel.destroy();
|
||||
process.exit(0);
|
||||
break;
|
||||
case 'KILL':
|
||||
self.channel.destroy();
|
||||
process.exit(0);
|
||||
break;
|
||||
|
||||
default:
|
||||
self.onMessage(message);
|
||||
break;
|
||||
default:
|
||||
self.onMessage(message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -43,7 +45,7 @@ function (NotificationCenter, Channel) {
|
|||
};
|
||||
|
||||
PipeToLobby.prototype.onMessage = function (message) {
|
||||
NotificationCenter.trigger(message.recipient + '/message', message.data);
|
||||
NotificationCenter.trigger(message.recipient + '/message', message);
|
||||
}
|
||||
|
||||
return PipeToLobby;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue