chiark / gitweb /
clock: Provide a loaded_hook, to restart after load
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 20 Mar 2021 22:27:51 +0000 (22:27 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 20 Mar 2021 22:27:51 +0000 (22:27 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/clock.rs

index c612b7afe317d2f11ed1d84b290f0749dbf385ec..787a3de611bde3470732bd47f0e450d56275591c 100644 (file)
@@ -715,5 +715,18 @@ impl PieceTrait for Clock {
     unprepared_update(piece)
   }
 
+  #[throws(IE)]
+  fn loaded_hook(&self, piece: PieceId, gs: &mut GameState,
+                 ig: &InstanceRef) {
+    // The effect of this is to reload to the amount remaining at the
+    // last game save.  That's probably tolerable, and even arguably
+    // better than having the clock "have kept running" during the
+    // lost state.
+    let gpc = gs.pieces.byid_mut(piece).context("load hook")?;
+    let held = gpc.held;
+    let state = gpc.xdata_mut(|| State::new(&self.spec))?;
+    state.do_start_or_stop(piece, None, None, held, &self.spec, ig)?;
+  }
+
   fn itemname(&self) -> &str { "chess-clock" }
 }