chiark / gitweb /
Revert "SimpleShape: Move itemname out of common"
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 13 Feb 2021 11:05:30 +0000 (11:05 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 13 Feb 2021 11:06:03 +0000 (11:06 +0000)
Actually we need to reuse Disc and Square as they are, so we must
do this by hand somehow.

This reverts commit 878aeb46778ef76feea9bc51d0691f37074fcabb.

src/pieces.rs
src/spec.rs

index 4efae312b13964a79b78891439c794993d721710..c0c02d10385c8b52214504caf5d9f73cf436d523 100644 (file)
@@ -171,11 +171,12 @@ impl SimpleShape {
   #[throws(SpecError)]
   fn new(desc: Html, path: Html,
          outline: Box<dyn Outline>,
-         itemname: &'_ str,
+         def_itemname: &'_ str,
          common: &piece_specs::SimpleCommon)
          -> SimpleShape
   {
-    let itemname = itemname.to_owned();
+    let itemname = common.itemname.clone()
+      .unwrap_or_else(|| def_itemname.to_string());
 
     let cmap = |spec: &FaceColourSpecs| Ok::<_,SpecError>(
       spec
@@ -225,7 +226,7 @@ impl SimplePieceSpec for piece_specs::Disc {
       Html::lit("disc"),
       svg_circle_path(self.diam as f64)?,
       Box::new(outline),
-      self.itemname.as_deref().unwrap_or("simple-disc"),
+      "simple-disc",
       &self.common,
     )?
   }
@@ -256,7 +257,7 @@ impl SimplePieceSpec for piece_specs::Square {
       Html::lit("square"),
       svg_rectangle_path(self.xy()?.promote())?,
       Box::new(outline),
-      self.itemname.as_deref().unwrap_or("simple-square"),
+      "simple-square",
       &self.common,
     )?
   }
index a6725621418d91f83850b7bffae0064277decd49..879cca400f4286ddc69538f53b59f09d2ea18e3e 100644 (file)
@@ -199,6 +199,7 @@ pub mod piece_specs {
 
   #[derive(Debug,Serialize,Deserialize)]
   pub struct SimpleCommon {
+    pub itemname: Option<String>,
     pub faces: IndexVec<FaceId, ColourSpec>,
     #[serde(default)] pub edges: IndexVec<FaceId, ColourSpec>,
     pub edge_width: Option<f64>,
@@ -207,7 +208,6 @@ pub mod piece_specs {
   #[derive(Debug,Serialize,Deserialize)]
   pub struct Disc {
     pub diam: Coord,
-    pub itemname: Option<String>,
     #[serde(flatten)]
     pub common: SimpleCommon,
   }
@@ -215,7 +215,6 @@ pub mod piece_specs {
   #[derive(Debug,Serialize,Deserialize)]
   pub struct Square {
     pub size: Vec<Coord>,
-    pub itemname: Option<String>,
     #[serde(flatten)]
     pub common: SimpleCommon,
   }