mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
restructured repository
This commit is contained in:
parent
cc6279eac9
commit
080a2e410c
38 changed files with 87 additions and 26 deletions
72
tests/game-draft/js/Chuck/Control/KeyboardInput.js
Executable file
72
tests/game-draft/js/Chuck/Control/KeyboardInput.js
Executable file
|
|
@ -0,0 +1,72 @@
|
|||
Chuck.Control.KeyboardInput = function() {
|
||||
this._registry = {};
|
||||
this._inputControlUnit = null;
|
||||
|
||||
this.init();
|
||||
}
|
||||
|
||||
Chuck.Control.KeyboardInput.prototype.init = function() {
|
||||
$(window).keydown($.proxy(this._onKeyDown, this));
|
||||
$(window).keyup($.proxy(this._onKeyUp, this));
|
||||
}
|
||||
|
||||
Chuck.Control.KeyboardInput.prototype.setInputControlUnit = function(inputControlUnit) {
|
||||
this._inputControlUnit = inputControlUnit;
|
||||
}
|
||||
|
||||
Chuck.Control.KeyboardInput.prototype.registerKey = function(keyCode, onKeyDown, onKeyUp, onKeyFrame) {
|
||||
var key = new Chuck.Control.Key();
|
||||
key.setKeyDownFunction(onKeyDown);
|
||||
key.setKeyUpFunction(onKeyUp);
|
||||
key.setKeyFrameFunction(onKeyFrame);
|
||||
this._registry[keyCode] = key;
|
||||
}
|
||||
|
||||
Chuck.Control.KeyboardInput.prototype._getKeyByKeyCode = function(keyCode) {
|
||||
return this._registry[keyCode];
|
||||
}
|
||||
|
||||
Chuck.Control.KeyboardInput.prototype._onKeyDown = function(e) {
|
||||
var key = this._getKeyByKeyCode(e.keyCode);
|
||||
if (key && key.getActive() == false) {
|
||||
key.setActivityUpdateStatus(true);
|
||||
key.setActivityUpdateNeeded(true);
|
||||
}
|
||||
}
|
||||
|
||||
Chuck.Control.KeyboardInput.prototype._onKeyUp = function(e) {
|
||||
var key = this._getKeyByKeyCode(e.keyCode);
|
||||
if (key != null) {
|
||||
key.setActivityUpdateStatus(false);
|
||||
key.setActivityUpdateNeeded(true);
|
||||
}
|
||||
}
|
||||
|
||||
Chuck.Control.KeyboardInput.prototype.update = function() {
|
||||
var callback = null;
|
||||
var self = this;
|
||||
$.each(this._registry, function(keyCode, key) {
|
||||
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;
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue