use ecs::pair::Pair; use ecs::phase::START as START_PHASE; use ecs::uid::Wildcard; use ecs::{Component, Query, World}; #[derive(Component)] struct Sword { attack_strength: u32, } #[derive(Component)] struct Player; #[derive(Component)] struct Health { health: u32, } #[derive(Component)] struct Holding; fn print_player_stats(player_query: Query<(&Player, &Health, Pair)>) { for (_, health, sword_relationship) in &player_query { println!("Player health: {}", health.health); if let Some(sword_ent) = sword_relationship.get_target_entity() { let sword = sword_ent .get::() .expect("Sword entity is missing sword component"); println!("Player sword attack strength: {}", sword.attack_strength); } } } fn main() { let mut world = World::new(); 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 }, Pair::new::(sword_uid), )); world.step(); }