diff options
| author | HampusM <hampus@hampusmat.com> | 2026-10-30 05:37:18 +0100 |
|---|---|---|
| committer | HampusM <hampus@hampusmat.com> | 2026-10-30 05:52:48 +0100 |
| commit | 3b94659adf7fb25999c2815cb903f71eb1087896 (patch) | |
| tree | 7e70c313dd6d9549eb36dd8f1b1b39862904bc4e | |
| parent | 723f48d8e008d216978b8ed7d70499c972cc5a1c (diff) | |
feat(engine-ecs): add entity::Handle fn to check for component by type
| -rw-r--r-- | engine-ecs/src/entity.rs | 9 | ||||
| -rw-r--r-- | engine-ecs/src/phase.rs | 3 |
2 files changed, 9 insertions, 3 deletions
diff --git a/engine-ecs/src/entity.rs b/engine-ecs/src/entity.rs index 7515f73..4d472ad 100644 --- a/engine-ecs/src/entity.rs +++ b/engine-ecs/src/entity.rs @@ -232,9 +232,16 @@ impl<'a> Handle<'a> } } + /// Returns whether or not this entity contains the specified component. + #[must_use] + pub fn has_component<ComponentT: Component>(&self) -> bool + { + self.has_component_by_id(ComponentT::id()) + } + /// Returns whether or not this entity contains a component with the specified `Uid`. #[must_use] - pub fn has_component(&self, component_uid: Uid) -> bool + pub fn has_component_by_id(&self, component_uid: Uid) -> bool { self.archetype .contains_component_with_exact_id(component_uid) diff --git a/engine-ecs/src/phase.rs b/engine-ecs/src/phase.rs index e5008ad..8d09ab4 100644 --- a/engine-ecs/src/phase.rs +++ b/engine-ecs/src/phase.rs @@ -1,4 +1,3 @@ -use crate::component::WithAssociatedId as _; use crate::{declare_entity, Component, World}; #[cfg(debug_assertions)] use crate::{ @@ -57,7 +56,7 @@ pub(crate) fn check_parents( continue; }; - if !parent_ent.has_component(Phase::id()) { + if !parent_ent.has_component::<Phase>() { let parent_ent_name = parent_ent.get::<EntityName>(); tracing::warn!( |
