Skip to content

Commit

Permalink
fix: Adjust clocks on correct turns
Browse files Browse the repository at this point in the history
On white's move, we should keep black's previous turn clock, as they have not played yet.
This was not happening before, which was causing black's clock to go back and forward.
Now the main frame encoding loop checks if it needs to fetch black's previous turn clock.
  • Loading branch information
tomasfarias committed May 2, 2021
1 parent 4875891 commit 6c78a1e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
4 changes: 4 additions & 0 deletions src/drawer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,10 @@ impl BoardDrawer {
self.size
}

pub fn flip(&self) -> bool {
self.flip
}

pub fn image_buffer(&self) -> RgbaImage {
ImageBuffer::new(self.size, self.size)
}
Expand Down
13 changes: 4 additions & 9 deletions src/giffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -603,18 +603,13 @@ impl Visitor for PGNGiffer {
log::debug!("Building frame for board number: {}", n);
log::debug!("Board width: {}, height: {}", b.width(), b.height());

let turn = n / 2;
let turn = if n == 0 { n } else { (n - 1) / 2 };

let mut white_clock = self.clocks.white.get(turn);
let white_clock = self.clocks.white.get(turn);
let mut black_clock = self.clocks.black.get(turn);

if n == (total_frames - 1) {
if white_clock.is_none() {
white_clock = self.clocks.white.get(turn - 1);
}
if black_clock.is_none() {
black_clock = self.clocks.black.get(turn - 1);
}
if turn > 0 && n % 2 != 0 {
black_clock = self.clocks.black.get(turn - 1);
}

if white_clock.is_some()
Expand Down

0 comments on commit 6c78a1e

Please sign in to comment.