chiark / gitweb /
SimpleShape: Move itemname out of common
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 13 Feb 2021 11:02:37 +0000 (11:02 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 13 Feb 2021 11:02:37 +0000 (11:02 +0000)
We want Hand not to have an itemname field.

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

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