diff options
Diffstat (limited to 'ecs/src/entity.rs')
-rw-r--r-- | ecs/src/entity.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/ecs/src/entity.rs b/ecs/src/entity.rs index d7e5945..8c07ea8 100644 --- a/ecs/src/entity.rs +++ b/ecs/src/entity.rs @@ -12,6 +12,7 @@ use crate::component::{ Handle as ComponentHandle, HandleMut as ComponentHandleMut, }; +use crate::pair::{ComponentOrWildcard, Pair, WithWildcard as PairWithWildcard}; use crate::uid::{Kind as UidKind, Uid}; use crate::{EntityComponentRef, World}; @@ -154,6 +155,25 @@ impl<'a> Handle<'a> ) } + #[must_use] + pub fn get_first_wildcard_pair_match<Relation, Target>( + &self, + ) -> Option<PairWithWildcard<'a, Relation, Target>> + where + Relation: ComponentOrWildcard, + Target: ComponentOrWildcard, + { + let mut matching_comps = self.get_matching_components( + Pair::builder() + .relation_id(Relation::uid()) + .target_id(Target::uid()) + .build() + .id(), + ); + + Some(PairWithWildcard::new(self.world, matching_comps.next()?)) + } + #[inline] #[must_use] pub fn get_matching_components(&self, component_uid: Uid) |