chiark / gitweb /
dice: Break out cooldown_start_value
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 16 Apr 2022 00:10:53 +0000 (01:10 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 16 Apr 2022 00:10:53 +0000 (01:10 +0100)
The "roll" ui operation is going to want this too.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/dice.rs

index 8fcc6132a620c61969f8e7af85a82823342b86d3..b874fe7dc0870cf7bcf2eff6be8d6242dcc8360b 100644 (file)
@@ -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<FutureInstant> {
+  let t = cooldown_time.try_into().map_err(IE::from)?;
+  Some(t)
+}
+
 impl Die {
   #[throws(IE)]
   pub fn cooldown_remaining(&self, state: &State) -> Duration {