mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 18:47:35 +00:00
refactoring
This commit is contained in:
parent
39af52dd14
commit
c256f8a729
8 changed files with 87 additions and 160 deletions
|
|
@ -18,23 +18,13 @@
|
|||
|
||||
this.gameController = new GameController(this);
|
||||
this.gameController.loadLevel("default.json");
|
||||
|
||||
|
||||
|
||||
var self = this;
|
||||
NotificationCenter.on("processGameCommandFromUser", function (topic, args) {
|
||||
self.processGameCommandFromUser.apply(self, args);
|
||||
});
|
||||
|
||||
|
||||
NotificationCenter.on('channel/message', function (message) {
|
||||
ProtocolHelper.runCommands(message.data, function (command, options) {
|
||||
self[command].call(self, options);
|
||||
});
|
||||
NotificationCenter.on('channel/controlCommand', function (message) {
|
||||
ProtocolHelper.applyCommand(message.data, self);
|
||||
});
|
||||
|
||||
NotificationCenter.on('sendControlCommandToAllUsers', this.sendControlCommandToAllUsers, this);
|
||||
NotificationCenter.on('channel/users/all/except', this.sendControlCommandToAllUsersExcept, this);
|
||||
NotificationCenter.on('sendControlCommandToAllUsersExcept', this.sendControlCommandToAllUsersExcept, this);
|
||||
|
||||
console.checkpoint('channel ' + name + ' created');
|
||||
}
|
||||
|
|
@ -43,7 +33,10 @@
|
|||
return true;
|
||||
}
|
||||
|
||||
Channel.prototype.addUser = function (userId) {
|
||||
|
||||
// Channel command callbacks
|
||||
|
||||
Channel.prototype.onAddUser = function (userId) {
|
||||
var user = new User(userId, this);
|
||||
var others = Object.keys(this.users);
|
||||
|
||||
|
|
@ -52,15 +45,15 @@
|
|||
NotificationCenter.trigger('user/joined', user);
|
||||
}
|
||||
|
||||
|
||||
Channel.prototype.releaseUser = function (userId) {
|
||||
Channel.prototype.onReleaseUser = function (userId) {
|
||||
var user = this.users[userId];
|
||||
//this.gameController.userIdLeft(user.id);
|
||||
|
||||
this.sendControlCommandToAllUsersExcept("userLeft", user.id, user);
|
||||
delete this.users[user.id];
|
||||
}
|
||||
|
||||
|
||||
// Sending commands
|
||||
|
||||
Channel.prototype.sendControlCommandToAllUsers = function (command, options) {
|
||||
for(var id in this.users) {
|
||||
this.users[id].sendControlCommand(command, options);
|
||||
|
|
@ -74,11 +67,7 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
Channel.prototype.processGameCommandFromUser = function (command, options, user) {
|
||||
this.gameController.progressGameCommandFromUser(command, options, user);
|
||||
}
|
||||
*/
|
||||
|
||||
return Channel;
|
||||
|
||||
});
|
||||
|
|
@ -2,7 +2,7 @@ define([
|
|||
"Game/Core/GameController",
|
||||
"Game/Core/Physics/Engine",
|
||||
"Game/Config/Settings",
|
||||
"Game/Core/Control/InputController",
|
||||
"Game/Server/Control/InputController",
|
||||
"Lib/Utilities/RequestAnimFrame",
|
||||
"Game/Core/NotificationCenter"
|
||||
],
|
||||
|
|
@ -68,9 +68,6 @@ function (Parent, PhysicsEngine, Settings, InputController, requestAnimFrame, No
|
|||
do {
|
||||
var userData = body.GetUserData();
|
||||
|
||||
|
||||
|
||||
|
||||
if(userData && body.IsAwake()) {
|
||||
update[userData] = {
|
||||
p: body.GetPosition(),
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ function (NotificationCenter, Channel) {
|
|||
};
|
||||
|
||||
PipeToLobby.prototype.onMessage = function (message) {
|
||||
NotificationCenter.trigger(message.recipient + '/message', message);
|
||||
NotificationCenter.trigger(message.recipient + '/controlCommand', message);
|
||||
}
|
||||
|
||||
return PipeToLobby;
|
||||
|
|
|
|||
|
|
@ -23,15 +23,27 @@ function(Parent, NotificationCenter, ProtocolHelper) {
|
|||
self.sendControlCommand("joinSuccess", options);
|
||||
});
|
||||
|
||||
NotificationCenter.on('user/' + this.id + "/message", function(message) { // FIXME: right now only game commands?
|
||||
ProtocolHelper.runCommands(message.data, function (command, options) {
|
||||
self.gameCommand(command, options);
|
||||
});
|
||||
NotificationCenter.on('user/' + this.id + "/controlCommand", function(message) { // FIXME: right now only game commands?
|
||||
ProtocolHelper.applyCommand(message.data, self);
|
||||
});
|
||||
}
|
||||
|
||||
User.prototype = Object.create(Parent.prototype);
|
||||
|
||||
User.prototype.setPlayer = function(player) {
|
||||
this.player = player;
|
||||
};
|
||||
|
||||
|
||||
// User command callbacks
|
||||
|
||||
User.prototype.onGameCommand = function(command) {
|
||||
this.player.inputController.applyCommand(command);
|
||||
};
|
||||
|
||||
|
||||
// Sending commands
|
||||
|
||||
User.prototype.sendControlCommand = function(command, options) {
|
||||
var recipient = "user/" + this.id;
|
||||
var data = ProtocolHelper.encodeCommand(command, options);
|
||||
|
|
@ -44,13 +56,6 @@ function(Parent, NotificationCenter, ProtocolHelper) {
|
|||
this.sendControlCommand("gameCommand", data);
|
||||
};
|
||||
|
||||
User.prototype.gameCommand = function(command, options) {
|
||||
this.player.inputController[command].call(this.player.inputController);
|
||||
};
|
||||
|
||||
User.prototype.setPlayer = function(player) {
|
||||
this.player = player;
|
||||
};
|
||||
|
||||
return User;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue