From: Ian Jackson Date: Fri, 15 Apr 2022 12:14:24 +0000 (+0100) Subject: dice: Start a cooldown the first time a die is added to the game X-Git-Tag: otter-1.1.0~568 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=a9116a2f30d693d6b1c879f4fab0532368fc5cce;p=otter.git 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 --- 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 == "" {