This commit is contained in:
Jeena 2014-03-02 01:15:33 +01:00
parent 810a74a28b
commit 39bdac0d7b
12 changed files with 118 additions and 100 deletions

View file

@ -46,22 +46,26 @@
// Channel command callbacks
Channel.prototype.onAddUser = function (userId) {
Channel.prototype.onAddUser = function (options) {
var self = this;
if(!this.gameController.level || !this.gameController.level.isLoaded) {
var token = Nc.on("game/level/loaded", function() {
self.sendJoinSuccess(userId);
self.sendJoinSuccess(options);
Nc.off(token);
});
} else {
self.sendJoinSuccess(userId);
self.sendJoinSuccess(options);
}
}
Channel.prototype.sendJoinSuccess = function(userId) {
var user = new User(userId, this);
var joinedUsers = Object.keys(this.users);
Channel.prototype.sendJoinSuccess = function(options) {
var user = new User(options.id, options);
var joinedUsers = [];
for(var userId in this.users) {
joinedUsers.push(this.users[userId].options)
}
var levelUid = null;
if(this.gameController.level) {
@ -71,14 +75,16 @@
this.users[user.id] = user;
var options = {
userId: user.id,
channelName: this.name,
user: user.options,
joinedUsers: joinedUsers,
levelUid: levelUid
};
Nc.trigger('user/' + user.id + "/joinSuccess", options);
Nc.trigger('user/joined', user);
//Nc.trigger('user/' + user.id + "/joinSuccess", options);
user.sendControlCommand("joinSuccess", options);
Nc.trigger('user/joined', user);
this.broadcastControlCommandExcept("userJoined", user.options, user);
};
Channel.prototype.onReleaseUser = function (userId) {

View file

@ -88,15 +88,6 @@ function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, N
}, respawnTime * 1000);
};
/*
GameController.prototype.createPlayer = function(user) {
var player = new Player(user.id, this.physicsEngine);
player.setPlayerController(new PlayerController(player))
return player;
};
*/
GameController.prototype.updateWorld = function () {
var update = this.getWorldUpdateObject(false);

View file

@ -5,8 +5,8 @@ define([
function (Parent, Nc) {
function Player(id, physicsEngine) {
Parent.call(this, id, physicsEngine);
function Player(id, physicsEngine, user) {
Parent.call(this, id, physicsEngine, user);
}
Player.prototype = Object.create(Parent.prototype);

View file

@ -7,20 +7,13 @@ define([
function(Parent, Nc, ProtocolHelper, ProtocolParser) {
function User(id, channel) {
Parent.call(this, id);
function User(id, options) {
Parent.call(this, id, options);
this.channel = channel;
this.player = null;
this.isReady = false;
var self = this;
Nc.on('user/joined', function(user) { // FIXME: use sendToAllUsersExcept instead
if(user.id != self.id) {
self.sendControlCommand("userJoined", user.id);
}
});
Nc.on('user/' + this.id + "/joinSuccess", function(options) {
self.sendControlCommand("joinSuccess", options);
});