diff --git a/app/Game/Core/NotificationCenter.js b/app/Game/Core/NotificationCenter.js index 2747c2a..4dd3d6a 100755 --- a/app/Game/Core/NotificationCenter.js +++ b/app/Game/Core/NotificationCenter.js @@ -11,7 +11,7 @@ function () { NotificationCenter.prototype.trigger = function (topic /*, arguments*/) { 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); diff --git a/app/Game/Server/Channel.js b/app/Game/Server/Channel.js index db99290..ea72aef 100755 --- a/app/Game/Server/Channel.js +++ b/app/Game/Server/Channel.js @@ -5,11 +5,16 @@ function (GameController, NotificationCenter) { - function Channel (coordinatorLink) { + function Channel (pipeToLobby) { + var self = this; - this.coordinatorLink = coordinatorLink; - this.coordinatorLink.receive = function (message) { self.onMessage(message) }; + this.pipeToLobby = pipeToLobby; + + + //this.pipeToLobby.receive = function (message) { self.onMessage(message) }; + // !!! This should be done differently - use NotificationCenter.on('channel/dungeon/message') instead + this.users = {}; diff --git a/app/Game/Server/PipeToLobby.js b/app/Game/Server/PipeToLobby.js index a28d97f..671b3b6 100755 --- a/app/Game/Server/PipeToLobby.js +++ b/app/Game/Server/PipeToLobby.js @@ -1,30 +1,33 @@ define([ - "Game/Core/NotficationCenter" + "Game/Core/NotificationCenter", + "Game/Server/Channel" ], -function (NotficationCenter) { +function (NotificationCenter, Channel) { function PipeToLobby (process) { + var self = this; + this.channel = null; this.process = process; - NotficationCenter.on('net/send', this.send, this); + NotificationCenter.on('net/send', this.send, this); process.on('message', function (message, handle) { - switch(message) { + switch(message.data) { case 'CREATE': - this.channel = new Channel(this); + self.channel = new Channel(self); break; case 'KILL': - this.channel.destroy(); + self.channel.destroy(); process.exit(0); break; default: - this.onMessage(message); + self.onMessage(message); break; } }); @@ -40,7 +43,7 @@ function (NotficationCenter) { }; PipeToLobby.prototype.onMessage = function (message) { - NotficationCenter.trigger(message.recipient + '/message', message.data); + NotificationCenter.trigger(message.recipient + '/message', message.data); } return PipeToLobby; diff --git a/app/Lobby/Coordinator.js b/app/Lobby/Coordinator.js index 9ab30bc..bd74ede 100755 --- a/app/Lobby/Coordinator.js +++ b/app/Lobby/Coordinator.js @@ -1,13 +1,11 @@ define([ "Lobby/User", "Game/Server/Channel", - "Lobby/PipeToChannel" - "child_process" + "Lobby/PipeToChannel", + "Game/Core/NotificationCenter" ], -function (User, Channel, PipeToChannel, childProcess) { - - var fork = childProcess.fork; +function (User, Channel, PipeToChannel, NotificationCenter) { function Coordinator () { this.channels = {}; diff --git a/app/Lobby/PipeToChannel.js b/app/Lobby/PipeToChannel.js index bf8f54b..fbfffd3 100755 --- a/app/Lobby/PipeToChannel.js +++ b/app/Lobby/PipeToChannel.js @@ -1,8 +1,11 @@ define([ - "Game/Core/NotificationCenter" + //"Game/Core/NotificationCenter", + "child_process" ], -function (NotificationCenter) { +function (childProcess) { + + var fork = childProcess.fork; function PipeToChannel (channelName) { diff --git a/channel.js b/channel.js index f4102ce..4d2a0fd 100755 --- a/channel.js +++ b/channel.js @@ -1,17 +1,19 @@ var requirejs = require('requirejs'); requirejs.config({ + nodeRequire: require, baseUrl: 'app' }); var inspector = {}; requirejs([ - "Game/Server/LobbyPipe" + "Game/Server/PipeToLobby", + "Game/Core/NotificationCenter" ], -function (LobbyPipe) { - var lobbyPipe = new LobbyPipe(process); +function (PipeToLobby, nc) { + var PipeToLobby = new PipeToLobby(process); - inspector.lobbyPipe = lobbyPipe; + inspector.PipeToLobby = PipeToLobby; }); \ No newline at end of file