From: Ian Jackson Date: Tue, 16 Mar 2021 13:28:57 +0000 (+0000) Subject: hidden: Provide IPiece::show_or_instead X-Git-Tag: otter-0.4.0~10 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=bee3121fe2a3391bd5b91846ddbe2f1de2d32d0b;p=otter.git hidden: Provide IPiece::show_or_instead For doing things when we don't have a PieceRenderInstructions - eg when logging, which must be player-agnostic. Signed-off-by: Ian Jackson --- diff --git a/src/hidden.rs b/src/hidden.rs index 8b652caf..26534885 100644 --- a/src/hidden.rs +++ b/src/hidden.rs @@ -246,6 +246,27 @@ impl IPieceTraitObj { pub fn into_inner(self) -> Box { self.0 } } +impl IPiece { + #[throws(IE)] + pub fn show_or_instead<'p>(&self, ioccults: &'p IOccults, + y: Option) + -> Either { + match y { + Some(y) => Left(y), + None => Right({ + let occilk = self.occilk.as_ref() + .ok_or_else(|| internal_logic_error(format!( + "occulted non-occultable {:?}", self)))? + .borrow(); + let occ_data = ioccults.ilks.get(occilk) + .ok_or_else(|| internal_logic_error(format!( + "occulted ilk vanished {:?} {:?}", self, occilk)))?; + occ_data.p_occ.as_ref() + }), + } + } +} + impl GPiece { pub fn fully_visible_to_everyone(&self) -> Option { match self.occult.passive { diff --git a/src/pcrender.rs b/src/pcrender.rs index 27782caf..03206712 100644 --- a/src/pcrender.rs +++ b/src/pcrender.rs @@ -43,24 +43,17 @@ impl VisiblePieceAngle { impl PriOccultedGeneral { #[throws(IE)] - fn instead<'p>(&self, ioccults: &'p IOccults, p: &'p IPiece) + pub fn instead<'p>(&self, ioccults: &'p IOccults, p: &'p IPiece) -> Either { + p.show_or_instead(ioccults, self.fully_visible())? + } + + pub fn fully_visible(&self) -> Option { use PriOG::*; match self { - Visible(v) => Left(*v), - Occulted | Displaced(..) => { - Right({ - let occilk = p.occilk.as_ref() - .ok_or_else(|| internal_logic_error(format!( - "occulted non-occultable {:?}", p)))? - .borrow(); - let occ_data = ioccults.ilks.get(occilk) - .ok_or_else(|| internal_logic_error(format!( - "occulted ilk vanished {:?} {:?}", p, occilk)))?; - occ_data.p_occ.as_ref() - }) - }, + Visible(v) => Some(*v), + Occulted | Displaced(..) => None, } }