Skip to content

Commit

Permalink
removed keyboard interactions when paused
Browse files Browse the repository at this point in the history
  • Loading branch information
BarthPaleologue committed Sep 22, 2023
1 parent 1a29578 commit 2266e73
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/ts/blackHoleDemo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
18 changes: 10 additions & 8 deletions src/ts/controller/spaceEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
}
});
}

Expand Down
1 change: 1 addition & 0 deletions src/ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/ts/randomizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 2266e73

Please sign in to comment.