chiark / gitweb /
shapelib refactoring: Break out svg_face and describe_face
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 22 Mar 2021 00:56:51 +0000 (00:56 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 22 Mar 2021 01:01:57 +0000 (01:01 +0000)
We're going to want to reuse this.

Happily, this gets rid of a call to GPiece::dummy().

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

index 178d755d9fddcce62b2dbf27fcb06aa774479b4a..448c293c302c99f54131c1affd4ac149b7ac2ad9 100644 (file)
@@ -238,6 +238,20 @@ impl FaceTransform {
   }
 }
 
+impl Item {
+  #[throws(IE)]
+  fn svg_face(&self, f: &mut Html, face: FaceId) {
+    let face = &self.faces[face];
+    let svgd = &self.svgs[face.svg];
+    face.xform.write_svgd(f, svgd)?;
+  }
+
+  #[throws(IE)]
+  fn describe_face(&self, face: FaceId) -> Html {
+    self.descs[ self.faces[face].desc ].clone()
+  }
+}
+
 #[typetag::serde(name="Lib")]
 impl PieceTrait for Item {
   fn nfaces(&self) -> RawFaceId {
@@ -245,15 +259,13 @@ impl PieceTrait for Item {
   }
 
   #[throws(IE)]
-  fn svg_piece(&self, f: &mut Html, gpc: &GPiece, _gs: &GameState, _vpid: VisiblePieceId) {
-    let face = &self.faces[gpc.face];
-    let svgd = &self.svgs[face.svg];
-    face.xform.write_svgd(f, svgd)?;
-    
+  fn svg_piece(&self, f: &mut Html, gpc: &GPiece,
+               _gs: &GameState, _vpid: VisiblePieceId) {
+    self.svg_face(f, gpc.face)?;
   }
   #[throws(IE)]
   fn describe_html(&self, gpc: &GPiece) -> Html {
-    self.descs[ self.faces[gpc.face].desc ].clone()
+    self.describe_face(gpc.face)?
   }
 
   fn itemname(&self) -> &str { &self.itemname }
@@ -391,7 +403,7 @@ impl Contents {
       let ier = ItemEnquiryData {
         itemname: k.clone(),
         f0bbox,
-        f0desc: loaded.describe_html(&GPiece::dummy())?,
+        f0desc: loaded.describe_face(default())?,
       };
       out.push(ier);
     }