Skip to content

Commit cbf9c90

Browse files
fix(ecs): fix TriggerEntity not passing params in callback call
1 parent c460e05 commit cbf9c90

3 files changed

Lines changed: 8 additions & 7 deletions

File tree

src/ecs/components/BoundingBoxComponent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { SerializableCallback, Type, Vec2, WithType } from "../../core";
1+
import { Type, Vec2, WithType } from "../../core";
22
import { PhysicsObject, Physx } from "../../physx";
33
import { BaseComponent } from "./BaseComponent";
44
import { TransformComponent } from "./TransformComponent";

src/ecs/entities/TriggerEntity.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,6 @@ export class TriggerEntity extends StaticObject implements TriggerEntityProps {
7979
}
8080

8181
private onCollisionHandler(params: CollisionCallbackParams): void {
82-
params.collider.uuid === this._targetComponent?.uuid && this.onTriggerCB?.call(params);
82+
params.collider.uuid === this._targetComponent?.uuid && this.onTriggerCB?.call(this, params);
8383
}
8484
}

test/unit/ecs/entities/TriggerEntity.test.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,7 @@ describe('ecs/entities/TriggerEntity', () => {
7272

7373
describe('.onTriggerCB', () => {
7474
it('Should be invoked when a collision between this entity and the target is detected', () => {
75-
const callback = jest.fn();
76-
triggerEntity.onTriggerCB = SerializableCallback.fromFunction(callback);
77-
triggerEntity.boundingBox.onCollisionCb?.call(this, {
75+
const params = {
7876
collider: {
7977
aabb: [1, 0, 1, 0],
8078
velocity: new Vec2(),
@@ -85,9 +83,12 @@ describe('ecs/entities/TriggerEntity', () => {
8583
velocity: new Vec2(),
8684
uuid: triggerEntity.boundingBox.uuid
8785
}
88-
});
86+
}
87+
const callback = jest.fn();
88+
triggerEntity.onTriggerCB = SerializableCallback.fromFunction(callback);
89+
triggerEntity.boundingBox.onCollisionCb?.call(this, params);
8990

90-
expect(callback).toHaveBeenCalled();
91+
expect(callback).toHaveBeenCalledWith(params);
9192
});
9293
});
9394

0 commit comments

Comments
 (0)