Closed eonarheim closed 1 week ago
I'm interested in giving this issue a try!
@Autsider666 all yours!
Does the scope of this issue also include the https://github.com/excaliburjs/Excalibur/discussions/3099#discussioncomment-9791793 about the type of the actor being returned being modified by the filter callback?
That's a tough one, I think the best we say is that TEntity extends Entity
in some way for the filter? Since there are no runtime types I'm not sure we can capture the return, unless it's statically known, so we could allow folks to say triggers only operate on x types?
Rough possible sketch, may or may not compile, but types should be inferred?
class Trigger<TActionTarget extends Entity = Entity> {
constructor(public targetType: typeof TActionTarget) => {}
onFilter<TEntity extends Entity>(entity: TEntity): TActionTarget {
if (entity instanceof this.targetType) {
return entity
}
..
}
onAction(actionTarget: TActionTarget) {
}
}
Discussed in https://github.com/excaliburjs/Excalibur/discussions/3099