From 8b58118f16be3494a2fdf06c943d9e79babc422b Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Thu, 14 Apr 2022 20:55:17 +0100 Subject: [PATCH] Plumb xdata through to InertPieceTrait svg Occulted dice will need this to display the cooldown timer. This makes dice's InertPieceTrait impl not very inert, but it is OK because nothing can set off an inert die's cooldown timer. Signed-off-by: Ian Jackson --- src/gamestate.rs | 4 ++-- src/pcrender.rs | 2 +- src/pieces.rs | 3 ++- src/shapelib.rs | 15 +++++++++------ 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/gamestate.rs b/src/gamestate.rs index 74c5670b..9dc9d8ff 100644 --- a/src/gamestate.rs +++ b/src/gamestate.rs @@ -242,8 +242,8 @@ pub trait PieceTrait: PieceBaseTrait + Send + Debug + 'static { pub trait InertPieceTrait: PieceBaseTrait { /// 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 svg(&self, f: &mut Html, id: VisiblePieceId, face: FaceId, + xdata: &PieceXDataState /* use with care! */) -> Result<(),IE>; fn describe_html(&self) -> Result; } diff --git a/src/pcrender.rs b/src/pcrender.rs index 5d9b83a7..6dbcb80a 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, default())?; + i.svg(&mut defs, pri.vpid, default(), &gpc.xdata)?; }, }; diff --git a/src/pieces.rs b/src/pieces.rs index ac3e093e..14194eeb 100644 --- a/src/pieces.rs +++ b/src/pieces.rs @@ -154,7 +154,8 @@ impl PieceTrait for SimpleShape { #[typetag::serde] impl InertPieceTrait for SimpleShape { #[throws(IE)] - fn svg(&self, f: &mut Html, _vpid: VisiblePieceId, face: FaceId) { + fn svg(&self, f: &mut Html, _vpid: VisiblePieceId, face: FaceId, + _: &PieceXDataState) { self.svg_piece_raw(f, face, &mut |_|Ok(()))?; } diff --git a/src/shapelib.rs b/src/shapelib.rs index 39e9baad..c7e7c780 100644 --- a/src/shapelib.rs +++ b/src/shapelib.rs @@ -231,7 +231,8 @@ impl PieceBaseTrait for ItemInertForOcculted { #[typetag::serde(name="Lib")] impl InertPieceTrait for ItemInertForOcculted { #[throws(IE)] - fn svg(&self, f: &mut Html, _: VisiblePieceId, face: FaceId) { + fn svg(&self, f: &mut Html, _: VisiblePieceId, face: FaceId, + _: &PieceXDataState) { if face != FaceId::default() { throw!(internal_logic_error("ItemInertForOcculted non-default face")) } @@ -342,12 +343,13 @@ impl FaceTransform { impl Item { #[throws(IE)] - fn svg_face(&self, f: &mut Html, face: FaceId, vpid: VisiblePieceId) { + fn svg_face(&self, f: &mut Html, face: FaceId, vpid: VisiblePieceId, + xdata: &PieceXDataState) { if let Some(face) = self.faces.get(face) { let svgd = &self.svgs[face.svg]; face.xform.write_svgd(f, svgd)?; } else if let Some(back) = &self.back { - back.svg(f, vpid, default())?; + back.svg(f, vpid, default(), &xdata)?; } else { throw!(internal_error_bydebug(&(self, face))) } @@ -382,7 +384,7 @@ impl PieceTrait for Item { #[throws(IE)] fn svg_piece(&self, f: &mut Html, gpc: &GPiece, _gs: &GameState, vpid: VisiblePieceId) { - self.svg_face(f, gpc.face, vpid)?; + self.svg_face(f, gpc.face, vpid, &gpc.xdata)?; } #[throws(IE)] fn describe_html(&self, gpc: &GPiece, _goccults: &GameOccults) -> Html { @@ -395,8 +397,9 @@ impl PieceTrait for Item { #[typetag::serde(name="LibItem")] impl InertPieceTrait for Item { #[throws(IE)] - fn svg(&self, f: &mut Html, id: VisiblePieceId, face: FaceId) { - self.svg_face(f, face, id)?; + fn svg(&self, f: &mut Html, id: VisiblePieceId, face: FaceId, + xdata: &PieceXDataState) { + self.svg_face(f, face, id, xdata)?; } #[throws(IE)] fn describe_html(&self) -> Html { -- 2.30.2