From 815d04da602c58ed8b13eeb612fe73180204039d Mon Sep 17 00:00:00 2001 From: HampusM Date: Mon, 26 Feb 2024 20:05:27 +0100 Subject: fix(ecs): make Component trait not automatic & add derive macro --- ecs/examples/simple.rs | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'ecs/examples/simple.rs') diff --git a/ecs/examples/simple.rs b/ecs/examples/simple.rs index b58d2ba..b8dc50f 100644 --- a/ecs/examples/simple.rs +++ b/ecs/examples/simple.rs @@ -1,14 +1,21 @@ -use ecs::{Query, World}; +use ecs::{Component, Query, World}; +#[derive(Component)] struct SomeData { num: u64, } -fn say_hello(mut query: Query<(SomeData, String)>) +#[derive(Component)] +struct Greeting { - for (data, text) in query.iter_mut() { - println!("Hello {}: {}", text, data.num); + greeting: String, +} + +fn say_hello(mut query: Query<(SomeData, Greeting)>) +{ + for (data, greeting) in query.iter_mut() { + println!("{}: {}", greeting.greeting, data.num); } } @@ -24,9 +31,17 @@ fn main() world.register_system(Event::Start, say_hello); - world.create_entity((SomeData { num: 987_654 }, "Yoo".to_string())); - - world.create_entity((SomeData { num: 345 }, "Haha".to_string())); + world.create_entity(( + SomeData { num: 987_654 }, + Greeting { + greeting: "Good afternoon".to_string(), + }, + )); + + world.create_entity(( + SomeData { num: 345 }, + Greeting { greeting: "Good evening".to_string() }, + )); world.emit(&Event::Start); } -- cgit v1.2.3-18-g5258