chiark / gitweb /
dice: Break out check_permit_flip_roll
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 16 Apr 2022 00:11:49 +0000 (01:11 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 16 Apr 2022 00:11:49 +0000 (01:11 +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 b874fe7dc0870cf7bcf2eff6be8d6242dcc8360b..d03b5ea3f212c20f676f8cedc80fce82ea0b6646 100644 (file)
@@ -257,6 +257,15 @@ impl Die {
     self.cooldown_remaining(state)? != Duration::default()
   }
 
+  #[throws(ApiPieceOpError)]
+  pub fn check_permit_flip_roll(&self, state: &State) {
+    if self.cooldown_running(state)? {
+      throw!(Inapplicable::DieCooldown)
+    } else {
+      ()
+    }        
+  }
+
   /// Possible stores None, saving us calling Instant::now in the future
   #[throws(IE)]
   pub fn cooldown_cleanup(&self, state: &mut State) {
@@ -325,11 +334,8 @@ impl PieceTrait for Die {
   #[throws(ApiPieceOpError)]
   fn ui_permit_flip(&self, gpc: &GPiece) -> bool {
     let state: &State = gpc.xdata.get_exp()?;
-    if self.cooldown_running(state)? {
-      throw!(Inapplicable::DieCooldown)
-    } else {
-      true
-    }        
+    let () = self.check_permit_flip_roll(state)?;
+    true
   }
 
   #[throws(IE)]