From 6f8aeb236725f673f199bce7a6f3942eb56a8318 Mon Sep 17 00:00:00 2001 From: HampusM Date: Sat, 2 Mar 2024 12:00:01 +0100 Subject: feat(ecs): add event trait --- ecs/examples/with_local.rs | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'ecs/examples/with_local.rs') diff --git a/ecs/examples/with_local.rs b/ecs/examples/with_local.rs index b37a5c3..0342930 100644 --- a/ecs/examples/with_local.rs +++ b/ecs/examples/with_local.rs @@ -1,4 +1,5 @@ use ecs::component::Local; +use ecs::event::{Event, Id as EventId}; use ecs::system::{Into, System}; use ecs::{Component, Query, World}; @@ -41,25 +42,30 @@ fn say_whats_up(query: Query<(SomeData, Name)>, mut state: Local) } } -#[derive(Debug, PartialEq, Eq, Hash)] -enum Event +#[derive(Debug)] +struct Update; + +impl Event for Update { - Update, + fn id(&self) -> EventId + { + EventId::of::() + } } fn main() { - let mut world = World::::new(); + let mut world = World::new(); world.register_system( - Event::Update, + &Update, say_hello .into_system() .initialize((SayHelloState { cnt: 0 },)), ); world.register_system( - Event::Update, + &Update, say_whats_up .into_system() .initialize((SayHelloState { cnt: 0 },)), @@ -69,9 +75,9 @@ fn main() world.create_entity((SomeData { num: 345 },)); - world.emit(&Event::Update); + world.emit(&Update); println!("Haha"); - world.emit(&Event::Update); + world.emit(&Update); } -- cgit v1.2.3-18-g5258