|
|
|
@ -197,8 +197,8 @@ impl CaptureFlow {
|
|
|
|
/// Fade out, then store, then fade in
|
|
|
|
/// Fade out, then store, then fade in
|
|
|
|
pub(crate) fn next(&self) -> Option<Self> {
|
|
|
|
pub(crate) fn next(&self) -> Option<Self> {
|
|
|
|
match self {
|
|
|
|
match self {
|
|
|
|
Self::FadeOut(e) => Some(Self::Store(e.clone())),
|
|
|
|
Self::FadeOut(e) => Some(Self::Store(*e)),
|
|
|
|
Self::Store(e) => Some(Self::FadeIn(e.clone())),
|
|
|
|
Self::Store(e) => Some(Self::FadeIn(*e)),
|
|
|
|
Self::FadeIn(_) => None,
|
|
|
|
Self::FadeIn(_) => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -297,7 +297,7 @@ impl Board {
|
|
|
|
.map(|p| (p, BoardIndex { x, y }))
|
|
|
|
.map(|p| (p, BoardIndex { x, y }))
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.filter_map(|r| r)
|
|
|
|
.flatten()
|
|
|
|
.collect()
|
|
|
|
.collect()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Side::B => {
|
|
|
|
Side::B => {
|
|
|
|
@ -309,7 +309,7 @@ impl Board {
|
|
|
|
.map(|p| (p, BoardIndex { x, y }))
|
|
|
|
.map(|p| (p, BoardIndex { x, y }))
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.filter_map(|r| r)
|
|
|
|
.flatten()
|
|
|
|
.collect()
|
|
|
|
.collect()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -322,7 +322,7 @@ impl Board {
|
|
|
|
.enumerate()
|
|
|
|
.enumerate()
|
|
|
|
.flat_map(|(y, nested)| {
|
|
|
|
.flat_map(|(y, nested)| {
|
|
|
|
nested.iter().enumerate().filter_map(move |(x, p)| {
|
|
|
|
nested.iter().enumerate().filter_map(move |(x, p)| {
|
|
|
|
p.as_ref().map(|val| (BoardIndex { x, y }, val.clone()))
|
|
|
|
p.as_ref().map(|val| (BoardIndex { x, y }, *val))
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.collect()
|
|
|
|
.collect()
|
|
|
|
@ -337,7 +337,7 @@ impl Board {
|
|
|
|
if from == to {
|
|
|
|
if from == to {
|
|
|
|
Err(GameError::NullMove)
|
|
|
|
Err(GameError::NullMove)
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
match self.at(from.clone()) {
|
|
|
|
match self.at(from) {
|
|
|
|
Some(from_piece) => {
|
|
|
|
Some(from_piece) => {
|
|
|
|
// Check if this is a valid move for this piece
|
|
|
|
// Check if this is a valid move for this piece
|
|
|
|
if self.valid_moves(from).contains(&to) {
|
|
|
|
if self.valid_moves(from).contains(&to) {
|
|
|
|
@ -351,7 +351,7 @@ impl Board {
|
|
|
|
if self.inner[to.y][to.x].is_some() {
|
|
|
|
if self.inner[to.y][to.x].is_some() {
|
|
|
|
moves.push(Move {
|
|
|
|
moves.push(Move {
|
|
|
|
epoch,
|
|
|
|
epoch,
|
|
|
|
from: to.clone(),
|
|
|
|
from: to,
|
|
|
|
to: None,
|
|
|
|
to: None,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -359,8 +359,8 @@ impl Board {
|
|
|
|
// Capture the intened move in the moves ledger
|
|
|
|
// Capture the intened move in the moves ledger
|
|
|
|
moves.push(Move {
|
|
|
|
moves.push(Move {
|
|
|
|
epoch,
|
|
|
|
epoch,
|
|
|
|
from: from.clone(),
|
|
|
|
from: from,
|
|
|
|
to: Some(to.clone()),
|
|
|
|
to: Some(to),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
self.inner[to.y][to.x] = Some(*from_piece);
|
|
|
|
self.inner[to.y][to.x] = Some(*from_piece);
|
|
|
|
@ -500,7 +500,7 @@ impl Board {
|
|
|
|
impl std::fmt::Display for Board {
|
|
|
|
impl std::fmt::Display for Board {
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
|
|
self.inner.iter().rev().for_each(|row| {
|
|
|
|
self.inner.iter().rev().for_each(|row| {
|
|
|
|
let _ = write!(f, "+--+--+--+--+--+--+--+--+\n");
|
|
|
|
let _ = writeln!(f, "+--+--+--+--+--+--+--+--+");
|
|
|
|
let _ = write!(f, "|");
|
|
|
|
let _ = write!(f, "|");
|
|
|
|
row.iter().for_each(|piece| {
|
|
|
|
row.iter().for_each(|piece| {
|
|
|
|
let _ = match piece {
|
|
|
|
let _ = match piece {
|
|
|
|
@ -508,7 +508,7 @@ impl std::fmt::Display for Board {
|
|
|
|
None => write!(f, " |"),
|
|
|
|
None => write!(f, " |"),
|
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|
|
|
|
});
|
|
|
|
let _ = write!(f, "\n");
|
|
|
|
let _ = writeln!(f);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
let _ = write!(f, "+--+--+--+--+--+--+--+--+");
|
|
|
|
let _ = write!(f, "+--+--+--+--+--+--+--+--+");
|
|
|
|
Ok(())
|
|
|
|
Ok(())
|
|
|
|
@ -552,7 +552,7 @@ pub(crate) fn update_board(
|
|
|
|
match to {
|
|
|
|
match to {
|
|
|
|
Some(to_idx) => {
|
|
|
|
Some(to_idx) => {
|
|
|
|
info!("Moving piece {:?} {:?} -> {:?}", entity, from, to_idx);
|
|
|
|
info!("Moving piece {:?} {:?} -> {:?}", entity, from, to_idx);
|
|
|
|
*index = to_idx.clone();
|
|
|
|
*index = *to_idx;
|
|
|
|
if !(*played) {
|
|
|
|
if !(*played) {
|
|
|
|
audio_events.send(audio::AudioEvent::PutDown);
|
|
|
|
audio_events.send(audio::AudioEvent::PutDown);
|
|
|
|
audio_events.send(audio::AudioEvent::StopIdle);
|
|
|
|
audio_events.send(audio::AudioEvent::StopIdle);
|
|
|
|
@ -853,8 +853,8 @@ fn cancel_place(current: Query<&BoardIndex, With<Selected>>, mut events: EventWr
|
|
|
|
current.iter().for_each(|board_index| {
|
|
|
|
current.iter().for_each(|board_index| {
|
|
|
|
info!("De-selecting piece at {:?}", board_index);
|
|
|
|
info!("De-selecting piece at {:?}", board_index);
|
|
|
|
events.send(Move {
|
|
|
|
events.send(Move {
|
|
|
|
from: board_index.clone(),
|
|
|
|
from: *board_index,
|
|
|
|
to: Some(board_index.clone()),
|
|
|
|
to: Some(*board_index),
|
|
|
|
..default()
|
|
|
|
..default()
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
@ -938,7 +938,7 @@ fn reset_game(
|
|
|
|
.for_each(|(e, (i, p))| {
|
|
|
|
.for_each(|(e, (i, p))| {
|
|
|
|
commands
|
|
|
|
commands
|
|
|
|
.entity(e)
|
|
|
|
.entity(e)
|
|
|
|
.insert((i.clone(), p.clone()))
|
|
|
|
.insert((*i, *p))
|
|
|
|
.remove::<Captured>();
|
|
|
|
.remove::<Captured>();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|