From: Ian Jackson Date: Mon, 15 Mar 2021 16:14:02 +0000 (+0000) Subject: hidden: Introduce ShowUnocculted as an svg_piece parameter X-Git-Tag: otter-0.4.0~31 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=7afc3d43e57d4386f0474c6390e2c55473a489b3;p=otter.git hidden: Introduce ShowUnocculted as an svg_piece parameter The need to provide a vpid served (and still servers) the same function, but this plumbing work will make prepare the way for doing the same to other methods. Signed-off-by: Ian Jackson --- diff --git a/src/bin/otterlib.rs b/src/bin/otterlib.rs index e3a5ffd6..55de6bca 100644 --- a/src/bin/otterlib.rs +++ b/src/bin/otterlib.rs @@ -172,7 +172,8 @@ fn preview(items: Vec) { } let mut html = Html("".into()); let gpc = GPiece { face: face.into(), ..GPiece::dummy() }; - p.svg_piece(&mut html, &gpc, default())?; + p.svg_piece(&mut html, &gpc, default(), + ShowUnocculted::new_visible())?; println!("{}", html.0); } println!(""); diff --git a/src/gamestate.rs b/src/gamestate.rs index 6b8635da..1e233fe0 100644 --- a/src/gamestate.rs +++ b/src/gamestate.rs @@ -144,7 +144,7 @@ pub trait PieceTrait: OutlineTrait + Send + Debug + 'static { // #[throws] doesn't work here - fehler #todo fn svg_piece(&self, f: &mut Html, gpc: &GPiece, - id: VisiblePieceId) -> Result<(),IE>; + id: VisiblePieceId, y: ShowUnocculted) -> Result<(),IE>; fn describe_html(&self, gpc: &GPiece) -> Result; diff --git a/src/hand.rs b/src/hand.rs index e8f0917d..7776e2ff 100644 --- a/src/hand.rs +++ b/src/hand.rs @@ -87,7 +87,8 @@ impl Hand { impl PieceTrait for Hand { fn nfaces(&self) -> RawFaceId { 1 } #[throws(IE)] - fn svg_piece(&self, f: &mut Html, gpc: &GPiece, _vpid: VisiblePieceId) { + fn svg_piece(&self, f: &mut Html, gpc: &GPiece, + _vpid: VisiblePieceId, _: ShowUnocculted) { self.shape.svg_piece_raw(f, gpc.face, &mut |f: &mut String| { if_chain!{ if let Some(xdata) = gpc.xdata.get::()?; diff --git a/src/hidden.rs b/src/hidden.rs index ad82efe6..7973891e 100644 --- a/src/hidden.rs +++ b/src/hidden.rs @@ -15,6 +15,9 @@ visible_slotmap_key!{ OccId(b'H') } // ========== data structures ========== +#[derive(Copy,Clone,Debug)] +pub struct ShowUnocculted(()); + #[derive(Clone,Debug,Default,Serialize,Deserialize)] pub struct GameOccults { occults: DenseSlotMap, @@ -192,7 +195,7 @@ pub fn piece_pri( trace_dbg!("piece_pri", player, piece, occk, gpc); return None; } - OccKG::Visible => PriOcculted::Visible, + OccKG::Visible => PriOcculted::Visible(ShowUnocculted(())), OccKG::Scrambled => PriOcculted::Occulted, OccKG::Displaced((pos,z)) => PriOcculted::Displaced(pos, z), }; @@ -201,6 +204,23 @@ pub fn piece_pri( Some(PieceRenderInstructions { vpid, occulted }) } +impl ShowUnocculted { + /// override + pub fn new_visible() -> ShowUnocculted { + ShowUnocculted(()) + } +} + +impl PieceRenderInstructions { + /// override + pub fn new_visible(vpid: VisiblePieceId) -> PieceRenderInstructions { + PieceRenderInstructions { + vpid, + occulted: PriOcculted::Visible(ShowUnocculted(())), + } + } +} + pub fn piece_at_all_occulted(gpc: &GPiece) -> bool { gpc.occult.passive.is_some() } diff --git a/src/pcrender.rs b/src/pcrender.rs index 08928c56..34c92375 100644 --- a/src/pcrender.rs +++ b/src/pcrender.rs @@ -18,7 +18,11 @@ pub struct PieceRenderInstructions { } #[derive(Debug,Clone)] -pub enum PriOcculted { Visible, Occulted, Displaced(Pos, ZLevel) } +pub enum PriOcculted { + Visible(ShowUnocculted), + Occulted, + Displaced(Pos, ZLevel), +} impl VisiblePieceAngle { pub fn to_transform(self) -> VisibleAngleTransform { @@ -49,7 +53,7 @@ impl PieceRenderInstructions { ! Delete() | Insert(_) | Modify(_) | ModifyQuiet(_), ) { match self.occulted { - Visible | Occulted => (), + Visible(_) | Occulted => (), Displaced(..) => return None, } } @@ -85,18 +89,14 @@ impl PieceRenderInstructions { } } - pub fn new_visible(vpid: VisiblePieceId) -> PieceRenderInstructions { - PieceRenderInstructions { vpid, occulted: PriOcculted::Visible } - } - #[throws(IE)] fn instead<'p>(&self, ioccults: &'p IOccults, p: &'p IPiece) - -> Option<&'p dyn OccultedPieceTrait> + -> Either { match self.occulted { - PriOcculted::Visible => None, + PriOcculted::Visible(v) => Left(v), PriOcculted::Occulted | PriOcculted::Displaced(..) => { - Some({ + Right({ let occilk = p.occilk.as_ref() .ok_or_else(|| internal_logic_error(format!( "occulted non-occultable {:?}", p)))? @@ -112,7 +112,7 @@ impl PieceRenderInstructions { pub fn angle(&self, gpc: &GPiece) -> VisiblePieceAngle { match self.occulted { - PriOcculted::Visible => gpc.angle, + PriOcculted::Visible(_) => gpc.angle, PriOcculted::Occulted | PriOcculted::Displaced(..) => default(), } } @@ -120,7 +120,7 @@ impl PieceRenderInstructions { pub fn pos_zlevel<'r>(&'r self, gpc: &'r GPiece) -> (Pos, &'r ZLevel) { use PriOcculted as PO; match &self.occulted { - PO::Visible | PO::Occulted => (gpc.pos, &gpc.zlevel), + PO::Visible(_) | PO::Occulted => (gpc.pos, &gpc.zlevel), PO::Displaced(pos, zlevel) => (*pos, &zlevel), } } @@ -133,8 +133,8 @@ impl PieceRenderInstructions { let instead = pri.instead(ioccults, ipc)?; let o: &dyn OutlineTrait = match instead { - None => Borrow::::borrow(&ipc.p).dyn_upcast(), - Some(i) => i.dyn_upcast(), + Left(_) => Borrow::::borrow(&ipc.p).dyn_upcast(), + Right(i) => i.dyn_upcast(), }; let angle = pri.angle(gpc); @@ -153,10 +153,10 @@ impl PieceRenderInstructions { pri.vpid, &transform.0, dragraise)?; match instead { - None => { - ipc.p.svg_piece(&mut defs, gpc, pri.vpid)?; + Left(y) => { + ipc.p.svg_piece(&mut defs, gpc, pri.vpid, y)?; }, - Some(i) => { + Right(i) => { i.svg(&mut defs, pri.vpid)?; }, }; @@ -182,8 +182,8 @@ impl PieceRenderInstructions { pub fn describe_fallible(&self, ioccults: &IOccults, gpc: &GPiece, ipc: &IPiece) -> Html { match self.instead(ioccults, ipc)? { - None => ipc.p.describe_html(gpc)?, - Some(i) => i.describe_html()?, + Left(_y) => ipc.p.describe_html(gpc)?, + Right(i) => i.describe_html()?, } } @@ -192,7 +192,7 @@ impl PieceRenderInstructions { -> Vec { match self.occulted { - PriOcculted::Visible => (), + PriOcculted::Visible(_) => (), PriOcculted::Occulted | PriOcculted::Displaced(..) => return vec![], }; diff --git a/src/pieces.rs b/src/pieces.rs index 370fccde..675258fa 100644 --- a/src/pieces.rs +++ b/src/pieces.rs @@ -129,7 +129,8 @@ impl OutlineTrait for GenericSimpleShape #[typetag::serde] impl PieceTrait for SimpleShape { #[throws(IE)] - fn svg_piece(&self, f: &mut Html, gpc: &GPiece, _vpid: VisiblePieceId) { + fn svg_piece(&self, f: &mut Html, gpc: &GPiece, + _vpid: VisiblePieceId, _: ShowUnocculted) { self.svg_piece_raw(f, gpc.face, &mut |_|Ok(()))?; } #[throws(IE)] diff --git a/src/shapelib.rs b/src/shapelib.rs index 43640421..df1977ee 100644 --- a/src/shapelib.rs +++ b/src/shapelib.rs @@ -214,7 +214,8 @@ impl PieceTrait for Item { fn nfaces(&self) -> RawFaceId { self.faces.len().try_into().unwrap() } #[throws(IE)] - fn svg_piece(&self, f: &mut Html, gpc: &GPiece, _vpid: VisiblePieceId) { + fn svg_piece(&self, f: &mut Html, gpc: &GPiece, + _vpid: VisiblePieceId, _: ShowUnocculted) { let face = &self.faces[gpc.face]; let svgd = &self.svgs[face.svg]; face.xform.write_svgd(f, svgd)?;