From 92e4bf9653a3b5ddeda614ac381ff1db47e42d65 Mon Sep 17 00:00:00 2001 From: Elijah Voigt Date: Sat, 7 Dec 2024 21:28:05 -0800 Subject: [PATCH] scaffolding for checking set --- src/play.rs | 20 ++++++++++++++++++++ src/setup.rs | 24 ++++++++++++++++++++++-- todo.txt | 6 ++++++ 3 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 todo.txt diff --git a/src/play.rs b/src/play.rs index 0232fe0..b2820b9 100644 --- a/src/play.rs +++ b/src/play.rs @@ -32,3 +32,23 @@ pub(crate) fn toggle_selected( commands.entity(e).insert(Selected); } } + +pub(crate) fn check_set(trigger: Trigger>, query: Query<&Card, With>) { + let mut cards = query.iter(); + if cards.len() == 3 { + let (a, b, c) = ( + cards.next().unwrap(), + cards.next().unwrap(), + cards.next().unwrap(), + ); + _is_set((a, b, c)); + } else if cards.len() > 3 { + info!("Too many cards!") + } else if cards.len() < 3 { + info!("Not enough cards!") + } +} + +fn _is_set((_a, _b, _c): (&Card, &Card, &Card)) -> bool { + todo!() +} diff --git a/src/setup.rs b/src/setup.rs index 037d05e..43b01ed 100644 --- a/src/setup.rs +++ b/src/setup.rs @@ -1,5 +1,5 @@ use crate::{deck::*, *}; -use bevy::prelude::*; +use bevy::{color::palettes::css::TEAL, prelude::*}; pub struct SetupPlugin; @@ -7,7 +7,13 @@ impl Plugin for SetupPlugin { fn build(&self, app: &mut App) { app.add_systems( OnEnter(GameState::Setup), - (setup::setup_cards, setup::setup_camera, setup::start_play).chain(), + ( + setup_cards, + setup_camera, + setup_set_check_button, + start_play, + ) + .chain(), ); } } @@ -52,6 +58,20 @@ pub(crate) fn setup_camera(mut commands: Commands) { )); } +#[derive(Component)] +pub(crate) struct CheckSet; + +pub(crate) fn setup_set_check_button(mut commands: Commands) { + commands.spawn(Node::default()).with_children(|parent| { + parent + .spawn((Button, CheckSet, BackgroundColor(TEAL.into()))) + .with_children(|parent| { + parent.spawn(Text("Set!?".to_string())); + }) + .observe(play::check_set); + }); +} + /// Finish the setup state by progressing to the play state pub(crate) fn start_play(mut game_state: ResMut>) { game_state.set(GameState::Play); diff --git a/todo.txt b/todo.txt new file mode 100644 index 0000000..c0a9278 --- /dev/null +++ b/todo.txt @@ -0,0 +1,6 @@ +TODO: +* Shuffle deck +* Serve out 12 cards +* Check for sets +* Capture valid sets +* Deal out additional cards