chiark / gitweb /
Implement InertPieceTrait for SimpleShape
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 11 Apr 2022 09:50:03 +0000 (10:50 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 11 Apr 2022 10:01:16 +0000 (11:01 +0100)
Right now, this allows simple circles and rectangles to be used as
backs (for occultation).  It will also allow them to be used for dice,
when we have those.

It is not convenient to provide a test for this because occultation
methods must be provided in libraries, and we don't have a test
library.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/pieces.rs

index a1563be1944607550694d7f3c0a5ef605e346ad5..c65294bba205b05ef4d78ead0d306afe1dd2efcc 100644 (file)
@@ -150,6 +150,21 @@ impl PieceTrait for SimpleShape {
   fn itemname(&self) -> &str { self.itemname() }
 }
 
+#[typetag::serde]
+impl InertPieceTrait for SimpleShape {
+  fn nfaces(&self) -> RawFaceId { PieceTrait::nfaces(self) }
+
+  #[throws(IE)]
+  fn svg(&self, f: &mut Html, _vpid: VisiblePieceId, face: FaceId) {
+    self.svg_piece_raw(f, face, &mut |_|Ok(()))?; 
+  }
+
+  #[throws(IE)]
+  fn describe_html(&self) -> Html {
+    hformat!("a {}", self.desc)
+  }
+}
+
 #[derive(Debug,Clone,Serialize,Deserialize)]
 pub struct PieceLabelLoaded {
   #[serde(default)] pub place: piece_specs::PieceLabelPlace,