summaryrefslogtreecommitdiff
path: root/client/src/akkamon/render/BattleControls.ts
blob: d61e9d4b005063e1d9e5332f58dd21f976a7aa4f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { Direction } from './Direction';
import type { BattleEngine } from './BattleEngine';
import type { AkkamonMenu } from '../scenes/UIElement';

export class BattleControls {
    private cursors: Phaser.Types.Input.Keyboard.CursorKeys;

    constructor(
        private input: Phaser.Input.InputPlugin,
        private menu: AkkamonMenu,
    ) {
        this.cursors = this.input.keyboard.createCursorKeys();
    }

    update() {
        console.log("updating battle controls");
        if (Phaser.Input.Keyboard.JustDown(this.cursors.left)) {
            console.log("left");
            this.menu.selectButton(Direction.LEFT);
        } else if (Phaser.Input.Keyboard.JustDown(this.cursors.right)) {
            console.log("right");
            this.menu.selectButton(Direction.RIGHT);
        } else if (Phaser.Input.Keyboard.JustDown(this.cursors.up)) {
            console.log("up");
            this.menu.selectButton(Direction.UP);
        } else if (Phaser.Input.Keyboard.JustDown(this.cursors.down)) {
            console.log("down");
            this.menu.selectButton(Direction.DOWN);
        } else if (Phaser.Input.Keyboard.JustDown(this.cursors.space)) {
            console.log("confirm");
            this.menu.confirm();
        }
    }
}