diff options
author | HampusM <hampus@hampusmat.com> | 2025-10-13 18:05:16 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2025-10-13 18:05:16 +0200 |
commit | d7d07c6437ead8b3ef2b6c967268d6d151ac4237 (patch) | |
tree | 40185bcd93f17d6c0c1986e9280c087b7997b938 /ecs/src/entity.rs | |
parent | 88a33aed4115984d496fcd12a965f9c4aaa0faf6 (diff) |
feat(ecs): add get_first_wildcard_pair_match fn to entity::Handle
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) |