From 3b94659adf7fb25999c2815cb903f71eb1087896 Mon Sep 17 00:00:00 2001 From: HampusM Date: Fri, 30 Oct 2026 05:37:18 +0100 Subject: feat(engine-ecs): add entity::Handle fn to check for component by type --- engine-ecs/src/entity.rs | 9 ++++++++- 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(&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::() { let parent_ent_name = parent_ent.get::(); tracing::warn!( -- cgit v1.2.3-18-g5258