diff options
| author | HampusM <hampus@hampusmat.com> | 2026-06-20 16:35:45 +0200 |
|---|---|---|
| committer | HampusM <hampus@hampusmat.com> | 2026-06-23 00:25:39 +0200 |
| commit | 7dad5922276687d284269316158ec7e742f6d1fc (patch) | |
| tree | 28e2823dd619d7fdcf9ae032ba08b0978f4b9de2 /engine-ecs/src/entity.rs | |
| parent | 7b3374ad9585f78c60e1b158126ab54384a83f32 (diff) | |
feat(engine-ecs): add entity name component
Diffstat (limited to 'engine-ecs/src/entity.rs')
| -rw-r--r-- | engine-ecs/src/entity.rs | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/engine-ecs/src/entity.rs b/engine-ecs/src/entity.rs index d7b63be..9ef9da0 100644 --- a/engine-ecs/src/entity.rs +++ b/engine-ecs/src/entity.rs @@ -1,14 +1,15 @@ use std::any::{type_name, Any}; +use std::borrow::Cow; use std::ops::Deref; use std::sync::LazyLock; +use crate::Component; use crate::component::storage::archetype::{ Archetype, Entity as ArchetypeEntity, MatchingComponentIter as ArchetypeMatchingComponentIter, }; use crate::component::{ - Component, Handle as ComponentHandle, HandleMut as ComponentHandleMut, }; @@ -42,6 +43,18 @@ impl<'a> Handle<'a> self.entity.uid() } + /// Returns a reference to the [`Name`] component in this entity. `None` is + /// returned if the component isn't found in the entity. + /// + /// # Panics + /// Will panic if: + /// - The component is mutably borrowed elsewhere + #[must_use] + pub fn get_name(&self) -> Option<ComponentHandle<'a, Name>> + { + self.get::<Name>() + } + /// Returns a reference to the specified component in this entity. `None` is /// returned if the component isn't found in the entity. /// @@ -315,3 +328,10 @@ macro_rules! declare_entity { }); } } + +/// Entity name. +#[derive(Debug, Clone, Component)] +pub struct Name +{ + pub name: Cow<'static, str> +} |
