chiark / gitweb /
break out SimpleShape
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 12 Feb 2021 23:41:06 +0000 (23:41 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 13 Feb 2021 01:47:10 +0000 (01:47 +0000)
NFC

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

index a5e5aa92249b74a337604319f76d596bacac0c90..2bc59e804d972c5e85e36d236fe5b0bd35adc357 100644 (file)
@@ -140,15 +140,14 @@ impl Piece for SimpleShape {
 impl SimpleShape {
   #[throws(SpecError)]
   fn new(desc: Html, path: Html,
-         faces: &IndexVec<FaceId,ColourSpec>,
          outline: Box<dyn Outline>,
-         spec_itemname: &Option<String>,
-         def_itemname: &'_ str)
+         def_itemname: &'_ str,
+         common: &piece_specs::SimpleCommon)
          -> SimpleShape
   {
-    let itemname = spec_itemname.clone()
+    let itemname = common.itemname.clone()
       .unwrap_or_else(|| def_itemname.to_string());
-    let colours = faces
+    let colours = common.faces
       .iter()
       .map(|s| s.try_into())
       .collect::<Result<_,SpecError>>()?;
@@ -172,10 +171,9 @@ impl SimplePieceSpec for piece_specs::Disc {
     SimpleShape::new(
       Html::lit("disc"),
       svg_circle_path(self.diam as f64)?,
-      &self.faces,
       Box::new(outline),
-      &self.itemname,
       "simple-disc",
+      &self.common,
     )?
   }
 }
@@ -204,10 +202,9 @@ impl SimplePieceSpec for piece_specs::Square {
     SimpleShape::new(
       Html::lit("square"),
       svg_rectangle_path(self.xy()?.promote())?,
-      &self.faces,
       Box::new(outline),
-      &self.itemname,
       "simple-square",
+      &self.common,
     )?
   }
 }
index 59d55273a75043d6cdf421413b5cc52a7b3d143d..03bcccb20cecfa9e6adb4b39ecfe8370267e3b67 100644 (file)
@@ -195,17 +195,23 @@ pub mod piece_specs {
   pub type FaceColourSpecs = IndexVec<FaceId,ColourSpec>;
 
   #[derive(Debug,Serialize,Deserialize)]
-  pub struct Disc {
+  pub struct SimpleCommon {
     pub itemname: Option<String>,
-    pub diam: Coord,
     pub faces: IndexVec<FaceId, ColourSpec>,
   }
 
+  #[derive(Debug,Serialize,Deserialize)]
+  pub struct Disc {
+    pub diam: Coord,
+    #[serde(flatten)]
+    pub common: SimpleCommon,
+  }
+
   #[derive(Debug,Serialize,Deserialize)]
   pub struct Square {
-    pub itemname: Option<String>,
     pub size: Vec<Coord>,
-    pub faces: IndexVec<FaceId, ColourSpec>,
+    #[serde(flatten)]
+    pub common: SimpleCommon,
   }
 /*
   pub struct Hand {