mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
cleaned up the mess ... :)
This commit is contained in:
parent
ec1bceb1b6
commit
dd154aa576
6 changed files with 34 additions and 23 deletions
|
|
@ -11,7 +11,7 @@ function () {
|
||||||
NotificationCenter.prototype.trigger = function (topic /*, arguments*/) {
|
NotificationCenter.prototype.trigger = function (topic /*, arguments*/) {
|
||||||
|
|
||||||
if (!this.topics[topic]) {
|
if (!this.topics[topic]) {
|
||||||
throw "No such topic " + topic + ". Could not trigger.";
|
throw "No such topic " + topic + ". Could not trigger. arguments: " + arguments.join;
|
||||||
}
|
}
|
||||||
|
|
||||||
var args = Array.prototype.slice.call(arguments, 1);
|
var args = Array.prototype.slice.call(arguments, 1);
|
||||||
|
|
|
||||||
|
|
@ -5,11 +5,16 @@
|
||||||
|
|
||||||
function (GameController, NotificationCenter) {
|
function (GameController, NotificationCenter) {
|
||||||
|
|
||||||
function Channel (coordinatorLink) {
|
function Channel (pipeToLobby) {
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
this.coordinatorLink = coordinatorLink;
|
this.pipeToLobby = pipeToLobby;
|
||||||
this.coordinatorLink.receive = function (message) { self.onMessage(message) };
|
|
||||||
|
|
||||||
|
//this.pipeToLobby.receive = function (message) { self.onMessage(message) };
|
||||||
|
// !!! This should be done differently - use NotificationCenter.on('channel/dungeon/message') instead
|
||||||
|
|
||||||
|
|
||||||
this.users = {};
|
this.users = {};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,30 +1,33 @@
|
||||||
define([
|
define([
|
||||||
"Game/Core/NotficationCenter"
|
"Game/Core/NotificationCenter",
|
||||||
|
"Game/Server/Channel"
|
||||||
],
|
],
|
||||||
|
|
||||||
function (NotficationCenter) {
|
function (NotificationCenter, Channel) {
|
||||||
|
|
||||||
function PipeToLobby (process) {
|
function PipeToLobby (process) {
|
||||||
|
|
||||||
|
var self = this;
|
||||||
|
|
||||||
this.channel = null;
|
this.channel = null;
|
||||||
this.process = process;
|
this.process = process;
|
||||||
|
|
||||||
NotficationCenter.on('net/send', this.send, this);
|
NotificationCenter.on('net/send', this.send, this);
|
||||||
|
|
||||||
process.on('message', function (message, handle) {
|
process.on('message', function (message, handle) {
|
||||||
|
|
||||||
switch(message) {
|
switch(message.data) {
|
||||||
case 'CREATE':
|
case 'CREATE':
|
||||||
this.channel = new Channel(this);
|
self.channel = new Channel(self);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'KILL':
|
case 'KILL':
|
||||||
this.channel.destroy();
|
self.channel.destroy();
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
this.onMessage(message);
|
self.onMessage(message);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -40,7 +43,7 @@ function (NotficationCenter) {
|
||||||
};
|
};
|
||||||
|
|
||||||
PipeToLobby.prototype.onMessage = function (message) {
|
PipeToLobby.prototype.onMessage = function (message) {
|
||||||
NotficationCenter.trigger(message.recipient + '/message', message.data);
|
NotificationCenter.trigger(message.recipient + '/message', message.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
return PipeToLobby;
|
return PipeToLobby;
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,11 @@
|
||||||
define([
|
define([
|
||||||
"Lobby/User",
|
"Lobby/User",
|
||||||
"Game/Server/Channel",
|
"Game/Server/Channel",
|
||||||
"Lobby/PipeToChannel"
|
"Lobby/PipeToChannel",
|
||||||
"child_process"
|
"Game/Core/NotificationCenter"
|
||||||
],
|
],
|
||||||
|
|
||||||
function (User, Channel, PipeToChannel, childProcess) {
|
function (User, Channel, PipeToChannel, NotificationCenter) {
|
||||||
|
|
||||||
var fork = childProcess.fork;
|
|
||||||
|
|
||||||
function Coordinator () {
|
function Coordinator () {
|
||||||
this.channels = {};
|
this.channels = {};
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,11 @@
|
||||||
define([
|
define([
|
||||||
"Game/Core/NotificationCenter"
|
//"Game/Core/NotificationCenter",
|
||||||
|
"child_process"
|
||||||
],
|
],
|
||||||
|
|
||||||
function (NotificationCenter) {
|
function (childProcess) {
|
||||||
|
|
||||||
|
var fork = childProcess.fork;
|
||||||
|
|
||||||
function PipeToChannel (channelName) {
|
function PipeToChannel (channelName) {
|
||||||
|
|
||||||
|
|
|
||||||
10
channel.js
10
channel.js
|
|
@ -1,17 +1,19 @@
|
||||||
var requirejs = require('requirejs');
|
var requirejs = require('requirejs');
|
||||||
|
|
||||||
requirejs.config({
|
requirejs.config({
|
||||||
|
nodeRequire: require,
|
||||||
baseUrl: 'app'
|
baseUrl: 'app'
|
||||||
});
|
});
|
||||||
|
|
||||||
var inspector = {};
|
var inspector = {};
|
||||||
|
|
||||||
requirejs([
|
requirejs([
|
||||||
"Game/Server/LobbyPipe"
|
"Game/Server/PipeToLobby",
|
||||||
|
"Game/Core/NotificationCenter"
|
||||||
],
|
],
|
||||||
|
|
||||||
function (LobbyPipe) {
|
function (PipeToLobby, nc) {
|
||||||
var lobbyPipe = new LobbyPipe(process);
|
var PipeToLobby = new PipeToLobby(process);
|
||||||
|
|
||||||
inspector.lobbyPipe = lobbyPipe;
|
inspector.PipeToLobby = PipeToLobby;
|
||||||
});
|
});
|
||||||
Loading…
Add table
Add a link
Reference in a new issue