Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Trigger event signature type was incorrect #2811

Merged
merged 1 commit into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).

### Fixed

- Fixed typo in trigger event signature `entertrigger` should have been `enter`
- Fixed typo in trigger event signature `exittrigger` should have been `exit`
- Fixed typo in animation event signature `ended` should have been `end`
- Fixed issue where some excalibur `clear()`` implementations modified the collection they were iterating over
- Fixed async issue where sound could not be stopped if stop()/start() were called in rapid succession
Expand Down
14 changes: 7 additions & 7 deletions src/engine/Trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import { Actor, ActorEvents } from './Actor';
import { EventEmitter } from './EventEmitter';

export type TriggerEvents = ActorEvents & {
exittrigger: ExitTriggerEvent,
entertrigger: EnterTriggerEvent
exit: ExitTriggerEvent,
enter: EnterTriggerEvent
}

export const TriggerEvents = {
ExitTrigger: 'exittrigger',
EnterTrigger: 'entertrigger'
ExitTrigger: 'exit',
EnterTrigger: 'enter'
};

/**
Expand Down Expand Up @@ -56,7 +56,7 @@ const triggerDefaults: Partial<TriggerOptions> = {
* are invisible, and can only be seen when [[Trigger.visible]] is set to `true`.
*/
export class Trigger extends Actor {
public events = new EventEmitter<TriggerEvents>();
public events = new EventEmitter<TriggerEvents & ActorEvents>();
private _target: Entity;
/**
* Action to fire when triggered by collision
Expand Down Expand Up @@ -97,7 +97,7 @@ export class Trigger extends Actor {

this.events.on('collisionstart', (evt: CollisionStartEvent<Actor>) => {
if (this.filter(evt.other)) {
this.emit('enter', new EnterTriggerEvent(this, evt.other));
this.events.emit('enter', new EnterTriggerEvent(this, evt.other));
this._dispatchAction();
// remove trigger if its done, -1 repeat forever
if (this.repeat === 0) {
Expand All @@ -108,7 +108,7 @@ export class Trigger extends Actor {

this.events.on('collisionend', (evt: CollisionEndEvent<Actor>) => {
if (this.filter(evt.other)) {
this.emit('exit', new ExitTriggerEvent(this, evt.other));
this.events.emit('exit', new ExitTriggerEvent(this, evt.other));
}
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/spec/TriggerSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ describe('A Trigger', () => {

const exitSpy = jasmine.createSpy('exit');
const collisionEnd = jasmine.createSpy('collisionend');
trigger.on('exit', exitSpy);
trigger.on('collisionend', collisionEnd);
trigger.events.on('exit', exitSpy);
trigger.events.on('collisionend', collisionEnd);

// Act
actor.vel = ex.vec(0, 10);
Expand Down