summaryrefslogtreecommitdiff
path: root/ecs
diff options
context:
space:
mode:
Diffstat (limited to 'ecs')
-rw-r--r--ecs/src/relationship.rs68
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,