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

feat: Trigger - access to action's actor #3157

Closed
eonarheim opened this issue Aug 1, 2024 Discussed in #3099 · 2 comments · Fixed by #3176
Closed

feat: Trigger - access to action's actor #3157

eonarheim opened this issue Aug 1, 2024 Discussed in #3099 · 2 comments · Fixed by #3176
Assignees

Comments

@eonarheim
Copy link
Member

Discussed in #3099

Originally posted by KostarSf June 17, 2024
Hi! It would be very useful to have access to the Actor, which calls Trigger's action callback. Something like this:

const trigger = new Trigger({
  // rest
  action: (actor) => {
    // do action
  }
})

I want to use triggers as areas of view for AI enemies, so it's important for me to know which Actor called action. Now I have to do my own implementation of the trigger, which takes this into account.

It would be great if it appeared in Excalibur!

@Autsider666
Copy link
Contributor

I'm interested in giving this issue a try!

  • Does the scope of this issue also include the second comment about the type of the actor being returned being modified by the filter callback?
  • And if so: It sounds really useful, but what TS magic would be required to achieve this?

@eonarheim
Copy link
Member Author

@Autsider666 all yours!

Does the scope of this issue also include the #3099 (comment) 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) {
    
    } 
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants