From 3724b51ecabd818eb0f8a6cef6fbffd8042c3375 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 20 Mar 2021 22:15:44 +0000 Subject: [PATCH] PieceTrait, global: Provide loaded_hook() Signed-off-by: Ian Jackson --- src/gamestate.rs | 3 +++ src/global.rs | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/gamestate.rs b/src/gamestate.rs index 75c57c10..de5ecbbb 100644 --- a/src/gamestate.rs +++ b/src/gamestate.rs @@ -152,6 +152,9 @@ pub trait PieceTrait: OutlineTrait + Send + Debug + 'static { _was_held: Option) -> UnpreparedUpdates { None } + #[throws(IE)] + fn loaded_hook(&self, _piece: PieceId, _gs: &mut GameState) { } + /// Not called if the whole game is destroyed. /// You can use Drop of course but it's not usually much use since /// you don't have a reference to the game or anything. diff --git a/src/global.rs b/src/global.rs index 15c965fe..3cc573e2 100644 --- a/src/global.rs +++ b/src/global.rs @@ -1118,7 +1118,10 @@ impl InstanceGuard<'_> { let gref = InstanceRef(Arc::new(Mutex::new(cont))); let mut g = gref.lock().unwrap(); - // xxx add hook to let chess clock restart after reload + let ig = &mut *g; + for (piece, ipc) in ig.ipieces.0.iter() { + ipc.direct_trait_access().loaded_hook(piece, &mut ig.gs)?; + } for (token, _) in &tokens_players { g.tokens_players.tr.insert(RawToken(token.clone())); -- 2.30.2