From: Ian Jackson Date: Fri, 12 Feb 2021 23:41:06 +0000 (+0000) Subject: break out SimpleShape X-Git-Tag: otter-0.4.0~531 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=466cc71c6dd94bd1317d1d852be41228e796c161;p=otter.git break out SimpleShape NFC Signed-off-by: Ian Jackson --- diff --git a/src/pieces.rs b/src/pieces.rs index a5e5aa92..2bc59e80 100644 --- a/src/pieces.rs +++ b/src/pieces.rs @@ -140,15 +140,14 @@ impl Piece for SimpleShape { impl SimpleShape { #[throws(SpecError)] fn new(desc: Html, path: Html, - faces: &IndexVec, outline: Box, - spec_itemname: &Option, - 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::>()?; @@ -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, )? } } diff --git a/src/spec.rs b/src/spec.rs index 59d55273..03bcccb2 100644 --- a/src/spec.rs +++ b/src/spec.rs @@ -195,17 +195,23 @@ pub mod piece_specs { pub type FaceColourSpecs = IndexVec; #[derive(Debug,Serialize,Deserialize)] - pub struct Disc { + pub struct SimpleCommon { pub itemname: Option, - pub diam: Coord, pub faces: IndexVec, } + #[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, pub size: Vec, - pub faces: IndexVec, + #[serde(flatten)] + pub common: SimpleCommon, } /* pub struct Hand {