From a9116a2f30d693d6b1c879f4fab0532368fc5cce Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Fri, 15 Apr 2022 13:14:24 +0100 Subject: [PATCH] dice: Start a cooldown the first time a die is added to the game This is useful for testing. It also means you can't just add a die showing what you want using the game management interface... Signed-off-by: Ian Jackson --- src/dice.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/dice.rs b/src/dice.rs index 80bd5611..72a15870 100644 --- a/src/dice.rs +++ b/src/dice.rs @@ -148,11 +148,14 @@ impl PieceSpec for Spec { if t <= MAX_COOLDOWN { t } else { throw!(SpecError::TimeoutTooLarge { got: t, max: MAX_COOLDOWN }) } }; - let itemname = self.itemname.clone().unwrap_or_else( || format!("die.{}.{}", nfaces, image.itemname())); - let _state: &mut State = gpc.xdata_mut(|| State::dummy())?; + let initial_state = { + let t = cooldown_time.try_into().map_err(IE::from)?; + State { cooldown_expires: Some(t) } + }; + let _state: &mut State = gpc.xdata_mut(|| initial_state)?; let occultable = match (img_occultable, &self.occult_label) { (None, l) => if l == "" { -- 2.30.2