From a5b072955f7d16ffe751661bb8367e62070ed102 Mon Sep 17 00:00:00 2001 From: Jeremiah Billmann Date: Tue, 21 May 2013 20:19:27 -0400 Subject: [PATCH] Progress: Server loops & player input; --- lib/server/garageserver.io.js | 10 ++++++---- lib/server/garageservergame.js | 9 +++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/server/garageserver.io.js b/lib/server/garageserver.io.js index 8c79b3b..1755ccf 100644 --- a/lib/server/garageserver.io.js +++ b/lib/server/garageserver.io.js @@ -27,26 +27,28 @@ GarageServer.prototype.registerSocketEvents = function (options) { console.log('garageserver.io:: socket ping'); self.onPlayerInput(socket, options); }); - }); }; GarageServer.prototype.onPlayerConnect = function (socket, options) { this.game.addPlayer(socket); if(options.onPlayerConnect) { - options(socket); + options.onPlayerConnect(socket); } }; GarageServer.prototype.onPlayerDisconnect = function (socket, options) { this.game.removePlayer(socket); if(options.onPlayerDisconnect) { - options(socket); + options.onPlayerDisconnect(socket); } }; GarageServer.prototype.onPlayerInput = function (socket, input, options) { - + this.game.addPlayerInput(socket, input); + if(options.onPlayerInput) { + options.onPlayerInput(socket, input); + } }; GarageServer.prototype.onPing = function(socket, options) { diff --git a/lib/server/garageservergame.js b/lib/server/garageservergame.js index 473481a..a372342 100644 --- a/lib/server/garageservergame.js +++ b/lib/server/garageservergame.js @@ -36,6 +36,15 @@ GarageServerGame.prototype.removePlayer = function (client) { } }; +GarageServerGame.prototype.addPlayerInput = function (client, input) { + for(var i = 0; i < this.players.length; i ++) { + if(this.players[i].id === client.id) { + this.players[i].inputs.push(input); + return; + } + } +}; + exports.createGame = function (options){ return new GarageServerGame(options); }; \ No newline at end of file