fixed #97 chuck stops when he shouldnt, also removed f/g for handActionRequestLeft and Right, since we don't need it for DebugDraw anymore.

This commit is contained in:
logsol 2015-03-10 14:42:54 +01:00
parent 5f5fec5b10
commit 61e66f5796
3 changed files with 61 additions and 52 deletions

View file

@ -18,19 +18,7 @@ function (Parent, KeyboardInput, DomController, Settings, Swiper) {
this.swiper = null;
this.lastLookDirection = 1;
this.playerController = playerController;
this.keyboardInit();
this.mouseInit();
}
KeyboardAndMouse.prototype = Object.create(Parent.prototype);
KeyboardAndMouse.prototype.keyboardInit = function() {
this.keyboardInput = new KeyboardInput();
var self = this;
var keys = {
this.keys = {
w:87,
a:65,
s:83,
@ -56,29 +44,39 @@ function (Parent, KeyboardInput, DomController, Settings, Swiper) {
zero: 48
}
this.playerController = playerController;
this.keyboardInit();
this.mouseInit();
}
KeyboardAndMouse.prototype = Object.create(Parent.prototype);
KeyboardAndMouse.prototype.keyboardInit = function() {
this.keyboardInput = new KeyboardInput();
var self = this;
function bind2Pc(methodName) {
return self.playerController[methodName].bind(self.playerController);
}
this.keyboardInput.registerKey(keys.a, this.moveLeft.bind(this), bind2Pc('stop'));
this.keyboardInput.registerKey(keys.left, this.moveLeft.bind(this), bind2Pc('stop'));
this.keyboardInput.registerKey(keys.d, this.moveRight.bind(this), bind2Pc('stop'));
this.keyboardInput.registerKey(keys.right, this.moveRight.bind(this), bind2Pc('stop'));
this.keyboardInput.registerKey(keys.w, bind2Pc('jump'), bind2Pc('jumpStop'));
this.keyboardInput.registerKey(keys.up, bind2Pc('jump'), bind2Pc('jumpStop'));
this.keyboardInput.registerKey(keys.space, bind2Pc('jump'), bind2Pc('jumpStop'));
this.keyboardInput.registerKey(keys.plus, bind2Pc('zoomIn'));
this.keyboardInput.registerKey(keys.plusfx, bind2Pc('zoomIn'));
this.keyboardInput.registerKey(keys.minus, bind2Pc('zoomOut'));
this.keyboardInput.registerKey(keys.minusfx, bind2Pc('zoomOut'));
this.keyboardInput.registerKey(keys.zero, bind2Pc('zoomReset'));
this.keyboardInput.registerKey(keys.tab, bind2Pc('showInfo'), bind2Pc('hideInfo'));
this.keyboardInput.registerKey(keys.f, bind2Pc('handActionLeft'));
this.keyboardInput.registerKey(keys.g, bind2Pc('handActionRight'));
this.keyboardInput.registerKey(keys.k, bind2Pc('suicide'));
this.keyboardInput.registerKey(this.keys.a, this.moveLeft.bind(this), this.stop.bind(this));
this.keyboardInput.registerKey(this.keys.left, this.moveLeft.bind(this), this.stop.bind(this));
this.keyboardInput.registerKey(this.keys.d, this.moveRight.bind(this), this.stop.bind(this));
this.keyboardInput.registerKey(this.keys.right, this.moveRight.bind(this), this.stop.bind(this));
this.keyboardInput.registerKey(this.keys.w, bind2Pc('jump'), bind2Pc('jumpStop'));
this.keyboardInput.registerKey(this.keys.up, bind2Pc('jump'), bind2Pc('jumpStop'));
this.keyboardInput.registerKey(this.keys.space, bind2Pc('jump'), bind2Pc('jumpStop'));
this.keyboardInput.registerKey(this.keys.plus, bind2Pc('zoomIn'));
this.keyboardInput.registerKey(this.keys.plusfx, bind2Pc('zoomIn'));
this.keyboardInput.registerKey(this.keys.minus, bind2Pc('zoomOut'));
this.keyboardInput.registerKey(this.keys.minusfx, bind2Pc('zoomOut'));
this.keyboardInput.registerKey(this.keys.zero, bind2Pc('zoomReset'));
this.keyboardInput.registerKey(this.keys.tab, bind2Pc('showInfo'), bind2Pc('hideInfo'));
this.keyboardInput.registerKey(this.keys.k, bind2Pc('suicide'));
this.keyboardInput.registerKey(
keys.shift,
this.keys.shift,
this.activateModifier.bind(this),
this.deactivateModifier.bind(this)
);
@ -100,6 +98,27 @@ function (Parent, KeyboardInput, DomController, Settings, Swiper) {
this.playerController.moveRight();
};
KeyboardAndMouse.prototype.stop = function(e) {
var isMovingLeft = this.keyboardInput.getKeyByKeyCode(this.keys.a).getActive()
|| this.keyboardInput.getKeyByKeyCode(this.keys.left).getActive();
var isMovingRight = this.keyboardInput.getKeyByKeyCode(this.keys.d).getActive()
|| this.keyboardInput.getKeyByKeyCode(this.keys.right).getActive();
if (isMovingLeft) {
this.moveLeft();
return;
}
if (isMovingRight) {
this.moveRight();
return;
}
this.playerController.stop();
};
KeyboardAndMouse.prototype.mouseInit = function() {
var canvas = DomController.getCanvas();
var self = this;

View file

@ -5,46 +5,46 @@ define([
function (Key) {
function KeyboardInput () {
this._registry = {};
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);
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;
this.registry[keyCode] = key;
}
KeyboardInput.prototype._getKeyByKeyCode = function (keyCode) {
return this._registry[keyCode];
KeyboardInput.prototype.getKeyByKeyCode = function (keyCode) {
return this.registry[keyCode];
}
KeyboardInput.prototype._onKeyDown = function (e) {
var key = this._getKeyByKeyCode(e.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);
if(callback) callback();
}
// Prevent tab from changing focus
if(e.keyCode == 9) return false;
}
KeyboardInput.prototype._onKeyUp = function (e) {
var key = this._getKeyByKeyCode(e.keyCode);
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);
if(callback) callback();
}
// Prevent tab from changing focus

View file

@ -62,16 +62,6 @@ function (Parent, Nc, KeyboardAndMouse, Gamepad, PointerLockManager) {
Nc.trigger(Nc.ns.client.to.server.gameCommand.send, 'lookAt', options);
};
PlayerController.prototype.handActionLeft = function() {
if (!PointerLockManager.isLocked()) return;
this.handActionRequest(-0.5, 0.5);
};
PlayerController.prototype.handActionRight = function() {
if (!PointerLockManager.isLocked()) return;
this.handActionRequest(0.5, 0.5);
};
PlayerController.prototype.suicide = function() {
if (!PointerLockManager.isLocked()) return;
Nc.trigger(Nc.ns.client.to.server.gameCommand.send, "suicide");