summaryrefslogtreecommitdiffstats
path: root/src/view/input/directionhandler.ts
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2018-11-01 00:59:13 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2018-11-01 00:59:13 +0100
commit9f2e4e6996fb96d23e1ca29667130a2111a59de5 (patch)
treefa7c3c22d469f062252735269dbc09031fc47dd8 /src/view/input/directionhandler.ts
parent22b06efe2c2646a01535b5bbf5f3cc57de81ad0d (diff)
downloadrpgedit-9f2e4e6996fb96d23e1ca29667130a2111a59de5.tar
rpgedit-9f2e4e6996fb96d23e1ca29667130a2111a59de5.zip
Do not use default exports
Diffstat (limited to 'src/view/input/directionhandler.ts')
-rw-r--r--src/view/input/directionhandler.ts37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/view/input/directionhandler.ts b/src/view/input/directionhandler.ts
new file mode 100644
index 0000000..0a3687e
--- /dev/null
+++ b/src/view/input/directionhandler.ts
@@ -0,0 +1,37 @@
+import { InputHandler } from './inputhandler';
+
+import { Listenable } from '../../util';
+
+import { vec2 } from 'gl-matrix';
+
+export const enum Keycode {
+ Left = 37,
+ Up = 38,
+ Right = 39,
+ Down = 40,
+}
+
+export class DirectionHandler extends Listenable<[vec2]> {
+ private readonly input: InputHandler;
+
+ constructor() {
+ super();
+
+ this.input = new InputHandler(new Set([Keycode.Left, Keycode.Up, Keycode.Right, Keycode.Down]));
+
+ this.input.addListener(() => {
+ const dir = vec2.create();
+
+ if (this.input.has(Keycode.Left))
+ vec2.add(dir, dir, [-1, 0]);
+ if (this.input.has(Keycode.Up))
+ vec2.add(dir, dir, [0, -1]);
+ if (this.input.has(Keycode.Right))
+ vec2.add(dir, dir, [1, 0]);
+ if (this.input.has(Keycode.Down))
+ vec2.add(dir, dir, [0, 1]);
+
+ this.runListeners(dir);
+ });
+ }
+}