mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
refactoring
This commit is contained in:
parent
39af52dd14
commit
c256f8a729
8 changed files with 87 additions and 160 deletions
|
|
@ -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