|
|
|
@ -3,7 +3,7 @@ use bevy::{prelude::*, utils::RandomState};
|
|
|
|
use crate::{
|
|
|
|
use crate::{
|
|
|
|
animation::{AnimationStore, DelayedAnimation},
|
|
|
|
animation::{AnimationStore, DelayedAnimation},
|
|
|
|
deck::{Card, Deck},
|
|
|
|
deck::{Card, Deck},
|
|
|
|
menu::UiMessage,
|
|
|
|
menu::{SetCounter, UiMessage},
|
|
|
|
setup::TopCard,
|
|
|
|
setup::TopCard,
|
|
|
|
view::ViewState,
|
|
|
|
view::ViewState,
|
|
|
|
GameState,
|
|
|
|
GameState,
|
|
|
|
@ -15,7 +15,7 @@ impl Plugin for PlayPlugin {
|
|
|
|
fn build(&self, app: &mut App) {
|
|
|
|
fn build(&self, app: &mut App) {
|
|
|
|
app.add_event::<ServeCards>()
|
|
|
|
app.add_event::<ServeCards>()
|
|
|
|
.add_systems(Update, serve_cards)
|
|
|
|
.add_systems(Update, serve_cards)
|
|
|
|
.add_systems(OnEnter(GameState::NewGame), reset_game)
|
|
|
|
.add_systems(OnEnter(GameState::NewGame), (reset_game, reset_set_counter))
|
|
|
|
.add_systems(OnEnter(ViewState::Play), deal_cards)
|
|
|
|
.add_systems(OnEnter(ViewState::Play), deal_cards)
|
|
|
|
.add_systems(Update, deal_cards.run_if(set_added));
|
|
|
|
.add_systems(Update, deal_cards.run_if(set_added));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -26,7 +26,7 @@ impl Plugin for PlayPlugin {
|
|
|
|
pub(crate) struct Selected;
|
|
|
|
pub(crate) struct Selected;
|
|
|
|
|
|
|
|
|
|
|
|
/// Where in the deck a card is
|
|
|
|
/// Where in the deck a card is
|
|
|
|
#[derive(Component, Clone, PartialEq)]
|
|
|
|
#[derive(Component, Clone, PartialEq, Debug)]
|
|
|
|
pub(crate) struct DeckOrder(pub u8);
|
|
|
|
pub(crate) struct DeckOrder(pub u8);
|
|
|
|
|
|
|
|
|
|
|
|
/// Where on the board/table/play-space a card is
|
|
|
|
/// Where on the board/table/play-space a card is
|
|
|
|
@ -213,14 +213,9 @@ fn serve_cards(
|
|
|
|
let candidate = in_deck
|
|
|
|
let candidate = in_deck
|
|
|
|
.iter()
|
|
|
|
.iter()
|
|
|
|
.find(|(_entity, _deck_card, order)| order.0 == n as u8);
|
|
|
|
.find(|(_entity, _deck_card, order)| order.0 == n as u8);
|
|
|
|
n = n.saturating_sub(1);
|
|
|
|
|
|
|
|
if n == 0 {
|
|
|
|
|
|
|
|
**top_card = Visibility::Hidden;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// If that search was fruitful, pull the card from the deck and play it
|
|
|
|
// If that search was fruitful, pull the card from the deck and play it
|
|
|
|
if let Some((e, _, _)) = candidate {
|
|
|
|
if let Some((e, card, order)) = candidate {
|
|
|
|
info!("Inserting location ({},{}) for {}", this_x, this_y, e);
|
|
|
|
info!("serving #{} {} to {:?}", order.0, card, (this_x, this_y));
|
|
|
|
commands
|
|
|
|
commands
|
|
|
|
.entity(e)
|
|
|
|
.entity(e)
|
|
|
|
.remove::<DeckOrder>()
|
|
|
|
.remove::<DeckOrder>()
|
|
|
|
@ -229,6 +224,11 @@ fn serve_cards(
|
|
|
|
y: this_y,
|
|
|
|
y: this_y,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
n = n.saturating_sub(1);
|
|
|
|
|
|
|
|
if n == 0 {
|
|
|
|
|
|
|
|
**top_card = Visibility::Hidden;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -251,10 +251,11 @@ pub(crate) fn shuffle_card(
|
|
|
|
mut query: Query<(&mut Transform, &mut Visibility, &mut AnimationPlayer)>,
|
|
|
|
mut query: Query<(&mut Transform, &mut Visibility, &mut AnimationPlayer)>,
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
{
|
|
|
|
{
|
|
|
|
let (mut t, mut _v, mut ap) = query.get_mut(trigger.entity()).unwrap();
|
|
|
|
let (mut t, mut v, mut ap) = query.get_mut(trigger.entity()).unwrap();
|
|
|
|
|
|
|
|
*v = Visibility::Hidden;
|
|
|
|
|
|
|
|
ap.rewind_all().stop_all();
|
|
|
|
t.translation = Vec3::new(-400.0, -200.0, 0.0);
|
|
|
|
t.translation = Vec3::new(-400.0, -200.0, 0.0);
|
|
|
|
// *v = Visibility::Hidden;
|
|
|
|
t.rotation = Quat::IDENTITY;
|
|
|
|
ap.rewind_all();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
commands
|
|
|
|
commands
|
|
|
|
.entity(trigger.entity())
|
|
|
|
.entity(trigger.entity())
|
|
|
|
@ -282,8 +283,6 @@ pub(crate) fn place_card(
|
|
|
|
.get(&format!("deck->{:?}", (play_location.x, play_location.y)))
|
|
|
|
.get(&format!("deck->{:?}", (play_location.x, play_location.y)))
|
|
|
|
.unwrap();
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
info!("Placing card {:?} at {:?}", entity, play_location);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let delay = ((random_state.hash_one(entity) % 9) as f32 / 10.0) + 0.1;
|
|
|
|
let delay = ((random_state.hash_one(entity) % 9) as f32 / 10.0) + 0.1;
|
|
|
|
commands.entity(entity).insert(DelayedAnimation {
|
|
|
|
commands.entity(entity).insert(DelayedAnimation {
|
|
|
|
animation_index: animation_index.clone(),
|
|
|
|
animation_index: animation_index.clone(),
|
|
|
|
@ -372,9 +371,13 @@ fn reset_game(
|
|
|
|
cards: Query<Entity, With<Card>>,
|
|
|
|
cards: Query<Entity, With<Card>>,
|
|
|
|
mut commands: Commands,
|
|
|
|
mut commands: Commands,
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
std::iter::zip(Deck::iter_shuffled().enumerate(), cards.iter()).for_each(|((i, _), entity)| {
|
|
|
|
std::iter::zip(Deck::iter_enumerated_shuffled(), cards.iter()).for_each(|((i, _), entity)| {
|
|
|
|
commands.entity(entity).insert(DeckOrder(i as u8));
|
|
|
|
commands.entity(entity).insert(DeckOrder(i as u8));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
view_state.set(ViewState::Play);
|
|
|
|
view_state.set(ViewState::Play);
|
|
|
|
game_state.set(GameState::Main);
|
|
|
|
game_state.set(GameState::Main);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn reset_set_counter(mut query: Query<&mut Text, With<SetCounter>>) {
|
|
|
|
|
|
|
|
query.single_mut().0 = "##".into();
|
|
|
|
|
|
|
|
}
|
|
|
|
|