summaryrefslogtreecommitdiffstats
path: root/src/renderer/runtime/view/input
diff options
context:
space:
mode:
Diffstat (limited to 'src/renderer/runtime/view/input')
-rw-r--r--src/renderer/runtime/view/input/gameinput.ts26
-rw-r--r--src/renderer/runtime/view/input/inputhandler.ts12
2 files changed, 12 insertions, 26 deletions
diff --git a/src/renderer/runtime/view/input/gameinput.ts b/src/renderer/runtime/view/input/gameinput.ts
index 67fbe0c..b116839 100644
--- a/src/renderer/runtime/view/input/gameinput.ts
+++ b/src/renderer/runtime/view/input/gameinput.ts
@@ -35,13 +35,8 @@ export class GameInputHandler extends Listenable<[GameInput]> {
super();
this.input = new InputHandler(
- new Set([
- 'ArrowLeft',
- 'ArrowUp',
- 'ArrowRight',
- 'ArrowDown',
- ...Object.keys(buttonMapping),
- ]));
+ new Set(['ArrowLeft', 'ArrowUp', 'ArrowRight', 'ArrowDown', ...Object.keys(buttonMapping)]),
+ );
this.input.addListener((key: string, pressed: boolean) => {
const button = buttonMapping[key];
@@ -57,17 +52,12 @@ export class GameInputHandler extends Listenable<[GameInput]> {
const dir = vec2.create();
- if (this.input.has('ArrowLeft'))
- vec2.add(dir, dir, [-1, 0]);
- if (this.input.has('ArrowUp'))
- vec2.add(dir, dir, [0, -1]);
- if (this.input.has('ArrowRight'))
- vec2.add(dir, dir, [1, 0]);
- if (this.input.has('ArrowDown'))
- vec2.add(dir, dir, [0, 1]);
-
- if (vec2.sqrLen(dir) > 0)
- vec2.normalize(dir, dir);
+ if (this.input.has('ArrowLeft')) vec2.add(dir, dir, [-1, 0]);
+ if (this.input.has('ArrowUp')) vec2.add(dir, dir, [0, -1]);
+ if (this.input.has('ArrowRight')) vec2.add(dir, dir, [1, 0]);
+ if (this.input.has('ArrowDown')) vec2.add(dir, dir, [0, 1]);
+
+ if (vec2.sqrLen(dir) > 0) vec2.normalize(dir, dir);
this.runListeners({
type: 'direction',
diff --git a/src/renderer/runtime/view/input/inputhandler.ts b/src/renderer/runtime/view/input/inputhandler.ts
index 17abfe6..4f5f150 100644
--- a/src/renderer/runtime/view/input/inputhandler.ts
+++ b/src/renderer/runtime/view/input/inputhandler.ts
@@ -7,26 +7,22 @@ export class InputHandler extends Listenable<[string, boolean]> {
super();
window.addEventListener('keydown', (ev) => {
- if (!relevantKeys.has(ev.code))
- return;
+ if (!relevantKeys.has(ev.code)) return;
ev.preventDefault();
- if (ev.repeat)
- return;
+ if (ev.repeat) return;
this.keys.add(ev.code);
this.runListeners(ev.code, true);
});
window.addEventListener('keyup', (ev) => {
- if (!relevantKeys.has(ev.code))
- return;
+ if (!relevantKeys.has(ev.code)) return;
ev.preventDefault();
- if (!this.keys.has(ev.code))
- return;
+ if (!this.keys.has(ev.code)) return;
this.keys.delete(ev.code);
this.runListeners(ev.code, false);