From: Ian Jackson Date: Mon, 15 Mar 2021 18:43:58 +0000 (+0000) Subject: Refactor to make some things into GPiece methods X-Git-Tag: otter-0.4.0~24 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=33abb32e64ac9b529a6d53c902b51a8aa1e22786;p=otter.git Refactor to make some things into GPiece methods Signed-off-by: Ian Jackson --- diff --git a/daemon/api.rs b/daemon/api.rs index c6939bb3..2ec54f89 100644 --- a/daemon/api.rs +++ b/daemon/api.rs @@ -446,7 +446,7 @@ api_route!{ ioccults, &gs.occults, player, gpl, piece, gpc, ipc, if gpc.pinned { "pinned" } else { "unpinned" }, )?; - forbid_piece_involved_in_occultation(&gpc)?; + gpc.forbid_involved_in_occultation()?; gpc.pinned = self.0; let update = PieceUpdateOp::Modify(()); (WhatResponseToClientOp::Predictable, diff --git a/src/hidden.rs b/src/hidden.rs index c94f3337..792acef0 100644 --- a/src/hidden.rs +++ b/src/hidden.rs @@ -228,15 +228,16 @@ impl GPiece { None => Some(ShowUnocculted(())), } } -} -pub fn piece_involved_in_occultation(gpc: &GPiece) -> bool { - gpc.occult.passive.is_some() || - gpc.occult.active.is_some() -} -#[throws(OE)] -pub fn forbid_piece_involved_in_occultation(gpc: &GPiece) { - if piece_involved_in_occultation(&gpc) { throw!(OE::Occultation) } + pub fn involved_in_occultation(&self) -> bool { + self.occult.passive.is_some() || + self.occult.active.is_some() + } + + #[throws(OE)] + pub fn forbid_involved_in_occultation(&self) { + if self.involved_in_occultation() { throw!(OE::Occultation) } + } } pub fn vpiece_decode(