From d7d07c6437ead8b3ef2b6c967268d6d151ac4237 Mon Sep 17 00:00:00 2001 From: HampusM Date: Mon, 13 Oct 2025 18:05:16 +0200 Subject: feat(ecs): add get_first_wildcard_pair_match fn to entity::Handle --- ecs/src/entity.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'ecs/src/entity.rs') 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( + &self, + ) -> Option> + 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) -- cgit v1.2.3-18-g5258