- commit
- 31d60d419356d354e83a666b6ca148957ba07d8f
- parent
- 6d55f2dfc36dcd3df82d2623cb06e4cdf4064459
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2024-09-27 15:55
dpad: reuse key handler
Diffstat
| M | static/dpad.js | 4 | ++-- |
| M | static/main.js | 5 | ++++- |
2 files changed, 6 insertions, 3 deletions
diff --git a/static/dpad.js b/static/dpad.js
@@ -7,9 +7,9 @@ export default function(handler) {
7 7 var x = (pointer.x - rect.x) / rect.width - 0.5;
8 8 var y = (pointer.y - rect.y) / rect.height - 0.5;
9 9 if (Math.abs(x) > Math.abs(y)) {
10 -1 handler(x > 0 ? 'right' : 'left');
-1 10 handler(x > 0 ? 'ArrowRight' : 'ArrowLeft');
11 11 } else {
12 -1 handler(y > 0 ? 'down' : 'up');
-1 12 handler(y > 0 ? 'ArrowDown' : 'ArrowUp');
13 13 }
14 14 };
15 15
diff --git a/static/main.js b/static/main.js
@@ -286,7 +286,10 @@ document.onkeydown = function(event) {
286 286 event.preventDefault();
287 287 };
288 288
289 -1 onDPad(dir => send({action: 'move', dir: dir}));
-1 289 onDPad(key => document.onkeydown({
-1 290 key: key,
-1 291 preventDefault: () => {},
-1 292 }));
290 293
291 294 screen.updateSize();
292 295 window.addEventListener('resize', () => screen.updateSize(), {passive: true});