From c9bc2cd5e4a115a771fad40ee04bdd4fa0e2c41e Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 16 Apr 2022 01:10:53 +0100 Subject: [PATCH] dice: Break out cooldown_start_value The "roll" ui operation is going to want this too. Signed-off-by: Ian Jackson --- src/dice.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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 { -- 2.30.2