diff options
author | HampusM <hampus@hampusmat.com> | 2025-10-12 17:13:42 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2025-10-13 17:22:35 +0200 |
commit | 88a33aed4115984d496fcd12a965f9c4aaa0faf6 (patch) | |
tree | 56e73790c9d1b8662d7997d93756ce9b2fadb8af /ecs/examples/component_removed_event.rs | |
parent | ea1d70c8c28e3b96da6264021fa1c62e28fcd8e4 (diff) |
feat(ecs): emit Removed events before component removal
Diffstat (limited to 'ecs/examples/component_removed_event.rs')
-rw-r--r-- | ecs/examples/component_removed_event.rs | 15 |
1 files changed, 12 insertions, 3 deletions
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<Pair<Removed, Cheese>>) { for evt_match in &observe { - println!("Cheese entity {} was eaten", evt_match.id()); + let ent = evt_match.get_entity().unwrap(); + + let cheese = ent.get::<Cheese>().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(); |