diff options
author | HampusM <hampus@hampusmat.com> | 2024-11-11 22:16:17 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2024-11-11 22:16:17 +0100 |
commit | 136d0511972fd31a82331cf769f8d309cd3438f8 (patch) | |
tree | fa2f242ed1d2b230be4adffa27194f7664970fc4 /ecs/src/relationship.rs | |
parent | df30c1f504e8282fb707b90cce6ee422f17d2ed1 (diff) |
refactor(ecs): make Relationship use Component derive macro
Diffstat (limited to 'ecs/src/relationship.rs')
-rw-r--r-- | ecs/src/relationship.rs | 68 |
1 files changed, 11 insertions, 57 deletions
diff --git a/ecs/src/relationship.rs b/ecs/src/relationship.rs index 259677b..0ebd9c2 100644 --- a/ecs/src/relationship.rs +++ b/ecs/src/relationship.rs @@ -1,6 +1,7 @@ -use std::any::{type_name, Any}; +use std::any::type_name; use std::marker::PhantomData; -use std::sync::LazyLock; + +use ecs_macros::Component; use crate::component::storage::Storage as ComponentStorage; use crate::component::{ @@ -9,14 +10,19 @@ use crate::component::{ FromOptionalMut as FromOptionalMutComponent, }; use crate::lock::ReadGuard; -use crate::system::{ComponentRef, ComponentRefMut, Input as SystemInput}; -use crate::type_name::TypeName; +use crate::system::{ComponentRef, ComponentRefMut}; use crate::uid::{Kind as UidKind, Uid}; use crate::World; /// A relationship to one or more targets. -#[derive(Debug)] +#[derive(Debug, Component)] +#[component( + ref_type = Relation<'component, Kind, ComponentT>, + ref_mut_type = RelationMut<'component, Kind, ComponentT>, +)] pub struct Relationship<Kind, ComponentT: Component> +where + Kind: 'static, { entity_uid: SingleOrMultiple<Uid>, _pd: PhantomData<(Kind, ComponentT)>, @@ -55,58 +61,6 @@ where } } -static COMPONENT_EUID: LazyLock<Uid> = - LazyLock::new(|| Uid::new_unique(UidKind::Component)); - -impl<Kind, ComponentT> Component for Relationship<Kind, ComponentT> -where - Kind: 'static, - ComponentT: Component, -{ - type Component = Self; - type Ref<'component> = Relation<'component, Kind, ComponentT>; - type RefMut<'component> = RelationMut<'component, Kind, ComponentT>; - - fn id() -> Uid - where - Self: Sized, - { - *COMPONENT_EUID - } - - fn self_id(&self) -> Uid - { - Self::id() - } - - fn as_any_mut(&mut self) -> &mut dyn Any - { - self - } - - fn as_any(&self) -> &dyn Any - { - self - } -} - -impl<Kind, ComponentT> SystemInput for Relationship<Kind, ComponentT> -where - Kind: 'static, - ComponentT: Component, -{ -} - -impl<Kind, ComponentT: Component> TypeName for Relationship<Kind, ComponentT> -where - ComponentT: Component, -{ - fn type_name(&self) -> &'static str - { - type_name::<Self>() - } -} - pub struct RelationMut<'rel_comp, Kind, ComponentT> where Kind: 'static, |