This involves a new hook for the piece trait.
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
let gpl = gs.players.byid_mut(player)?;
let _: Void = match (self.opname.as_str(), self.wrc) {
- ("flip", wrc@ WRC::UpdateSvg) => {
+ ("flip", wrc@ WRC::UpdateSvg)
+ if ipc.show(y).ui_permit_flip(gpc)?
+ =>
+ {
let nfaces = ipc.show(y).nfaces();
gpc.face = ((RawFaceId::from(gpc.face) + 1) % nfaces).into();
// todo: name the most visible aspect in the log ?
self.cooldown_time .as_secs_f64()
}
+ #[throws(IE)]
+ pub fn cooldown_running(&self, state: &State) -> bool {
+ self.cooldown_remaining(state)? != Duration::default()
+ }
+
/// Possible stores None, saving us calling Instant::now in the future
#[throws(IE)]
pub fn cooldown_cleanup(&self, state: &mut State) {
- if self.cooldown_remaining(state)? == Duration::default() {
+ if ! self.cooldown_running(state)? {
state.cooldown_expires = None;
}
}
}
}
+ #[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
+ }
+ }
+
#[throws(IE)]
fn svg_piece(&self, f: &mut Html, gpc: &GPiece, _: &GameState,
vpid: VisiblePieceId) {
#[error("occulter already rotated")] OcculterAlreadyRotated,
#[error("overfull, cannot organise")] OrganisedPlacementOverfull,
#[error("overlapping occultation(s)")] OverlappingOccultation,
+ #[error("die was recently rolled, cannot flip or roll")] DieCooldown,
#[error("UI operation not recognised")] BadUiOperation,
#[error("UI operation not valid in the curret piece state")]
BadPieceStateForOperation,
throw!(Ia::BadUiOperation)
}
+ /// Can return `false` to mean "I will handle it in ui_operation"
+ #[throws(ApiPieceOpError)]
+ fn ui_permit_flip(&self, _gpc: &GPiece) -> bool {
+ true
+ }
+
// #[throws] doesn't work here - fehler #todo
fn svg_piece(&self, f: &mut Html, gpc: &GPiece, gs: &GameState,
id: VisiblePieceId) -> Result<(),IE>;