chiark / gitweb /
Plumb xdata through to InertPieceTrait svg
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 14 Apr 2022 19:55:17 +0000 (20:55 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 14 Apr 2022 19:57:09 +0000 (20:57 +0100)
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 <ijackson@chiark.greenend.org.uk>
src/gamestate.rs
src/pcrender.rs
src/pieces.rs
src/shapelib.rs

index 74c5670bf8ed3fc0843f0d55f24c1c94b1edb422..9dc9d8ff443be4a3cf085fafd36b5db4bd89d7d5 100644 (file)
@@ -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<Html,IE>;
 }
 
index 5d9b83a7afae80303bd0d10595506e94f1928835..6dbcb80a9285ac2acea183a4c4e89ba17c5ad48c 100644 (file)
@@ -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)?;
       },
     };
 
index ac3e093ef8a3bce916be68135e94166b05948f7c..14194eeb38437f84d6fdc3818241b40e44dae762 100644 (file)
@@ -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(()))?; 
   }
 
index 39e9baad3dfa131fb8a22f6286b685b7ff305d3b..c7e7c780737d3136aafddf08581e8c5c2adac50b 100644 (file)
@@ -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 {