cargo fmt

main
Elijah C. Voigt 2 years ago
parent 18f3797340
commit 0e2308929c

@ -748,10 +748,7 @@ fn select(
meshes: Res<Assets<Mesh>>, meshes: Res<Assets<Mesh>>,
cameras: Query<(&Camera, &GlobalTransform)>, cameras: Query<(&Camera, &GlobalTransform)>,
windows: Query<&Window, With<PrimaryWindow>>, windows: Query<&Window, With<PrimaryWindow>>,
selectable: Query< selectable: Query<(Entity, &BoardIndex, &Side), (With<game::Selectable>, With<Display3d>)>,
(Entity, &BoardIndex, &Side),
(With<game::Selectable>, With<Display3d>),
>,
selected: Query<Entity, With<game::Selected>>, selected: Query<Entity, With<game::Selected>>,
children: Query<&Children>, children: Query<&Children>,
mut selections: EventWriter<game::Selection>, mut selections: EventWriter<game::Selection>,
@ -777,7 +774,8 @@ fn select(
.find_map(|(e, &board_index, &side)| { .find_map(|(e, &board_index, &side)| {
// Check the side of the selection if no piece is selected // Check the side of the selection if no piece is selected
// Otherwise this is fine, select away // Otherwise this is fine, select away
let side_check = !selected.is_empty() || *state.get() == side; let side_check =
!selected.is_empty() || *state.get() == side;
let hit_check = { let hit_check = {
// This entity was hit (tile hitboxes) // This entity was hit (tile hitboxes)

@ -208,7 +208,7 @@ pub(crate) struct BoardIndex {
#[derive(Debug, Component, PartialEq, Clone, Default, Copy, Eq, Hash)] #[derive(Debug, Component, PartialEq, Clone, Default, Copy, Eq, Hash)]
pub(crate) struct Previous { pub(crate) struct Previous {
board_index: BoardIndex board_index: BoardIndex,
} }
#[derive(Debug, Component, PartialEq, Clone, Copy)] #[derive(Debug, Component, PartialEq, Clone, Copy)]
@ -240,20 +240,26 @@ impl Board {
match side { match side {
Side::A => { Side::A => {
// X: 0..3, Y: 0..3 // X: 0..3, Y: 0..3
(0..=3).flat_map(|x| { (0..=3)
.flat_map(|x| {
(0..=3).map(move |y| { (0..=3).map(move |y| {
self.at(BoardIndex { x, y }).map(|p| (p, BoardIndex { x, y })) self.at(BoardIndex { x, y })
.map(|p| (p, BoardIndex { x, y }))
}) })
}).filter_map(|r| r) })
.filter_map(|r| r)
.collect() .collect()
} }
Side::B => { Side::B => {
// X: 4..7, Y: 0..3 // X: 4..7, Y: 0..3
(4..=7).flat_map(|x| { (4..=7)
.flat_map(|x| {
(0..=3).map(move |y| { (0..=3).map(move |y| {
self.at(BoardIndex { x, y }).map(|p| (p, BoardIndex { x, y })) self.at(BoardIndex { x, y })
.map(|p| (p, BoardIndex { x, y }))
})
}) })
}).filter_map(|r| r) .filter_map(|r| r)
.collect() .collect()
} }
} }
@ -582,20 +588,14 @@ fn track_previous_move(
#[derive(Debug, Component)] #[derive(Debug, Component)]
struct Endgame; struct Endgame;
fn check_endgame( fn check_endgame(board: Res<Board>, mut next_state: ResMut<NextState<GameState>>) {
board: Res<Board>,
mut next_state: ResMut<NextState<GameState>>,
) {
if board.on(Side::A).is_empty() || board.on(Side::B).is_empty() { if board.on(Side::A).is_empty() || board.on(Side::B).is_empty() {
warn!("The game is over!"); warn!("The game is over!");
next_state.set(GameState::Endgame); next_state.set(GameState::Endgame);
} }
} }
fn set_endgame( fn set_endgame(score: Res<Score>, mut commands: Commands) {
score: Res<Score>,
mut commands: Commands,
) {
commands commands
.spawn(( .spawn((
Endgame, Endgame,
@ -642,10 +642,7 @@ fn set_endgame(
}); });
} }
fn clear_endgame( fn clear_endgame(query: Query<Entity, With<Endgame>>, mut commands: Commands) {
query: Query<Entity, With<Endgame>>,
mut commands: Commands,
) {
query.iter().for_each(|e| { query.iter().for_each(|e| {
commands.entity(e).despawn_recursive(); commands.entity(e).despawn_recursive();
}) })
@ -695,7 +692,6 @@ fn handle_selection(
mut latest: Local<Option<BoardIndex>>, // Tracks the last one worked on mut latest: Local<Option<BoardIndex>>, // Tracks the last one worked on
) { ) {
selections.read().for_each(|Selection(index)| { selections.read().for_each(|Selection(index)| {
// Skip indexes already processed // Skip indexes already processed
if Some(*index) != *latest { if Some(*index) != *latest {
// Set the latest index to the current index // Set the latest index to the current index

Loading…
Cancel
Save