From 88a33aed4115984d496fcd12a965f9c4aaa0faf6 Mon Sep 17 00:00:00 2001 From: HampusM Date: Sun, 12 Oct 2025 17:13:42 +0200 Subject: feat(ecs): emit Removed events before component removal --- ecs/examples/component_removed_event.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'ecs/examples/component_removed_event.rs') diff --git a/ecs/examples/component_removed_event.rs b/ecs/examples/component_removed_event.rs index e8d1a47..f984092 100644 --- a/ecs/examples/component_removed_event.rs +++ b/ecs/examples/component_removed_event.rs @@ -7,7 +7,10 @@ use ecs::system::observer::Observe; use ecs::{Component, Query, World}; #[derive(Debug, Component)] -struct Cheese; +struct Cheese +{ + name: &'static str, +} fn eat_cheese(query: Query<(&Cheese,)>, mut actions: Actions) { @@ -21,7 +24,11 @@ fn eat_cheese(query: Query<(&Cheese,)>, mut actions: Actions) fn on_cheese_removed(observe: Observe>) { for evt_match in &observe { - println!("Cheese entity {} was eaten", evt_match.id()); + let ent = evt_match.get_entity().unwrap(); + + let cheese = ent.get::().unwrap(); + + println!("{} cheese was eaten", cheese.name); } } @@ -32,7 +39,9 @@ fn main() world.register_system(*UPDATE, eat_cheese); world.register_observer(on_cheese_removed); - world.create_entity((Cheese,)); + world.create_entity((Cheese { name: "Brie" },)); + world.create_entity((Cheese { name: "Parmesan" },)); + world.create_entity((Cheese { name: "Gouda" },)); world.step(); world.step(); -- cgit v1.2.3-18-g5258