From 48f1165e3bfe31a4df2b189cda87982eec378bd3 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Mon, 11 Apr 2022 10:18:12 +0100 Subject: [PATCH] Extend InertPieceTrait to support multiple faces We want this because we want to use InertPiece for dice and a die can have multiple faces, which we want to specify as a single piece. Ie, the die face images will be an inert version of the die. No functional change right now - we just move the default() call out from the trait impls to each of the call sites. In the shapelib impl (which is the only impl right now) we pass through the face to the rendering code (which lives in the main PieceTrait impl). Signed-off-by: Ian Jackson --- src/gamestate.rs | 7 ++++++- src/pcrender.rs | 2 +- src/shapelib.rs | 15 +++++++++++---- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/gamestate.rs b/src/gamestate.rs index fe167c47..6f229f20 100644 --- a/src/gamestate.rs +++ b/src/gamestate.rs @@ -237,7 +237,12 @@ pub trait PieceTrait: OutlineTrait + Send + Debug + 'static { #[typetag::serde] pub trait InertPieceTrait: OutlineTrait { - fn svg(&self, f: &mut Html, id: VisiblePieceId) -> Result<(),IE>; + fn nfaces(&self) -> RawFaceId; + + /// When used for occultated version of another object, + /// face used is always default, regardless of nfaces. + fn svg(&self, f: &mut Html, id: VisiblePieceId, face: FaceId) + -> Result<(),IE>; fn describe_html(&self) -> Result; } diff --git a/src/pcrender.rs b/src/pcrender.rs index 3a65dc45..5d9b83a7 100644 --- a/src/pcrender.rs +++ b/src/pcrender.rs @@ -207,7 +207,7 @@ impl PieceRenderInstructions { ipc.show(y).svg_piece(&mut defs, gpc, gs, pri.vpid)?; }, Right(i) => { - i.svg(&mut defs, pri.vpid)?; + i.svg(&mut defs, pri.vpid, default())?; }, }; diff --git a/src/shapelib.rs b/src/shapelib.rs index eca18a23..c50c53d5 100644 --- a/src/shapelib.rs +++ b/src/shapelib.rs @@ -225,8 +225,13 @@ impl OutlineTrait for ItemInertForOcculted { delegate! { to self.outline { }}} #[typetag::serde(name="Lib")] impl InertPieceTrait for ItemInertForOcculted { + fn nfaces(&self) -> RawFaceId { 1 } + #[throws(IE)] - fn svg(&self, f: &mut Html, _: VisiblePieceId) { + fn svg(&self, f: &mut Html, _: VisiblePieceId, face: FaceId) { + if face != FaceId::default() { + throw!(internal_logic_error("ItemInertForOcculted non-default face")) + } self.xform.write_svgd(f, &self.svgd)?; } #[throws(IE)] @@ -339,7 +344,7 @@ impl Item { let svgd = &self.svgs[face.svg]; face.xform.write_svgd(f, svgd)?; } else if let Some(back) = &self.back { - back.svg(f, vpid)?; + back.svg(f, vpid, default())?; } else { throw!(internal_error_bydebug(&(self, face))) } @@ -383,9 +388,11 @@ impl PieceTrait for Item { #[typetag::serde(name="LibItem")] impl InertPieceTrait for Item { + fn nfaces(&self) -> RawFaceId { ::nfaces(self) } + #[throws(IE)] - fn svg(&self, f: &mut Html, id: VisiblePieceId) { - self.svg_face(f, default(), id)?; + fn svg(&self, f: &mut Html, id: VisiblePieceId, face: FaceId) { + self.svg_face(f, face, id)?; } #[throws(IE)] fn describe_html(&self) -> Html { -- 2.30.2