Skip to content
This repository has been archived by the owner on Nov 29, 2022. It is now read-only.

Query utility for events #19

Closed
jcornaz opened this issue Jan 27, 2021 · 1 comment
Closed

Query utility for events #19

jcornaz opened this issue Jan 27, 2021 · 1 comment
Labels
enhancement New feature or improvement

Comments

@jcornaz
Copy link
Owner

jcornaz commented Jan 27, 2021

As a User, I want an easy way to query for components of the entities involved in a collision, so that it is easier to read/update components as part of the reaction to the event.

Here is how usage could look like:

fn damage_system(
  mut event_reader: Local<EventReader<CollisionEvent>>,
  events: Res<Events<CollisionEvent>>,
  mut damageables: Query<&mut Hp>,
  bullets: Query<Bullet>,
) {
  event_reader.iter(events)
    .flat_map(|event| event.query(&mut damageables, &bullets))
    .for_each(|(mut hp, bullet)| {
       hp.take_dmg(bullet.dmg());
    });
}
@jcornaz jcornaz added the enhancement New feature or improvement label Jan 27, 2021
@jcornaz
Copy link
Owner Author

jcornaz commented Mar 6, 2022

Closing in favor of #207

@jcornaz jcornaz closed this as completed Mar 6, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or improvement
Projects
None yet
Development

No branches or pull requests

1 participant