diff options
Diffstat (limited to 'ecs/examples/relationship.rs')
-rw-r--r-- | ecs/examples/relationship.rs | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/ecs/examples/relationship.rs b/ecs/examples/relationship.rs index e8fb327..6ad08e7 100644 --- a/ecs/examples/relationship.rs +++ b/ecs/examples/relationship.rs @@ -1,5 +1,5 @@ -use ecs::event::start::Start as StartEvent; -use ecs::relationship::Relationship; +use ecs::pair::{Pair, Wildcard}; +use ecs::phase::START as START_PHASE; use ecs::{Component, Query, World}; #[derive(Component)] @@ -17,14 +17,19 @@ struct Health health: u32, } +#[derive(Component)] struct Holding; -fn print_player_stats(player_query: Query<(Player, Health, Relationship<Holding, Sword>)>) +fn print_player_stats(player_query: Query<(&Player, &Health, Pair<Holding, Wildcard>)>) { - for (_, health, sword_relationship) in &player_query { + for (_, health, target_sword) in &player_query { println!("Player health: {}", health.health); - if let Some(sword) = sword_relationship.get(0) { + if let Some(sword_ent) = target_sword.get_entity() { + let sword = sword_ent + .get::<Sword>() + .expect("Sword entity is missing sword component"); + println!("Player sword attack strength: {}", sword.attack_strength); } } @@ -34,15 +39,15 @@ fn main() { let mut world = World::new(); - world.register_system(StartEvent, print_player_stats); + world.register_system(*START_PHASE, print_player_stats); let sword_uid = world.create_entity((Sword { attack_strength: 17 },)); world.create_entity(( Player, Health { health: 180 }, - Relationship::<Holding, Sword>::new(sword_uid), + Pair::new::<Holding>(sword_uid), )); - world.emit(StartEvent); + world.step(); } |