Skip to content

Commit

Permalink
Webclient: Continue movement on dir release if any other dir key is p…
Browse files Browse the repository at this point in the history
…ressed

#254
  • Loading branch information
AntumDeluge committed Dec 24, 2022
1 parent 79c078e commit 34a28d3
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions srcjs/stendhal/ui/keyhandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,25 @@ stendhal.ui.keycode = {
stendhal.ui.keyhandler = {
pressedKeys: [],

/**
* Checks if any direction key is currently pressed.
*
* @return
* <code>true</code> if direction keycode found in pressed
* keys list.
*/
isDirPressed: function() {
for (const dir of [stendhal.ui.keycode.left,
stendhal.ui.keycode.right, stendhal.ui.keycode.up,
stendhal.ui.keycode.down]) {
if (stendhal.ui.keyhandler.pressedKeys.indexOf(dir) > -1) {
return true;
}
}

return false;
},

extractMoveOrFaceActionFromEvent: function(event) {
if (event.ctrlKey) {
return "face";
Expand Down Expand Up @@ -102,14 +121,15 @@ stendhal.ui.keyhandler = {
var code = stendhal.ui.html.extractKeyCode(event);

if (code >= stendhal.ui.keycode.left && code <= stendhal.ui.keycode.down) {
var code = stendhal.ui.html.extractKeyCode(event);
var i = stendhal.ui.keyhandler.pressedKeys.indexOf(code);
if (i > -1) {
stendhal.ui.keyhandler.pressedKeys.splice(i, 1);
}

var action = {"type": "stop"};
marauroa.clientFramework.sendAction(action);
if (!stendhal.ui.keyhandler.isDirPressed()) {
var action = {"type": "stop"};
marauroa.clientFramework.sendAction(action);
}

if (stendhal.ui.keyhandler.pressedKeys.length > 0) {
code = stendhal.ui.keyhandler.pressedKeys[0];
Expand Down

0 comments on commit 34a28d3

Please sign in to comment.