aboutsummaryrefslogtreecommitdiff
path: root/web/pw-visualizer
diff options
context:
space:
mode:
authorIlion Beyst <ilion.beyst@gmail.com>2022-11-08 21:25:56 +0100
committerIlion Beyst <ilion.beyst@gmail.com>2022-11-08 21:25:56 +0100
commit949844b957055f2a45438db68c638ffbe218acda (patch)
tree49cc5d2f77ef005ee0c751fa367e2409fa175da1 /web/pw-visualizer
parent5c20f19c8aee925f24e80bea9f3c2198a47b14a9 (diff)
downloadplanetwars.dev-949844b957055f2a45438db68c638ffbe218acda.tar.xz
planetwars.dev-949844b957055f2a45438db68c638ffbe218acda.zip
Do not unpause visualizer when using arrow keys
Diffstat (limited to 'web/pw-visualizer')
-rw-r--r--web/pw-visualizer/src/index.ts53
1 files changed, 13 insertions, 40 deletions
diff --git a/web/pw-visualizer/src/index.ts b/web/pw-visualizer/src/index.ts
index 4c99311..f97bd2b 100644
--- a/web/pw-visualizer/src/index.ts
+++ b/web/pw-visualizer/src/index.ts
@@ -361,7 +361,6 @@ export class GameInstance {
this.planet_labels[i].setText(
GL,
- // this.planet_names[i] + " " +
"" + planet_ships[i],
Align.Middle,
Align.Begin
@@ -563,15 +562,8 @@ export class GameInstance {
updateTurn(turn: number) {
this.frame = Math.max(0, turn);
- const new_frame = this.game.update_turn(this.frame);
- if (new_frame < this.frame) {
- this.frame = new_frame;
- this.playing = false;
- } else {
- this._update_state();
- this.playing = true;
- }
-
+ this.game.update_turn(this.frame);
+ this._update_state();
this.updateTurnCounters();
}
@@ -583,36 +575,17 @@ export class GameInstance {
}
handleKey(event: KeyboardEvent) {
- // Space
- if (event.keyCode == 32) {
- if (this.playing) {
- this.playing = false;
- } else {
- this.playing = true;
- }
- }
-
- // Arrow left
- if (event.keyCode == 37) {
- // This feels more natural than -1 what it should be, I think
- this.updateTurn(this.frame - 2);
- }
-
- // Arrow right
- if (event.keyCode == 39) {
- this.updateTurn(this.frame + 1);
- }
-
- // d key
- if (event.keyCode == 68) {
- ELEMENTS["speed"].value = ms_per_frame + 10 + "";
- ELEMENTS["speed"].onchange(undefined);
- }
-
- // a key
- if (event.keyCode == 65) {
- ELEMENTS["speed"].value = Math.max(ms_per_frame - 10, 0) + "";
- ELEMENTS["speed"].onchange(undefined);
+ let delta = event.shiftKey ? 5 : 1;
+ switch (event.code) {
+ case "Space":
+ this.playing = !this.playing;
+ break;
+ case "ArrowLeft":
+ this.updateTurn(this.frame - delta);
+ break;
+ case "ArrowRight":
+ this.updateTurn(this.frame + delta);
+ break;
}
}
}