From: Ian Jackson Date: Sat, 13 Feb 2021 11:02:37 +0000 (+0000) Subject: SimpleShape: Move itemname out of common X-Git-Tag: otter-0.4.0~523 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=878aeb46778ef76feea9bc51d0691f37074fcabb;p=otter.git SimpleShape: Move itemname out of common We want Hand not to have an itemname field. Signed-off-by: Ian Jackson --- diff --git a/src/pieces.rs b/src/pieces.rs index c0c02d10..4efae312 100644 --- a/src/pieces.rs +++ b/src/pieces.rs @@ -171,12 +171,11 @@ impl SimpleShape { #[throws(SpecError)] fn new(desc: Html, path: Html, outline: Box, - 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, )? } diff --git a/src/spec.rs b/src/spec.rs index 879cca40..a6725621 100644 --- a/src/spec.rs +++ b/src/spec.rs @@ -199,7 +199,6 @@ pub mod piece_specs { #[derive(Debug,Serialize,Deserialize)] pub struct SimpleCommon { - pub itemname: Option, pub faces: IndexVec, #[serde(default)] pub edges: IndexVec, pub edge_width: Option, @@ -208,6 +207,7 @@ pub mod piece_specs { #[derive(Debug,Serialize,Deserialize)] pub struct Disc { pub diam: Coord, + pub itemname: Option, #[serde(flatten)] pub common: SimpleCommon, } @@ -215,6 +215,7 @@ pub mod piece_specs { #[derive(Debug,Serialize,Deserialize)] pub struct Square { pub size: Vec, + pub itemname: Option, #[serde(flatten)] pub common: SimpleCommon, }