mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
some more renaming
This commit is contained in:
parent
9de3147406
commit
bd45f538c7
34 changed files with 0 additions and 0 deletions
61
app/Game/Client/Control/Key.js
Executable file
61
app/Game/Client/Control/Key.js
Executable file
|
|
@ -0,0 +1,61 @@
|
|||
define(function(){
|
||||
|
||||
function Key () {
|
||||
this._active = false;
|
||||
this._activityUpdateStatus = false;
|
||||
this._activityUpdateNeeded = false;
|
||||
this._keyDownFunction = null;
|
||||
this._keyUpFunction = null;
|
||||
this._keyFrameFunction = null;
|
||||
}
|
||||
|
||||
Key.prototype.setActivityUpdateStatus = function(active) {
|
||||
this._activityUpdateStatus = active;
|
||||
}
|
||||
|
||||
Key.prototype.getActivityUpdateStatus = function() {
|
||||
return this._activityUpdateStatus;
|
||||
}
|
||||
|
||||
Key.prototype.setActivityUpdateNeeded = function(need) {
|
||||
this._activityUpdateNeeded = need;
|
||||
}
|
||||
|
||||
Key.prototype.getActivityUpdateNeeded = function() {
|
||||
return this._activityUpdateNeeded;
|
||||
}
|
||||
|
||||
Key.prototype.setActive = function(active) {
|
||||
this._active = active;
|
||||
}
|
||||
|
||||
Key.prototype.getActive = function() {
|
||||
return this._active;
|
||||
}
|
||||
|
||||
Key.prototype.setKeyDownFunction = function(f) {
|
||||
this._keyDownFunction = f;
|
||||
}
|
||||
|
||||
Key.prototype.getKeyDownFunction = function() {
|
||||
return this._keyDownFunction;
|
||||
}
|
||||
|
||||
Key.prototype.setKeyUpFunction = function(f) {
|
||||
this._keyUpFunction = f;
|
||||
}
|
||||
|
||||
Key.prototype.getKeyUpFunction = function() {
|
||||
return this._keyUpFunction;
|
||||
}
|
||||
|
||||
Key.prototype.setKeyFrameFunction = function(f) {
|
||||
this._keyFrameFunction = f;
|
||||
}
|
||||
|
||||
Key.prototype.getKeyFrameFunction = function() {
|
||||
return this._keyFrameFunction;
|
||||
}
|
||||
|
||||
return Key;
|
||||
});
|
||||
94
app/Game/Client/Control/KeyboardController.js
Executable file
94
app/Game/Client/Control/KeyboardController.js
Executable file
|
|
@ -0,0 +1,94 @@
|
|||
define(["Chuck/Control/InputController", "Chuck/Control/KeyboardInput"], function(InputController, KeyboardInput){
|
||||
|
||||
function InputControlUnit(me, clientProcessor) {
|
||||
|
||||
this.clientProcessor = clientProcessor;
|
||||
this.inputController = new InputController(me);
|
||||
|
||||
this.keyboardInput = new KeyboardInput(this);
|
||||
|
||||
var keys = {
|
||||
w:87,
|
||||
a:65,
|
||||
s:83,
|
||||
d:68,
|
||||
|
||||
up: 38,
|
||||
left: 37,
|
||||
down: 40,
|
||||
right: 39
|
||||
}
|
||||
|
||||
this.init(keys);
|
||||
}
|
||||
|
||||
InputControlUnit.prototype.init = function(keys) {
|
||||
|
||||
this.keyboardInput.registerKey(keys.a, 'moveLeft', 'stop', 'moveLeft');
|
||||
this.keyboardInput.registerKey(keys.left, 'moveLeft', 'stop', 'moveLeft');
|
||||
|
||||
this.keyboardInput.registerKey(keys.d, 'moveRight', 'stop', 'moveRight');
|
||||
this.keyboardInput.registerKey(keys.right, 'moveRight', 'stop', 'moveRight');
|
||||
|
||||
this.keyboardInput.registerKey(keys.w, 'jump', 'jumped', 'jumping');
|
||||
this.keyboardInput.registerKey(keys.up, 'jump', 'jumped', 'jumping');
|
||||
|
||||
this.keyboardInput.registerKey(keys.s, 'duck', 'standUp', 'duck');
|
||||
this.keyboardInput.registerKey(keys.down, 'duck', 'standUp', 'duck');
|
||||
|
||||
this.keyboardInput.registerKey(keys.s, 'activateShift', 'activateShift', 'deactivateShift');
|
||||
this.keyboardInput.registerKey(keys.down, 'activateShift', 'activateShift', 'deactivateShift');
|
||||
}
|
||||
|
||||
InputControlUnit.prototype.moveLeft = function() {
|
||||
this.inputController.moveLeft();
|
||||
this.clientProcessor.sendGameCommand('moveLeft');
|
||||
}
|
||||
|
||||
InputControlUnit.prototype.moveRight = function() {
|
||||
this.inputController.moveRight();
|
||||
this.clientProcessor.sendGameCommand('moveRight');
|
||||
}
|
||||
|
||||
InputControlUnit.prototype.stop = function() {
|
||||
this.inputController.stop();
|
||||
this.clientProcessor.sendGameCommand('stop');
|
||||
}
|
||||
|
||||
InputControlUnit.prototype.jump = function() {
|
||||
this.inputController.jump();
|
||||
this.clientProcessor.sendGameCommand('jump');
|
||||
}
|
||||
|
||||
InputControlUnit.prototype.jumped = function() {
|
||||
this.inputController.jumped();
|
||||
}
|
||||
|
||||
InputControlUnit.prototype.jumping = function() {
|
||||
this.inputController.jumping();
|
||||
}
|
||||
|
||||
InputControlUnit.prototype.duck = function() {
|
||||
this.inputController.duck();
|
||||
this.clientProcessor.sendGameCommand('duck');
|
||||
}
|
||||
|
||||
InputControlUnit.prototype.standUp = function() {
|
||||
this.inputController.standUp();
|
||||
}
|
||||
|
||||
InputControlUnit.prototype.activateShift = function() {
|
||||
this.inputController.activateShift();
|
||||
this.clientProcessor.sendGameCommand('activateShift');
|
||||
}
|
||||
|
||||
InputControlUnit.prototype.deactivateShift = function() {
|
||||
this.inputController.deactivateShift();
|
||||
}
|
||||
|
||||
InputControlUnit.prototype.update = function() {
|
||||
this.keyboardInput.update();
|
||||
}
|
||||
|
||||
return InputControlUnit;
|
||||
});
|
||||
78
app/Game/Client/Control/KeyboardInput.js
Executable file
78
app/Game/Client/Control/KeyboardInput.js
Executable file
|
|
@ -0,0 +1,78 @@
|
|||
define(["Chuck/Control/Key"], function(Key){
|
||||
|
||||
function KeyboardInput (inputControlUnit) {
|
||||
|
||||
this._registry = {};
|
||||
this._inputControlUnit = inputControlUnit;
|
||||
|
||||
this.init();
|
||||
}
|
||||
|
||||
KeyboardInput.prototype.init = function() {
|
||||
// Using window is ok here because it only runs in the browser
|
||||
window.onkeydown = this._onKeyDown.bind(this);
|
||||
window.onkeyup = this._onKeyUp.bind(this);
|
||||
}
|
||||
|
||||
KeyboardInput.prototype.registerKey = function(keyCode, onKeyDown, onKeyUp, onKeyFrame) {
|
||||
var key = new Key();
|
||||
key.setKeyDownFunction(onKeyDown);
|
||||
key.setKeyUpFunction(onKeyUp);
|
||||
key.setKeyFrameFunction(onKeyFrame);
|
||||
this._registry[keyCode] = key;
|
||||
}
|
||||
|
||||
KeyboardInput.prototype._getKeyByKeyCode = function(keyCode) {
|
||||
return this._registry[keyCode];
|
||||
}
|
||||
|
||||
KeyboardInput.prototype._onKeyDown = function(e) {
|
||||
var key = this._getKeyByKeyCode(e.keyCode);
|
||||
if (key && key.getActive() == false) {
|
||||
key.setActivityUpdateStatus(true);
|
||||
key.setActivityUpdateNeeded(true);
|
||||
}
|
||||
}
|
||||
|
||||
KeyboardInput.prototype._onKeyUp = function(e) {
|
||||
var key = this._getKeyByKeyCode(e.keyCode);
|
||||
if (key != null) {
|
||||
key.setActivityUpdateStatus(false);
|
||||
key.setActivityUpdateNeeded(true);
|
||||
}
|
||||
}
|
||||
|
||||
KeyboardInput.prototype.update = function() {
|
||||
var callback = null;
|
||||
var self = this;
|
||||
|
||||
for (var keyCode in this._registry) {
|
||||
var key = this._registry[keyCode];
|
||||
|
||||
if (key.getActivityUpdateNeeded()) {
|
||||
if (key.getActivityUpdateStatus() == true) {
|
||||
callback = key.getKeyDownFunction();
|
||||
key.setActive(true);
|
||||
} else {
|
||||
callback = key.getKeyUpFunction();
|
||||
key.setActive(false);
|
||||
}
|
||||
key.setActivityUpdateNeeded(false);
|
||||
}
|
||||
|
||||
if (callback) {
|
||||
self._inputControlUnit[callback]();
|
||||
} else {
|
||||
if (key.getActive()) {
|
||||
callback = key.getKeyFrameFunction();
|
||||
if (callback) {
|
||||
self._inputControlUnit[callback]();
|
||||
}
|
||||
}
|
||||
}
|
||||
callback = null;
|
||||
}
|
||||
}
|
||||
|
||||
return KeyboardInput;
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue