This commit is contained in:
Jeena 2014-02-10 16:11:01 +01:00
parent 7a59e175e0
commit 89c5e4a5d8
6 changed files with 64 additions and 25 deletions

View file

@ -14,11 +14,6 @@ function (ProtocolHelper, GameController, User, NotificationCenter, Settings, Do
this.gameController = null;
this.users = {};
this.init();
}
Networker.prototype.init = function () {
this.socketLink.on('connect', this.onConnect.bind(this));
this.socketLink.on('disconnect', this.onDisconnect.bind(this));
@ -33,7 +28,6 @@ function (ProtocolHelper, GameController, User, NotificationCenter, Settings, Do
NotificationCenter.on("sendGameCommand", this.sendGameCommand, this);
}
// Socket callbacks
Networker.prototype.onConnect = function () {
@ -49,6 +43,10 @@ function (ProtocolHelper, GameController, User, NotificationCenter, Settings, Do
}
Networker.prototype.onJoinSuccess = function (options) {
NotificationCenter.on("game/level/loaded", function() {
this.onLevelLoaded(options);
}, this);
this.gameController = new GameController();
this.gameController.loadLevel(options.levelUid);
@ -61,6 +59,10 @@ function (ProtocolHelper, GameController, User, NotificationCenter, Settings, Do
}
}
this.initPing();
}
Networker.prototype.onLevelLoaded = function(options) {
if (options.spawnedPlayers) {
for(var i = 0; i < options.spawnedPlayers.length; i++) {
this.gameController.onSpawnPlayer(options.spawnedPlayers[i]);
@ -70,9 +72,7 @@ function (ProtocolHelper, GameController, User, NotificationCenter, Settings, Do
if (options.worldUpdate) {
this.gameController.onWorldUpdate(options.worldUpdate);
}
this.initPing();
}
};
Networker.prototype.initPing = function() {