From 5adf2fd52b8fdd3907ef94c60cf8cb14daec6ecd Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 16 Apr 2022 01:11:49 +0100 Subject: [PATCH] dice: Break out check_permit_flip_roll The "roll" ui operation is going to want this too. Signed-off-by: Ian Jackson --- src/dice.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/dice.rs b/src/dice.rs index b874fe7d..d03b5ea3 100644 --- a/src/dice.rs +++ b/src/dice.rs @@ -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)] -- 2.30.2