chiark / gitweb /
Extend InertPieceTrait to support multiple faces
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 11 Apr 2022 09:18:12 +0000 (10:18 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 11 Apr 2022 09:25:55 +0000 (10:25 +0100)
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 <ijackson@chiark.greenend.org.uk>
src/gamestate.rs
src/pcrender.rs
src/shapelib.rs

index fe167c478c158ca79e61659a63dbdfc202abd8b0..6f229f209d3f6b07d43e6206ceb0fb9e76d80fd5 100644 (file)
@@ -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<Html,IE>;
 }
 
index 3a65dc450c6b33f516fc5d528a2f30a85a13c3ef..5d9b83a7afae80303bd0d10595506e94f1928835 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)?;
+        i.svg(&mut defs, pri.vpid, default())?;
       },
     };
 
index eca18a237452a5380850665c359b063f77032c0f..c50c53d575c91aa8448ca7d83b86c10447419c54 100644 (file)
@@ -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 { <Item as PieceTrait>::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 {