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

View file

@ -5,46 +5,46 @@ define([
function (Key) { function (Key) {
function KeyboardInput () { function KeyboardInput () {
this._registry = {}; this.registry = {};
this.init(); this.init();
} }
KeyboardInput.prototype.init = function () { KeyboardInput.prototype.init = function () {
// Using window is ok here because it only runs in the browser // Using window is ok here because it only runs in the browser
window.onkeydown = this._onKeyDown.bind(this); window.onkeydown = this.onKeyDown.bind(this);
window.onkeyup = this._onKeyUp.bind(this); window.onkeyup = this.onKeyUp.bind(this);
} }
KeyboardInput.prototype.registerKey = function (keyCode, onKeyDown, onKeyUp) { KeyboardInput.prototype.registerKey = function (keyCode, onKeyDown, onKeyUp) {
var key = new Key(); var key = new Key();
if(onKeyDown) key.setKeyDownFunction(onKeyDown); if(onKeyDown) key.setKeyDownFunction(onKeyDown);
if(onKeyUp) key.setKeyUpFunction(onKeyUp); if(onKeyUp) key.setKeyUpFunction(onKeyUp);
this._registry[keyCode] = key; this.registry[keyCode] = key;
} }
KeyboardInput.prototype._getKeyByKeyCode = function (keyCode) { KeyboardInput.prototype.getKeyByKeyCode = function (keyCode) {
return this._registry[keyCode]; return this.registry[keyCode];
} }
KeyboardInput.prototype._onKeyDown = function (e) { KeyboardInput.prototype.onKeyDown = function (e) {
var key = this._getKeyByKeyCode(e.keyCode); var key = this.getKeyByKeyCode(e.keyCode);
if (key && !key.getActive()) { if (key && !key.getActive()) {
var callback = key.getKeyDownFunction(); var callback = key.getKeyDownFunction();
if(callback) callback();
key.setActive(true); key.setActive(true);
if(callback) callback();
} }
// Prevent tab from changing focus // Prevent tab from changing focus
if(e.keyCode == 9) return false; if(e.keyCode == 9) return false;
} }
KeyboardInput.prototype._onKeyUp = function (e) { KeyboardInput.prototype.onKeyUp = function (e) {
var key = this._getKeyByKeyCode(e.keyCode); var key = this.getKeyByKeyCode(e.keyCode);
if (key && key.getActive()) { if (key && key.getActive()) {
var callback = key.getKeyUpFunction(); var callback = key.getKeyUpFunction();
if(callback) callback();
key.setActive(false); key.setActive(false);
if(callback) callback();
} }
// Prevent tab from changing focus // 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); 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() { PlayerController.prototype.suicide = function() {
if (!PointerLockManager.isLocked()) return; if (!PointerLockManager.isLocked()) return;
Nc.trigger(Nc.ns.client.to.server.gameCommand.send, "suicide"); Nc.trigger(Nc.ns.client.to.server.gameCommand.send, "suicide");