diff options
author | HampusM <hampus@hampusmat.com> | 2025-10-13 22:03:22 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2025-10-13 22:03:22 +0200 |
commit | a1816f82c2d5c18cfd3282047632959028685a45 (patch) | |
tree | bcc10a80145f16ebe258955eca4efdbbc7bf787d /ecs | |
parent | cb1197a132f87cd5034bb8927fdbd09878d9239a (diff) |
feat(ecs): add get_wildcard_pair_matches fn to entity::Handle
Diffstat (limited to 'ecs')
-rw-r--r-- | ecs/src/entity.rs | 18 | ||||
-rw-r--r-- | ecs/src/pair.rs | 27 |
2 files changed, 44 insertions, 1 deletions
diff --git a/ecs/src/entity.rs b/ecs/src/entity.rs index 8c07ea8..ad9f179 100644 --- a/ecs/src/entity.rs +++ b/ecs/src/entity.rs @@ -12,7 +12,12 @@ use crate::component::{ Handle as ComponentHandle, HandleMut as ComponentHandleMut, }; -use crate::pair::{ComponentOrWildcard, Pair, WithWildcard as PairWithWildcard}; +use crate::pair::{ + ComponentOrWildcard, + MultipleWithWildcard as PairMultipleWithWildcard, + Pair, + WithWildcard as PairWithWildcard, +}; use crate::uid::{Kind as UidKind, Uid}; use crate::{EntityComponentRef, World}; @@ -174,6 +179,17 @@ impl<'a> Handle<'a> Some(PairWithWildcard::new(self.world, matching_comps.next()?)) } + #[must_use] + pub fn get_wildcard_pair_matches<Relation, Target>( + &self, + ) -> PairMultipleWithWildcard<'a, Relation, Target> + where + Relation: ComponentOrWildcard, + Target: ComponentOrWildcard, + { + PairMultipleWithWildcard::new(self.world, self.clone()) + } + #[inline] #[must_use] pub fn get_matching_components(&self, component_uid: Uid) diff --git a/ecs/src/pair.rs b/ecs/src/pair.rs index 8bef70a..f9f76e7 100644 --- a/ecs/src/pair.rs +++ b/ecs/src/pair.rs @@ -542,6 +542,33 @@ pub struct MultipleWithWildcard<'a, Relation, Target> _pd: PhantomData<(Relation, Target)>, } +impl<'world, Relation, Target> MultipleWithWildcard<'world, Relation, Target> +{ + /// Returns a new `MultipleWithWildcard`. + /// + /// # Panics + /// This function will panic if: + /// - Both `Relation::uid()` and `Target::uid()` are wildcards + /// - Neither `Relation::uid()` or `Target::uid()` are wildcards + pub fn new(world: &'world World, entity_handle: EntityHandle<'world>) -> Self + where + Relation: ComponentOrWildcard, + Target: ComponentOrWildcard, + { + assert!(Relation::uid() == Wildcard::uid() || Target::uid() == Wildcard::uid()); + + assert!( + !(Relation::uid() == Wildcard::uid() && Target::uid() == Wildcard::uid()) + ); + + MultipleWithWildcard { + entity_handle, + world, + _pd: PhantomData, + } + } +} + impl<'a, Relation: Component> MultipleWithWildcard<'a, Relation, Wildcard> { #[must_use] |