diff --git a/client/garageserver.io.js b/client/garageserver.io.js index f82497c..a1dfcba 100644 --- a/client/garageserver.io.js +++ b/client/garageserver.io.js @@ -1,13 +1,27 @@ -window.GarageServerIO = (function (socketio) { +window.GarageServerIO = (function (window, socketio) { var io = socketio, - connectToGarageServer = function (path) { + garageServerGame = null, + + connectToGarageServer = function (path, options) { io.connect(path + '/garageserver'); + }, + + startGarageServerGame = function (options) { + garageServerGame = new GarageServerGame(options); + }; + + function GarageServerGame (options) { + + } + + GarageServerGame.prototype.update = function () { + }; return { connectToGarageServer: connectToGarageServer }; -}) (io); \ No newline at end of file +}) (window, io); \ No newline at end of file diff --git a/lib/server/garageserver.io.js b/lib/server/garageserver.io.js index 448d462..a809a10 100644 --- a/lib/server/garageserver.io.js +++ b/lib/server/garageserver.io.js @@ -2,21 +2,21 @@ var garageServerGame = require('./garageservergame'); function GarageServer (socketio, options) { this.io = socketio; - this.registerSocketEvents(this.io); + this.registerSocketEvents(options); this.game = new garageServerGame.createGame(options); } -GarageServer.prototype.registerSocketEvents = function () { +GarageServer.prototype.registerSocketEvents = function (options) { this.io.of('/garageserver.io').on('connection', function (socket) { - this.onPlayerConnect(socket); + this.onPlayerConnect(socket, options.onConnection); }.bind(this)); this.io.of('/garageserver.io').on('disconnect', function (socket) { - this.onPlayerDisconnect(socket); + this.onPlayerDisconnect(socket, options.onDisconnect); }.bind(this)); this.io.of('/garageserver.io').on('input', function (socket) { - this.onPlayerInput(socket); + this.onPlayerInput(socket, options.onInput); }.bind(this)); }; diff --git a/lib/server/garageservergame.js b/lib/server/garageservergame.js index 8af72fc..b529bbb 100644 --- a/lib/server/garageservergame.js +++ b/lib/server/garageservergame.js @@ -1,8 +1,14 @@ function GarageServerGame (options) { - + + this.physicsIntervalId = setInterval(this.updatePhysics, options.physicsInterval ? options.physicsInterval : 15); + this.playersIntervalId = setInterval(this.updatePlayers, options.playersInterval ? options.playersInterval : 45); } -GarageServerGame.prototype.update = function () { +GarageServerGame.prototype.updatePlayers = function () { + +}; + +GarageServerGame.prototype.updatePhysics = function () { };