From 87446f7ac5155eed2d3c5cde8771a3de74a71a26 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 20 Mar 2021 22:27:51 +0000 Subject: [PATCH] clock: Provide a loaded_hook, to restart after load Signed-off-by: Ian Jackson --- src/clock.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/clock.rs b/src/clock.rs index c612b7af..787a3de6 100644 --- a/src/clock.rs +++ b/src/clock.rs @@ -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" } } -- 2.30.2