From: Ian Jackson Date: Sat, 16 Apr 2022 00:10:53 +0000 (+0100) Subject: dice: Break out cooldown_start_value X-Git-Tag: otter-1.1.0~541 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=c9bc2cd5e4a115a771fad40ee04bdd4fa0e2c41e;p=otter.git dice: Break out cooldown_start_value The "roll" ui operation is going to want this too. Signed-off-by: Ian Jackson --- diff --git a/src/dice.rs b/src/dice.rs index 8fcc6132..b874fe7d 100644 --- a/src/dice.rs +++ b/src/dice.rs @@ -162,8 +162,7 @@ impl PieceSpec for Spec { || format!("die.{}.{}", nfaces, image.itemname())); let initial_state = { - let t = cooldown_time.try_into().map_err(IE::from)?; - State { cooldown_expires: Some(t) } + State { cooldown_expires: cooldown_start_value(cooldown_time)? } }; let _state: &mut State = gpc.xdata_mut(|| initial_state)?; @@ -222,6 +221,12 @@ impl PieceSpec for Spec { } } +#[throws(IE)] +pub fn cooldown_start_value(cooldown_time: Duration) -> Option { + let t = cooldown_time.try_into().map_err(IE::from)?; + Some(t) +} + impl Die { #[throws(IE)] pub fn cooldown_remaining(&self, state: &State) -> Duration {