From 7d25c21cdf4b46cdab680f11110fb23676c6141b Mon Sep 17 00:00:00 2001 From: HampusM Date: Thu, 10 Apr 2025 17:39:21 +0200 Subject: feat(ecs): re-add support for component events --- ecs/src/event/component.rs | 98 ++++++++-------------------------------------- 1 file changed, 16 insertions(+), 82 deletions(-) (limited to 'ecs/src/event/component.rs') diff --git a/ecs/src/event/component.rs b/ecs/src/event/component.rs index b4edffc..ef09480 100644 --- a/ecs/src/event/component.rs +++ b/ecs/src/event/component.rs @@ -1,84 +1,18 @@ //! Component events. -use std::fmt::{Debug, Formatter}; -use std::marker::PhantomData; - -use ecs_macros::Component; - -use crate::component::Component; - -/// Event emitted when: -/// a) A entity with component `ComponentT` is spawned. -/// b) A component `ComponentT` is added to a entity. -#[derive(Clone, Component)] -pub struct Added -where - ComponentT: Component, -{ - _pd: PhantomData, -} - -impl Debug for Added -where - ComponentT: Component, -{ - fn fmt(&self, formatter: &mut Formatter<'_>) -> std::fmt::Result - { - formatter - .debug_struct("Added") - .field("_pd", &self._pd) - .finish() - } -} - -impl Default for Added -where - ComponentT: Component, -{ - fn default() -> Self - { - Self { _pd: PhantomData } - } -} - -/// Event emitted when: -/// a) A `ComponentT` component is removed from a entity. -/// b) A entity with component `ComponentT` is despawned. -#[derive(Clone, Component)] -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 } - } -} - -/// Specifies a kind of component event UID. -#[derive(Debug, Clone, Copy)] -#[non_exhaustive] -pub enum Kind -{ - Removed, -} +use std::convert::Infallible; +use std::fmt::Debug; + +use crate::Component; + +/// Pair relation for events emitted when: +/// a) A entity with the target component is spawned. +/// b) The target component is added to a entity. +#[derive(Debug, Component)] +pub struct Added(Infallible); + +/// Pair relation for events emitted when: +/// a) The target component is removed from a entity. +/// b) A entity with the target component is despawned. +#[derive(Debug, Component)] +pub struct Removed(Infallible); -- cgit v1.2.3-18-g5258