diff options
Diffstat (limited to 'ecs/src')
-rw-r--r-- | ecs/src/system/observer.rs | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/ecs/src/system/observer.rs b/ecs/src/system/observer.rs index 1496d40..b7d84be 100644 --- a/ecs/src/system/observer.rs +++ b/ecs/src/system/observer.rs @@ -94,7 +94,7 @@ impl<ObservedT: Observed> Observe<'_, ObservedT> impl<'a, ObservedT: Observed> IntoIterator for &'a Observe<'_, ObservedT> { type IntoIter = ObserveIter<'a>; - type Item = EntityHandle<'a>; + type Item = <Self::IntoIter as Iterator>::Item; fn into_iter(self) -> Self::IntoIter { @@ -110,13 +110,37 @@ pub struct ObserveIter<'observe> impl<'observe> Iterator for ObserveIter<'observe> { - type Item = EntityHandle<'observe>; + type Item = EventMatch<'observe>; fn next(&mut self) -> Option<Self::Item> { - let target = *self.inner.next()?; + let match_id = *self.inner.next()?; - self.world.get_entity(target) + Some(EventMatch { world: self.world, id: match_id }) + } +} + +/// A event match. +#[derive(Debug)] +pub struct EventMatch<'world> +{ + world: &'world World, + id: Uid, +} + +impl<'world> EventMatch<'world> +{ + #[must_use] + pub fn id(&self) -> Uid + { + self.id + } + + /// Attempts to get the entity with the id of this match. + #[must_use] + pub fn get_entity(&self) -> Option<EntityHandle<'world>> + { + self.world.get_entity(self.id) } } |