You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.6 KiB
Rust

use crate::{deck::*, *};
use bevy::prelude::*;
pub struct SetupPlugin;
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 drawing our cards on the screen
pub(crate) fn setup_cards(mut commands: Commands, deck: Res<Deck>) {
let size = 75.0;
Deck::iter_cards().enumerate().for_each(|(i, this_card)| {
let this = deck
.cards
.get(&this_card)
.unwrap_or_else(|| panic!("fech card sprite {:?}", this_card))
.clone();
let new_this = Sprite {
custom_size: Some(Vec2::new(size, size)),
..this
};
// for a 9x9 grid we want x to wrap every 9 and y to increment every 9
// TODO: Determine based on screen size what this offset and scaling should be
let x = i % 9;
let y = i / 9;
let l = size;
let x_off = -(size / 2.0) * 9.0;
let y_off = -(size / 2.0) * 8.0;
let t = Transform::from_xyz(l * (x as f32) + x_off, l * (y as f32) + y_off, 0.0);
commands.spawn((new_this, this_card, t));
});
}
/// Setup our camera to view cardson the screen
pub(crate) fn setup_camera(mut commands: Commands) {
commands.spawn((
Camera2d,
Camera {
hdr: true,
..default()
},
));
}
/// Finish the setup state by progressing to the play state
pub(crate) fn start_play(mut game_state: ResMut<NextState<GameState>>) {
game_state.set(GameState::Play);
}