From: Ian Jackson Date: Sat, 16 Apr 2022 00:11:49 +0000 (+0100) Subject: dice: Break out check_permit_flip_roll X-Git-Tag: otter-1.1.0~540 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=5adf2fd52b8fdd3907ef94c60cf8cb14daec6ecd;p=otter.git dice: Break out check_permit_flip_roll 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 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)]