Skip to content

Commit

Permalink
fix(gamestate): leave being called on push state
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaisthorpe committed Sep 24, 2023
1 parent 48bf8e5 commit 12311cc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/green-stingrays-melt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@tedengine/ted': minor
---

Fix 'leave' triggered on game state push
6 changes: 3 additions & 3 deletions packages/ted/src/core/game-state-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ export default class TGameStateManager {

/**
* Pushes a new state onto the stack.
* Triggers [[`TGameState.onLeave`]] on the previously active state, then [[`TGameState.onEnter`]] on the new state.
* It triggers [[`TGameState.onEnter`]] on the new state.
*
* It does not trigger [[`TGameState.onLeave`]] on previously active state.
*
* @param name state name
* @param args args to pass to the resumed state
Expand All @@ -37,8 +39,6 @@ export default class TGameStateManager {
throw new Error(`Game State '${name}' does not exist`);
}

await this.current()?.leave(this.engine);

// If state hasn't been created, then create it
if (!this.states[name]) {
await this.createState(name);
Expand Down

0 comments on commit 12311cc

Please sign in to comment.