Skip to content

Commit

Permalink
feat: persisted selection
Browse files Browse the repository at this point in the history
  • Loading branch information
roboteng committed Oct 29, 2023
1 parent 406b307 commit 97018d7
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions game/src/in_game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,21 +113,23 @@ struct Health {
}

fn apply_seelected(
q: Query<(&Health, &PickingInteraction), Changed<PickingInteraction>>,
q: Query<(&Health, &PickSelection)>,
mut texts: Query<&mut Text, With<HealthVis>>,
) {
for (health, interaction) in &q {
for mut text in &mut texts {
match interaction {
PickingInteraction::Pressed => {
text.sections = vec![TextSection {
value: format!("{} of {}", health.current, health.max),
style: TextStyle::default(),
}]
}
PickingInteraction::Hovered => {}
PickingInteraction::None => text.sections = vec![],
}
let selections = q
.iter()
.filter(|(_, s)| s.is_selected)
.map(|(h, _)| h)
.collect::<Vec<_>>();
for mut text in &mut texts {
if selections.len() == 1 {
let health = selections[0];
text.sections = vec![TextSection {
value: format!("{} of {}", health.current, health.max),
style: TextStyle::default(),
}];
} else {
text.sections = vec![];
}
}
}

0 comments on commit 97018d7

Please sign in to comment.