summaryrefslogtreecommitdiff
path: root/ecs/examples/multiple_queries.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2024-03-02 12:00:01 +0100
committerHampusM <hampus@hampusmat.com>2024-03-02 12:00:01 +0100
commit6f8aeb236725f673f199bce7a6f3942eb56a8318 (patch)
tree5ed2b80d57f9115843be8b11118d44e6ec973215 /ecs/examples/multiple_queries.rs
parent7c6391c1bea40c5260f4a750adc9d3c648b05db9 (diff)
feat(ecs): add event trait
Diffstat (limited to 'ecs/examples/multiple_queries.rs')
-rw-r--r--ecs/examples/multiple_queries.rs16
1 files changed, 11 insertions, 5 deletions
diff --git a/ecs/examples/multiple_queries.rs b/ecs/examples/multiple_queries.rs
index 9a699c2..ed02a69 100644
--- a/ecs/examples/multiple_queries.rs
+++ b/ecs/examples/multiple_queries.rs
@@ -1,5 +1,6 @@
use std::fmt::Display;
+use ecs::event::{Event, Id as EventId};
use ecs::{Component, Query, World};
#[derive(Component)]
@@ -57,16 +58,21 @@ fn do_attacks(
}
#[derive(Debug, PartialEq, Eq, Hash)]
-enum Event
+struct Start;
+
+impl Event for Start
{
- Start,
+ fn id(&self) -> EventId
+ {
+ EventId::of::<Self>()
+ }
}
fn main()
{
- let mut world = World::<Event>::new();
+ let mut world = World::new();
- world.register_system(Event::Start, do_attacks);
+ world.register_system(&Start, do_attacks);
world.create_entity((
Health { health: 100 },
@@ -86,5 +92,5 @@ fn main()
world.create_entity((AttackStrength::Strong,));
world.create_entity((AttackStrength::Weak,));
- world.emit(&Event::Start);
+ world.emit(&Start);
}