From 2266e73b3a50052c32099435b10496b810e5a4de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barth=C3=A9lemy?= <31370477+BarthPaleologue@users.noreply.github.com> Date: Fri, 22 Sep 2023 12:06:54 +0200 Subject: [PATCH] removed keyboard interactions when paused --- src/ts/blackHoleDemo.ts | 1 + src/ts/controller/spaceEngine.ts | 18 ++++++++++-------- src/ts/index.ts | 1 + src/ts/randomizer.ts | 1 + 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/ts/blackHoleDemo.ts b/src/ts/blackHoleDemo.ts index 016a5c619..884233641 100644 --- a/src/ts/blackHoleDemo.ts +++ b/src/ts/blackHoleDemo.ts @@ -70,6 +70,7 @@ const planet = starSystem.makeTelluricPlanet(); planet.model.orbit.radius = 10000e3; document.addEventListener("keydown", (e) => { + if (engine.isPaused()) return; if (e.key === "g") { if (scene.getActiveController() === spaceshipController) { scene.setActiveController(player); diff --git a/src/ts/controller/spaceEngine.ts b/src/ts/controller/spaceEngine.ts index fa5e22571..d9dde87fb 100644 --- a/src/ts/controller/spaceEngine.ts +++ b/src/ts/controller/spaceEngine.ts @@ -103,6 +103,16 @@ export class SpaceEngine { //TODO: use the keyboard class document.addEventListener("keydown", (e) => { + // when pressing f11, the ui is hidden when the browser is in fullscreen mode + if (e.key === "F11") this.isFullscreen = !this.isFullscreen; + + if (e.key === "Escape") { + if (this.state === EngineState.RUNNING) this.pause(); + else this.resume(); + } + + if (this.isPaused()) return; + if (e.key === "o") OverlayPostProcess.ARE_ENABLED = !OverlayPostProcess.ARE_ENABLED; if (e.key === "n") this.orbitRenderer.setVisibility(!this.orbitRenderer.isVisible()); if (e.key === "p") this.takeScreenshot(); @@ -133,14 +143,6 @@ export class SpaceEngine { this.helmetOverlay.setVisibility(!this.helmetOverlay.isVisible()); } } - - // when pressing f11, the ui is hidden when the browser is in fullscreen mode - if (e.key === "F11") this.isFullscreen = !this.isFullscreen; - - if (e.key === "Escape") { - if (this.state === EngineState.RUNNING) this.pause(); - else this.resume(); - } }); } diff --git a/src/ts/index.ts b/src/ts/index.ts index f544e9098..35c89c6e5 100644 --- a/src/ts/index.ts +++ b/src/ts/index.ts @@ -190,6 +190,7 @@ if (aresAtmosphere) { } document.addEventListener("keydown", (e) => { + if (engine.isPaused()) return; if (e.key === "g") { if (scene.getActiveController() === spaceshipController) { scene.setActiveController(player); diff --git a/src/ts/randomizer.ts b/src/ts/randomizer.ts index 01d387784..f076b3de0 100644 --- a/src/ts/randomizer.ts +++ b/src/ts/randomizer.ts @@ -77,6 +77,7 @@ const starSystem = new StarSystem(seed ? Number(seed) : randRange(-1, 1, (step: engine.setStarSystem(starSystem, true); document.addEventListener("keydown", (e) => { + if (engine.isPaused()) return; if (e.key === "g") { if (scene.getActiveController() === spaceshipController) { scene.setActiveController(player);