Skip to content

Commit

Permalink
fix: Adding scene with the same name as a deleted scene would not work
Browse files Browse the repository at this point in the history
  • Loading branch information
eonarheim committed Mar 14, 2024
1 parent faa4a37 commit 0fc9ab8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).

### Fixed

- Fixed issue where adding scenes with the same name did not work when it was previously removed
- Fixed issue when WebGL context lost occurs where there was no friendly output to the user
- Fixed issue where HiDPI scaling could accidentally scale past the 4k mobile limit, if the context would scale too large it will now attempt to recover by backing off.
- Fixed issue where logo was sometimes not loaded during `ex.Loader`
Expand Down
2 changes: 2 additions & 0 deletions src/engine/Director/Director.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ export class Director<TKnownScenes extends string = any> {
throw new Error(`Cannot remove a currently active scene: ${key}`);
}

this._sceneToInstance.delete(key);
this._sceneToTransition.delete(key);
this._sceneToLoader.delete(key);
delete this.scenes[key as TKnownScenes];
Expand All @@ -363,6 +364,7 @@ export class Director<TKnownScenes extends string = any> {
}

// remove scene
this._sceneToInstance.delete(nameOrScene);
this._sceneToTransition.delete(nameOrScene);
this._sceneToLoader.delete(nameOrScene);
delete this.scenes[nameOrScene as TKnownScenes];
Expand Down
23 changes: 23 additions & 0 deletions src/spec/DirectorSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,29 @@ describe('A Director', () => {
expect(() => sut.remove(sut.rootScene)).toThrowError('Cannot remove a currently active scene: root');
});

it('can add a scene that was already deleted', async () => {
const engine = TestUtils.engine();
const clock = engine.clock as ex.TestClock;
clock.start();
const scene1 = new ex.Scene();
const scene2 = new ex.Scene();
const sut = new ex.Director(engine, {
scene1,
scene2
});
sut.configureStart('scene1');
sut.onInitialize();
await sut.goto('scene2');
expect(sut.currentScene).toBe(scene2);
sut.remove('scene1');

const newScene = new ex.Scene();
sut.add('scene1', newScene);

await sut.goto('scene1');
expect(sut.currentScene).toBe(newScene);
});

it('can goto a scene', async () => {
const engine = TestUtils.engine();
const clock = engine.clock as ex.TestClock;
Expand Down

0 comments on commit 0fc9ab8

Please sign in to comment.