|
|
|
@ -64,7 +64,7 @@ pub(crate) fn reset_rotation(
|
|
|
|
|
|
|
|
|
|
|
|
/// Check a set when the "Set" button is clicked
|
|
|
|
/// Check a set when the "Set" button is clicked
|
|
|
|
pub(crate) fn check_set(
|
|
|
|
pub(crate) fn check_set(
|
|
|
|
trigger: Trigger<Pointer<Click>>,
|
|
|
|
_trigger: Trigger<Pointer<Click>>,
|
|
|
|
mut query: Query<(Entity, &Card, &mut Visibility, &mut Transform), With<Selected>>,
|
|
|
|
mut query: Query<(Entity, &Card, &mut Visibility, &mut Transform), With<Selected>>,
|
|
|
|
mut commands: Commands,
|
|
|
|
mut commands: Commands,
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
@ -205,47 +205,49 @@ pub(crate) fn check_for_sets(
|
|
|
|
_trigger: Trigger<Pointer<Click>>,
|
|
|
|
_trigger: Trigger<Pointer<Click>>,
|
|
|
|
cards: Query<(Entity, &Card), With<PlayLocation>>,
|
|
|
|
cards: Query<(Entity, &Card), With<PlayLocation>>,
|
|
|
|
selected: Query<Entity, With<Selected>>,
|
|
|
|
selected: Query<Entity, With<Selected>>,
|
|
|
|
mut help_set: Local<Option<(Entity, Entity, Entity)>>,
|
|
|
|
|
|
|
|
mut commands: Commands,
|
|
|
|
mut commands: Commands,
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
match *help_set {
|
|
|
|
cards
|
|
|
|
None => {
|
|
|
|
// Iterate over all combinations of cards on the board
|
|
|
|
*help_set = cards
|
|
|
|
|
|
|
|
.iter_combinations()
|
|
|
|
.iter_combinations()
|
|
|
|
|
|
|
|
// Only find combinations including currently selected cards
|
|
|
|
|
|
|
|
.filter(|[(ea, _ca), (eb, _cb), (ec, _cc)]| {
|
|
|
|
|
|
|
|
// If selected is empty, proceed
|
|
|
|
|
|
|
|
match selected.iter().len() {
|
|
|
|
|
|
|
|
0 => true,
|
|
|
|
|
|
|
|
1 | 2 | 3 => {
|
|
|
|
|
|
|
|
let a = selected.contains(*ea);
|
|
|
|
|
|
|
|
let b = selected.contains(*eb);
|
|
|
|
|
|
|
|
let c = selected.contains(*ec);
|
|
|
|
|
|
|
|
match selected.iter().len() {
|
|
|
|
|
|
|
|
1 => a || b || c,
|
|
|
|
|
|
|
|
2 => a && b || b && c || a && c,
|
|
|
|
|
|
|
|
3 => a && b && c,
|
|
|
|
|
|
|
|
_ => panic!("WTF?"),
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
_ => panic!("Impossible!"),
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
// return the first valid set
|
|
|
|
.find_map(|[(ea, ca), (eb, cb), (ec, cc)]| {
|
|
|
|
.find_map(|[(ea, ca), (eb, cb), (ec, cc)]| {
|
|
|
|
(is_set((ca, cb, cc))).then_some((ea, eb, ec))
|
|
|
|
if is_set((ca, cb, cc)) {
|
|
|
|
});
|
|
|
|
info!("\n\t{}\n\t{}\n\t{}", ca, cb, cc);
|
|
|
|
}
|
|
|
|
Some((ea, eb, ec))
|
|
|
|
Some((a, b, c)) => {
|
|
|
|
} else {
|
|
|
|
if cards.get_many([a, b, c]).is_err() {
|
|
|
|
None
|
|
|
|
*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
|
|
|
|
.iter()
|
|
|
|
|
|
|
|
.for_each(|(a, b, c)| {
|
|
|
|
help_set.iter().for_each(|(a, b, c)| {
|
|
|
|
if !selected.contains(*a) {
|
|
|
|
match (
|
|
|
|
|
|
|
|
selected.contains(*a),
|
|
|
|
|
|
|
|
selected.contains(*b),
|
|
|
|
|
|
|
|
selected.contains(*c),
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
(false, false, false) => {
|
|
|
|
|
|
|
|
commands.entity(*a).insert(Selected);
|
|
|
|
commands.entity(*a).insert(Selected);
|
|
|
|
}
|
|
|
|
} else if !selected.contains(*b) {
|
|
|
|
(true, false, false) => {
|
|
|
|
|
|
|
|
commands.entity(*b).insert(Selected);
|
|
|
|
commands.entity(*b).insert(Selected);
|
|
|
|
}
|
|
|
|
} else if !selected.contains(*c) {
|
|
|
|
(true, true, false) => {
|
|
|
|
|
|
|
|
commands.entity(*c).insert(Selected);
|
|
|
|
commands.entity(*c).insert(Selected);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
(true, true, true) => info!("I can't hold your hand any further."),
|
|
|
|
info!("I cannot hold your hand further...");
|
|
|
|
_ => panic!("How???"),
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|