From 30f7ab671486c95287fb8d1c791aabef7007987c Mon Sep 17 00:00:00 2001 From: HampusM Date: Thu, 15 Aug 2024 19:04:03 +0200 Subject: feat(ecs): add component removed event --- ecs/src/event/component.rs | 48 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'ecs/src/event/component.rs') diff --git a/ecs/src/event/component.rs b/ecs/src/event/component.rs index 306d43f..4628cb1 100644 --- a/ecs/src/event/component.rs +++ b/ecs/src/event/component.rs @@ -54,11 +54,59 @@ where } } +/// Event emitted when a `ComponentT` component is removed from a entity. +pub struct Removed +where + ComponentT: Component, +{ + _pd: PhantomData, +} + +impl Debug for Removed +where + ComponentT: Component, +{ + fn fmt(&self, formatter: &mut Formatter<'_>) -> std::fmt::Result + { + formatter + .debug_struct("Removed") + .field("_pd", &self._pd) + .finish() + } +} + +impl Default for Removed +where + ComponentT: Component, +{ + fn default() -> Self + { + Self { _pd: PhantomData } + } +} + +impl Event for Removed +where + ComponentT: Component, +{ + fn id() -> Id + where + Self: Sized, + { + Id::new::, _>(Some(ComponentId::of::())) + } +} + pub fn create_added_id(component_id: ComponentId) -> Id { Id::new::, _>(Some(component_id)) } +pub fn create_removed_id(component_id: ComponentId) -> Id +{ + Id::new::, _>(Some(component_id)) +} + pub struct ComponentToAddedEvent; impl -- cgit v1.2.3-18-g5258