From: Ian Jackson Date: Wed, 10 Mar 2021 23:05:41 +0000 (+0000) Subject: hidden: Implement piece_pri properly (except for displacement) X-Git-Tag: otter-0.4.0~198 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=5dde9b188f7fba29b54f34867165d1cce2a3403e;p=otter.git hidden: Implement piece_pri properly (except for displacement) Signed-off-by: Ian Jackson --- diff --git a/src/hidden.rs b/src/hidden.rs index e24bb9e7..52e119fd 100644 --- a/src/hidden.rs +++ b/src/hidden.rs @@ -88,6 +88,20 @@ impl OccultationKind { } } +impl OccultationKindGeneral { + fn map_displaced(&self, f: F) -> OccultationKindGeneral + where F: FnOnce(&T) -> U, + { + use OccKG::*; + match self { + Visible => Visible, + Scrambled => Scrambled, + Invisible => Invisible, + Displaced(t) => Displaced(f(t)), + } + } +} + impl OccultationViews { pub fn get_kind(&self, player: PlayerId) -> &OccultationKind { let kind = self.views.iter().find_map(|view| { @@ -453,17 +467,38 @@ pub fn piece_pri>( ) -> Option { fn inner( - _occults: &GameOccults, // xxx + occults: &GameOccults, player: PlayerId, gpl: &mut GPlayer, piece: PieceId, gpc: &GPiece, _p: &dyn PieceTrait, ) -> Option { - trace_dbg!("piece_pri", &gpc); + let occk = if_chain! { + if let Some((occid, notch)) = gpc.occult.passive; + if let Some(occultation) = occults.occults.get(occid); + then { + occultation.views.get_kind(player) + .map_displaced(|area| { + let x: Coord = NotchNumber::from(notch).try_into().unwrap(); // xxx + let pos = area.0[0] + PosC([x*2, 0]); // xxx + pos.unwrap() + }) + } + else { + OccKG::Visible + } + }; + + let occulted = match occk { + OccKG::Invisible => { + trace_dbg!("piece_pri", gpc, occk); + return None; + } + OccKG::Visible => PriOcculted::Visible, + OccKG::Scrambled => PriOcculted::Occulted, + OccKG::Displaced(pos) => PriOcculted::Displaced(pos), + }; let vpid = gpl.idmap.fwd_or_insert(piece); - let angle = gpc.angle; - let occulted = PriOcculted::Visible; // xxx - trace!("{} {:?} => {} angle={:?}", - player, piece, vpid, angle); + trace_dbg!("piece_pri", gpc, occk, vpid, occulted); Some(PieceRenderInstructions { vpid, occulted }) } inner(occults, player, gpl, piece, gpc, p.borrow())