Skip to content

Commit

Permalink
fix: [#1850] Fix Scene.onActivate/onDeactivate args
Browse files Browse the repository at this point in the history
  • Loading branch information
eonarheim committed Jun 27, 2021
1 parent 37e1b24 commit 76b9014
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
### Breaking Changes

- `Timer`'s no longer automatically start when added to a `Scene`, this `Timer.start()` must be called. ([#1865](ttps://github.com/excaliburjs/Excalibur/issues/1865))
- `Timer.complete` is now read-only to prevent odd bugs, use `reset()`, `stop()`, and `start()` to manipulate timers.
- `Timer.complete` is now read-only to prevent odd bugs, use `reset()`, `stop()`, and `start()` to manipulate timers.
- `Actor.actions.repeat()` and `Actor.actions.repeatForever()` now require a handler that specifies the actions to repeat. This is more clear and helps prevent bugs like #1891

```typescript
Expand Down Expand Up @@ -94,6 +94,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).

### Fixed

- Fixed issue where `Scene.onActivate/onDeactivate` were called with the wrong arguments ([#1850](https://github.com/excaliburjs/Excalibur/issues/1850))
- Fixed issue where no width/height argmunents to engine throws an error
- Fixed issue where zero dimension image draws on the ExcaliburGraphicsContext throw an error
- Fixed issue where the first scene onInitialize fires at Engine contructor time and before the "play button" clicked ([#1900](https://github.com/excaliburjs/Excalibur/issues/1900))
Expand Down
4 changes: 2 additions & 2 deletions src/engine/Engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ O|===|* >________________>\n\

// only deactivate when initialized
if (this.currentScene.isInitialized) {
this.currentScene._deactivate.call(this.currentScene, [oldScene, newScene]);
this.currentScene._deactivate.apply(this.currentScene, [oldScene, newScene]);
this.currentScene.eventDispatcher.emit('deactivate', new DeactivateEvent(newScene, this.currentScene));
}

Expand All @@ -864,7 +864,7 @@ O|===|* >________________>\n\
// initialize the current scene if has not been already
this.currentScene._initialize(this);

this.currentScene._activate.call(this.currentScene, [oldScene, newScene]);
this.currentScene._activate.apply(this.currentScene, [oldScene, newScene]);
this.currentScene.eventDispatcher.emit('activate', new ActivateEvent(oldScene, this.currentScene));
} else {
this._logger.error('Scene', key, 'does not exist!');
Expand Down
25 changes: 25 additions & 0 deletions src/spec/SceneSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,31 @@ describe('A scene', () => {
expect(scene.onInitialize).toHaveBeenCalledTimes(1);
});

it('calls onActivate and onDeactivate with the correct args', () => {
const mock = new Mocks.Mocker();
const sceneA = new ex.Scene();
sceneA.onDeactivate = jasmine.createSpy('onDeactivate()');
const sceneB = new ex.Scene();
sceneB.onActivate = jasmine.createSpy('onActivate()');

engine.removeScene('root');
engine.addScene('root', sceneA);
engine.addScene('sceneB', sceneB);

const loop = mock.loop(engine);
engine.goToScene('root');
engine.start();
loop.advance(100);
loop.advance(100);

engine.goToScene('sceneB');
loop.advance(100);
loop.advance(100);

expect(sceneA.onDeactivate).toHaveBeenCalledWith(sceneA, sceneB);
expect(sceneB.onActivate).toHaveBeenCalledWith(sceneA, sceneB);
});

it('fires initialize before activate', (done) => {
const scene = new ex.Scene();
engine.removeScene('root');
Expand Down

0 comments on commit 76b9014

Please sign in to comment.