Skip to content

Commit

Permalink
Fix key/mouse handling when settings visible
Browse files Browse the repository at this point in the history
When the settings menu was being shown, the mouse and keyboard would not
work as expected; for example, neither could be used to modify the value
of an input[type="number"] field. Instead, a mouse click would be
interpreted as Blue getting (un)ready, which is not a desired behavior in
the settings menu.
  • Loading branch information
SimonAlling committed Mar 17, 2017
1 parent 27da313 commit bee69b6
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions js/Zatacka.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,17 +319,16 @@ const Zatacka = ((window, document) => {
}

function keyHandler(event) {
if (shouldPreventDefault(event.keyCode)) {
event.preventDefault();
}
const callback = game.isStarted() ? gameKeyHandler
: guiController.isShowingSettings() ? settingsKeyHandler
: lobbyKeyHandler;
guiController.keyPressed(event, callback);
}

function mouseHandler(event) {
const callback = game.isStarted() ? gameMouseHandler : lobbyMouseHandler;
const callback = game.isStarted() ? gameMouseHandler
: guiController.isShowingSettings() ? settingsMouseHandler
: lobbyMouseHandler;
guiController.mouseClicked(event, callback);
}

Expand All @@ -340,6 +339,9 @@ const Zatacka = ((window, document) => {
}

function lobbyKeyHandler(event) {
if (shouldPreventDefault(event.keyCode)) {
event.preventDefault();
}
const pressedKey = event.keyCode;
if (pressedKey === KEY_RELOAD) {
reload();
Expand All @@ -366,6 +368,9 @@ const Zatacka = ((window, document) => {
}

function gameKeyHandler(event) {
if (shouldPreventDefault(event.keyCode)) {
event.preventDefault();
}
const pressedKey = event.keyCode;
if (isProceedKey(pressedKey)) {
if (game.shouldQuitOnProceedKey()) {
Expand Down Expand Up @@ -404,6 +409,10 @@ const Zatacka = ((window, document) => {
}
}

function settingsMouseHandler(event) {
// Intentionally empty.
}

function showSettings() {
clearTimeout(hintPickTimer);
clearTimeout(hintProceedTimer);
Expand Down

0 comments on commit bee69b6

Please sign in to comment.