|
|
|
|
@ -21,7 +21,6 @@ impl Plugin for GamePlugin {
|
|
|
|
|
.run_if(on_event::<Move>())
|
|
|
|
|
.after(handle_selection),
|
|
|
|
|
set_side.run_if(any_component_changed::<BoardIndex>()),
|
|
|
|
|
cancel_place.run_if(just_pressed(MouseButton::Right)),
|
|
|
|
|
handle_selection.run_if(on_event::<Selection>()),
|
|
|
|
|
show_valid_moves.run_if(any_component_added::<Selected>()),
|
|
|
|
|
hide_valid_moves.run_if(any_component_removed::<Selected>()),
|
|
|
|
|
@ -372,14 +371,10 @@ impl Board {
|
|
|
|
|
|
|
|
|
|
fn new() -> Board {
|
|
|
|
|
Board::from_ascii(
|
|
|
|
|
// r#".....dqq
|
|
|
|
|
// dpp..pdq
|
|
|
|
|
// qdp..ppd
|
|
|
|
|
// qqd....."#,
|
|
|
|
|
r#"........
|
|
|
|
|
...p....
|
|
|
|
|
..p...p.
|
|
|
|
|
........"#,
|
|
|
|
|
r#".....dqq
|
|
|
|
|
dpp..pdq
|
|
|
|
|
qdp..ppd
|
|
|
|
|
qqd....."#,
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -1040,9 +1035,6 @@ pub(crate) fn update_board(
|
|
|
|
|
if *from != *to_idx {
|
|
|
|
|
match move_type {
|
|
|
|
|
MoveType::Promotion(piece) => {
|
|
|
|
|
error!("Hey Eli, this is where you are merging pieces");
|
|
|
|
|
// Here we insert a new Piece type based on the merge
|
|
|
|
|
// Other system should automatically update the model
|
|
|
|
|
commands
|
|
|
|
|
.entity(entity)
|
|
|
|
|
.insert(*piece);
|
|
|
|
|
@ -1055,7 +1047,7 @@ pub(crate) fn update_board(
|
|
|
|
|
next_state.set(ns);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// We are moving off the board (e.g,. capture or merge)
|
|
|
|
|
// We are moving off the board (e.g,. capture or promotion/merge)
|
|
|
|
|
None => {
|
|
|
|
|
match move_type {
|
|
|
|
|
MoveType::Capture => {
|
|
|
|
|
@ -1069,7 +1061,7 @@ pub(crate) fn update_board(
|
|
|
|
|
commands
|
|
|
|
|
.entity(entity)
|
|
|
|
|
.remove::<BoardIndex>()
|
|
|
|
|
.insert(Promoted);
|
|
|
|
|
.insert((Promoted, Visibility::Hidden));
|
|
|
|
|
},
|
|
|
|
|
_ => {
|
|
|
|
|
panic!("How did you do this!?");
|
|
|
|
|
@ -1353,18 +1345,6 @@ fn handle_selection(
|
|
|
|
|
*latest = None;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Triggered when right-mouse-button clicked
|
|
|
|
|
fn cancel_place(current: Query<&BoardIndex, With<Selected>>, mut events: EventWriter<Move>) {
|
|
|
|
|
current.iter().for_each(|board_index| {
|
|
|
|
|
info!("De-selecting piece at {:?}", board_index);
|
|
|
|
|
events.send(Move {
|
|
|
|
|
from: *board_index,
|
|
|
|
|
to: Some(*board_index),
|
|
|
|
|
..default()
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Panics if more than two pieces are selected at a time
|
|
|
|
|
fn asserts<T: Component>(
|
|
|
|
|
selected_pieces: Query<Entity, (With<Piece>, With<T>, With<Selected>)>,
|
|
|
|
|
@ -1431,6 +1411,7 @@ fn reset_game(
|
|
|
|
|
mut board: ResMut<Board>,
|
|
|
|
|
mut score: ResMut<Score>,
|
|
|
|
|
mut commands: Commands,
|
|
|
|
|
mut turn_state: ResMut<NextState<TurnState>>,
|
|
|
|
|
) {
|
|
|
|
|
// Setup the board
|
|
|
|
|
*board = Board::new();
|
|
|
|
|
@ -1438,12 +1419,17 @@ fn reset_game(
|
|
|
|
|
// Reset the score
|
|
|
|
|
*score = Score { ..default() };
|
|
|
|
|
|
|
|
|
|
// Reset to starting side
|
|
|
|
|
turn_state.set(TurnState(Side::B));
|
|
|
|
|
|
|
|
|
|
// Move all pieces to their correct spots
|
|
|
|
|
pieces
|
|
|
|
|
.iter()
|
|
|
|
|
.zip(board.pieces().iter())
|
|
|
|
|
.for_each(|(e, (i, p))| {
|
|
|
|
|
commands.entity(e).insert((*i, *p)).remove::<Captured>();
|
|
|
|
|
commands.entity(e)
|
|
|
|
|
.insert((*i, *p, Visibility::Inherited))
|
|
|
|
|
.remove::<(Captured, Promoted)>();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|