summaryrefslogtreecommitdiff
path: root/ecs/examples/relationship.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2025-04-09 20:50:14 +0200
committerHampusM <hampus@hampusmat.com>2025-04-10 17:04:40 +0200
commit94e5e592baea2935af7c94ad44805a09d0e30740 (patch)
tree358f7496ac40e2a7d7cae10cf04bf25246debdec /ecs/examples/relationship.rs
parentb982b205373f445db9ced7f3cf13c1156ad8a40a (diff)
feat(ecs): replace Relationship component with pair UID support
Diffstat (limited to 'ecs/examples/relationship.rs')
-rw-r--r--ecs/examples/relationship.rs16
1 files changed, 10 insertions, 6 deletions
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();