summaryrefslogtreecommitdiff
path: root/ecs/src/event/component.rs
diff options
context:
space:
mode:
Diffstat (limited to 'ecs/src/event/component.rs')
-rw-r--r--ecs/src/event/component.rs48
1 files changed, 48 insertions, 0 deletions
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<ComponentT>
+where
+ ComponentT: Component,
+{
+ _pd: PhantomData<ComponentT>,
+}
+
+impl<ComponentT> Debug for Removed<ComponentT>
+where
+ ComponentT: Component,
+{
+ fn fmt(&self, formatter: &mut Formatter<'_>) -> std::fmt::Result
+ {
+ formatter
+ .debug_struct("Removed")
+ .field("_pd", &self._pd)
+ .finish()
+ }
+}
+
+impl<ComponentT> Default for Removed<ComponentT>
+where
+ ComponentT: Component,
+{
+ fn default() -> Self
+ {
+ Self { _pd: PhantomData }
+ }
+}
+
+impl<ComponentT> Event for Removed<ComponentT>
+where
+ ComponentT: Component,
+{
+ fn id() -> Id
+ where
+ Self: Sized,
+ {
+ Id::new::<Removed<ComponentForId>, _>(Some(ComponentId::of::<ComponentT>()))
+ }
+}
+
pub fn create_added_id(component_id: ComponentId) -> Id
{
Id::new::<Added<ComponentForId>, _>(Some(component_id))
}
+pub fn create_removed_id(component_id: ComponentId) -> Id
+{
+ Id::new::<Removed<ComponentForId>, _>(Some(component_id))
+}
+
pub struct ComponentToAddedEvent;
impl<ComponentT: Component, Accumulator>