Improvement on initial version

(check if all entities are in active set)
main
Elijah Voigt 2 years ago
parent 08bd782db3
commit 6e1fdb5207

@ -208,34 +208,40 @@ pub(crate) fn check_for_sets(
mut help_set: Local<Option<(Entity, Entity, Entity)>>,
mut commands: Commands,
) {
if help_set.is_none() {
*help_set = cards
.iter_combinations()
.find_map(|[(ea, ca), (eb, cb), (ec, cc)]| {
info!("\n\t{}\n\t{}\n\t{}", ca, cb, cc);
(is_set((ca, cb, cc))).then_some((ea, eb, ec))
});
match *help_set {
None => {
*help_set = cards
.iter_combinations()
.find_map(|[(ea, ca), (eb, cb), (ec, cc)]| {
(is_set((ca, cb, cc))).then_some((ea, eb, ec))
});
}
Some((a, b, c)) => {
if cards.get_many([a, b, c]).is_err() {
*help_set = cards
.iter_combinations()
.find_map(|[(ea, ca), (eb, cb), (ec, cc)]| {
(is_set((ca, cb, cc))).then_some((ea, eb, ec))
});
}
}
}
// TODO: Check if help_set cards are all still on board, if not set to None
help_set.iter().for_each(|(a, b, c)| {
info!("Processing {} {} {}", a, b, c);
match (
selected.contains(*a),
selected.contains(*b),
selected.contains(*c),
) {
(false, false, false) => {
info!("Adding selected to first card");
commands.entity(*a).insert(Selected);
}
(true, false, false) => {
info!("Adding selected to second card");
commands.entity(*b).insert(Selected);
}
(true, true, false) => {
info!("Adding selected to third card");
commands.entity(*c).insert(Selected);
}
(true, true, true) => info!("I can't hold your hand any further."),

Loading…
Cancel
Save