diff options
Diffstat (limited to 'ecs/examples')
-rw-r--r-- | ecs/examples/event_loop.rs | 17 | ||||
-rw-r--r-- | ecs/examples/relationship.rs | 16 | ||||
-rw-r--r-- | ecs/examples/with_sole.rs | 4 |
3 files changed, 16 insertions, 21 deletions
diff --git a/ecs/examples/event_loop.rs b/ecs/examples/event_loop.rs index 2365eb0..61d7ba4 100644 --- a/ecs/examples/event_loop.rs +++ b/ecs/examples/event_loop.rs @@ -1,6 +1,6 @@ use ecs::actions::Actions; +use ecs::pair::{ChildOf, Pair}; use ecs::phase::{Phase, UPDATE as UPDATE_PHASE}; -use ecs::relationship::{ChildOf, Relationship}; use ecs::{static_entity, Component, Query, World}; #[derive(Component)] @@ -65,20 +65,11 @@ fn age(query: Query<(&mut Health, &Name)>, mut actions: Actions) } } -static_entity!( - SHEER_PHASE, - (Phase, <Relationship<ChildOf, Phase>>::new(*UPDATE_PHASE)) -); +static_entity!(SHEER_PHASE, (Phase, Pair::new::<ChildOf>(*UPDATE_PHASE))); -static_entity!( - FEED_PHASE, - (Phase, <Relationship<ChildOf, Phase>>::new(*SHEER_PHASE)) -); +static_entity!(FEED_PHASE, (Phase, Pair::new::<ChildOf>(*SHEER_PHASE))); -static_entity!( - AGE_PHASE, - (Phase, <Relationship<ChildOf, Phase>>::new(*FEED_PHASE)) -); +static_entity!(AGE_PHASE, (Phase, Pair::new::<ChildOf>(*FEED_PHASE))); fn main() { diff --git a/ecs/examples/relationship.rs b/ecs/examples/relationship.rs index 240884a..b607398 100644 --- a/ecs/examples/relationship.rs +++ b/ecs/examples/relationship.rs @@ -1,5 +1,6 @@ +use ecs::pair::Pair; use ecs::phase::START as START_PHASE; -use ecs::relationship::Relationship; +use ecs::uid::Wildcard; use ecs::{Component, Query, World}; #[derive(Component)] @@ -17,16 +18,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 { println!("Player health: {}", health.health); - if let Some(sword) = sword_relationship.get(0) { + if let Some(sword_ent) = sword_relationship.get_target_entity() { + let sword = sword_ent + .get::<Sword>() + .expect("Sword entity is missing sword component"); + println!("Player sword attack strength: {}", sword.attack_strength); } } @@ -43,7 +47,7 @@ fn main() world.create_entity(( Player, Health { health: 180 }, - Relationship::<Holding, Sword>::new(sword_uid), + Pair::new::<Holding>(sword_uid), )); world.step(); diff --git a/ecs/examples/with_sole.rs b/ecs/examples/with_sole.rs index 689e562..c3feaab 100644 --- a/ecs/examples/with_sole.rs +++ b/ecs/examples/with_sole.rs @@ -1,5 +1,5 @@ +use ecs::pair::{ChildOf, Pair}; use ecs::phase::{Phase, UPDATE as UPDATE_PHASE}; -use ecs::relationship::{ChildOf, Relationship}; use ecs::sole::Single; use ecs::{static_entity, Component, Query, Sole, World}; @@ -33,7 +33,7 @@ fn print_total_ammo_count(ammo_counter: Single<AmmoCounter>) static_entity!( PRINT_AMMO_COUNT_PHASE, - (Phase, <Relationship<ChildOf, Phase>>::new(*UPDATE_PHASE)) + (Phase, Pair::new::<ChildOf>(*UPDATE_PHASE)) ); fn main() |