From 6c78a1efa31806af5b59621480c5b42c7e88a387 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Far=C3=ADas=20Santana?= Date: Mon, 3 May 2021 00:03:56 +0200 Subject: [PATCH] fix: Adjust clocks on correct turns 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. --- src/drawer.rs | 4 ++++ src/giffer.rs | 13 ++++--------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/drawer.rs b/src/drawer.rs index 8cacb30..0bc2c88 100644 --- a/src/drawer.rs +++ b/src/drawer.rs @@ -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) } diff --git a/src/giffer.rs b/src/giffer.rs index 0daf885..790000f 100644 --- a/src/giffer.rs +++ b/src/giffer.rs @@ -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()