mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
merged from master (use strict)
This commit is contained in:
commit
1f8f0ef6e1
76 changed files with 157 additions and 60 deletions
|
|
@ -4,6 +4,8 @@ define([
|
|||
],
|
||||
|
||||
function (Parent, Settings) {
|
||||
|
||||
"use strict";
|
||||
|
||||
function GamepadInput(playerController) {
|
||||
this.playerController = playerController;
|
||||
|
|
|
|||
|
|
@ -1,55 +0,0 @@
|
|||
define([
|
||||
"Game/Client/Control/Key"
|
||||
],
|
||||
|
||||
function (Key) {
|
||||
|
||||
function KeyboardInput () {
|
||||
this._registry = {};
|
||||
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) {
|
||||
var key = new Key();
|
||||
if(onKeyDown) key.setKeyDownFunction(onKeyDown);
|
||||
if(onKeyUp) key.setKeyUpFunction(onKeyUp);
|
||||
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()) {
|
||||
var callback = key.getKeyDownFunction();
|
||||
if(callback) callback();
|
||||
key.setActive(true);
|
||||
}
|
||||
|
||||
// Prevent tab from changing focus
|
||||
if(e.keyCode == 9) return false;
|
||||
}
|
||||
|
||||
KeyboardInput.prototype._onKeyUp = function (e) {
|
||||
var key = this._getKeyByKeyCode(e.keyCode);
|
||||
if (key && key.getActive()) {
|
||||
var callback = key.getKeyUpFunction();
|
||||
if(callback) callback();
|
||||
key.setActive(false);
|
||||
}
|
||||
|
||||
// Prevent tab from changing focus
|
||||
if(e.keyCode == 9) return false;
|
||||
}
|
||||
|
||||
return KeyboardInput;
|
||||
});
|
||||
|
|
@ -7,6 +7,8 @@ define([
|
|||
|
||||
function (Parent, Nc, KeyboardAndMouse, Gamepad) {
|
||||
|
||||
"use strict";
|
||||
|
||||
function PlayerController (me) {
|
||||
|
||||
Parent.call(this, me);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue