summaryrefslogtreecommitdiff
path: root/ecs/examples/component_removed_event.rs
diff options
context:
space:
mode:
Diffstat (limited to 'ecs/examples/component_removed_event.rs')
-rw-r--r--ecs/examples/component_removed_event.rs15
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();