Skip to content

Commit

Permalink
Fixes #27
Browse files Browse the repository at this point in the history
The game would crash if you moved after the puzzle ended (which is
possible with the auto load of the next puzzle turned off).

Thanks @cyrillkuettel and Instit on lichess for reporting it.
  • Loading branch information
brianch committed Sep 16, 2024
1 parent 00bc421 commit cb9e896
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
20 changes: 12 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ impl OfflinePuzzles {
};
// If the user clicked on another piece of his own side,
// just replace the previous selection and exit
if self.puzzle_tab.is_playing() && color == Some(side) {
if self.puzzle_tab.game_status == GameStatus::Playing && color == Some(side) {
self.from_square = Some(to);
return;
}
Expand Down Expand Up @@ -503,7 +503,7 @@ impl Application for OfflinePuzzles {
config::GameMode::Puzzle => { self.board.color_on(pos) }
};

if (self.puzzle_tab.is_playing() || self.game_mode == config::GameMode::Analysis) && color == Some(side) {
if (self.puzzle_tab.game_status == GameStatus::Playing || self.game_mode == config::GameMode::Analysis) && color == Some(side) {
self.hint_square = None;
self.from_square = Some(pos);
}
Expand Down Expand Up @@ -777,12 +777,16 @@ impl Application for OfflinePuzzles {
iced::window::resize(window::Id::MAIN, new_size)
}
} (_, Message::DropPiece(square, cursor_pos, _bounds)) => {
iced_drop::zones_on_point(
move |zones| Message::HandleDropZones(square, zones),
cursor_pos,
None,
None,
)
if self.puzzle_tab.game_status == GameStatus::Playing {
iced_drop::zones_on_point(
move |zones| Message::HandleDropZones(square, zones),
cursor_pos,
None,
None,
)
} else {
Command::none()
}
} (_, Message::HandleDropZones(from, zones)) => {
if !zones.is_empty() {
let id: &GenericId = &zones[0].0.clone();
Expand Down
4 changes: 0 additions & 4 deletions src/puzzles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,6 @@ impl PuzzleTab {
}
promotion
}

pub fn is_playing(&self) -> bool {
self.game_status != GameStatus::NoPuzzles
}
}

impl Tab for PuzzleTab {
Expand Down

0 comments on commit cb9e896

Please sign in to comment.