diff --git a/src/debug.rs b/src/debug.rs index b8f2014..6f96a8d 100644 --- a/src/debug.rs +++ b/src/debug.rs @@ -18,7 +18,7 @@ pub(crate) struct DebugText; fn init_ui(mut commands: Commands) { commands .spawn(( - Sprite::from_color(Color::BLACK.with_alpha(0.9), [100.0, 100.0].into()), + Sprite::from_color(Color::BLACK.with_alpha(0.9), [250.0, 150.0].into()), DebugText, Visibility::Hidden, Transform::default().with_translation(Vec3::new(0.0, 0.0, 1.0)), @@ -42,7 +42,7 @@ fn track_card_info( let p = trigger.pointer_location.position; transforms.iter_mut().for_each(|mut t| { let offset = window.single().resolution.size() / 2.0; - let pos = p - offset + Vec2::new(-50.0, 50.0); + let pos = p - offset + Vec2::new(-125.0, 75.0); t.translation.x = pos.x; t.translation.y = -pos.y; }); @@ -56,7 +56,7 @@ pub(crate) fn set_debug_card( ) { let card = cards.get(trigger.entity()).unwrap(); debug_text.iter_mut().for_each(|mut text| { - text.0 = format!("{}", card); + text.0 = format!("{:#?}", card); }); vis.iter_mut().for_each(|mut v| { *v = Visibility::Inherited; diff --git a/src/deck.rs b/src/deck.rs index a977ca9..29c0c4b 100644 --- a/src/deck.rs +++ b/src/deck.rs @@ -116,7 +116,7 @@ impl std::fmt::Display for Card { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!( f, - "{}\n{}\n{}\n{}", + "{} {} {} {}", self.number, self.pattern, self.color, self.shape ) } diff --git a/src/menu.rs b/src/menu.rs index 86cfef1..2d2a977 100644 --- a/src/menu.rs +++ b/src/menu.rs @@ -1,9 +1,12 @@ use bevy::{ - color::palettes::css::{BLACK, INDIGO, ORANGE, PURPLE, RED, TEAL}, + color::palettes::css::{BLACK, GREEN, INDIGO, ORANGE, PURPLE, RED, TEAL}, prelude::*, }; -use crate::view::{button_set_state, ViewState}; +use crate::{ + play::check_for_sets, + view::{button_set_state, ViewState}, +}; /// Game Menu pub struct MenuPlugin; @@ -74,6 +77,12 @@ fn setup(mut commands: Commands) { parent.spawn(Text("Sets".to_string())); }) .observe(button_set_state(ViewState::Sets)); + parent + .spawn((Button, BackgroundColor(GREEN.into()), GlobalZIndex(1))) + .with_children(|parent| { + parent.spawn(Text("Help!".to_string())); + }) + .observe(check_for_sets); }); } diff --git a/src/play.rs b/src/play.rs index ee60827..84f426f 100644 --- a/src/play.rs +++ b/src/play.rs @@ -200,3 +200,46 @@ pub(crate) fn place_card( // Set it to visible *visibility = Visibility::Inherited; } + +pub(crate) fn check_for_sets( + _trigger: Trigger>, + cards: Query<(Entity, &Card), With>, + selected: Query>, + mut help_set: Local>, + 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)) + }); + } + + // 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."), + _ => panic!("How???"), + } + }); +} diff --git a/src/view.rs b/src/view.rs index a177528..2ba7e0c 100644 --- a/src/view.rs +++ b/src/view.rs @@ -39,7 +39,6 @@ fn state_monitor( entities .iter_mut() .for_each(|(view_state, mut visibility)| { - info!("Transition from {:?} to {:?}", event.exited, event.entered); if Some(view_state) == event.entered.as_ref() { *visibility = Visibility::Inherited; } else {