Skip to content

Commit

Permalink
fix: False positive warning when adding timers
Browse files Browse the repository at this point in the history
  • Loading branch information
eonarheim committed Jan 1, 2025
1 parent a167f8d commit 956056b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).

### Fixed

- Fixed false positive warning when adding timers
- Fixed issue where gamepad buttons wouldn't progress the default loader play button
- Add defense around middling Safari fullscreen support and update documentation
- Fixed issue where non-standard gamepad buttons would not be emitted by Excalibur
Expand Down
6 changes: 3 additions & 3 deletions src/engine/Scene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -536,14 +536,14 @@ export class Scene<TActivationData = unknown> implements CanInitialize, CanActiv
public add(screenElement: ScreenElement): void;
public add(entity: any): void {
this.emit('entityadded', { target: entity } as any);
this.world.add(entity);
entity.scene = this;
if (entity instanceof Timer) {
if (!Util.contains(this._timers, entity)) {
this.addTimer(entity);
}
return;
}
this.world.add(entity);
entity.scene = this;
}

/**
Expand Down Expand Up @@ -648,8 +648,8 @@ export class Scene<TActivationData = unknown> implements CanInitialize, CanActiv
*/
public remove(screenElement: ScreenElement): void;
public remove(entity: any): void {
this.emit('entityremoved', { target: entity } as any);
if (entity instanceof Entity) {
this.emit('entityremoved', { target: entity } as any);
if (entity.isActive) {
entity.kill();
}
Expand Down
13 changes: 13 additions & 0 deletions src/spec/TimerSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,19 @@ describe('A Timer', () => {
expect(sut.timeElapsedTowardNextAction).toBe(0);
});

it('does not warn when added to a scene', () => {
const warnSpy = spyOn(ex.Logger.getInstance(), 'warn');
const timerSpy = jasmine.createSpy('timer');
const sut = new ex.Timer({
interval: 42,
fcn: timerSpy
});

scene.add(sut);

expect(warnSpy).not.toHaveBeenCalled();
});

it('can be stopped and started', () => {
const timerSpy = jasmine.createSpy('timer');
const sut = new ex.Timer({
Expand Down

0 comments on commit 956056b

Please sign in to comment.