From: Ian Jackson Date: Sat, 13 Feb 2021 01:44:24 +0000 (+0000) Subject: SimpleShape: Allow specifying edge width X-Git-Tag: otter-0.4.0~525 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=5d7d4818477a47687ef9bbcb1c69d514d3166d14;p=otter.git SimpleShape: Allow specifying edge width Signed-off-by: Ian Jackson --- diff --git a/specs/demo.game.toml b/specs/demo.game.toml index c3c1d3fd..c8b1028e 100644 --- a/specs/demo.game.toml +++ b/specs/demo.game.toml @@ -38,3 +38,4 @@ size = [10] angle.Compass = 1 faces = [ ] edges = ["yellow", "orange"] +edge_width = 0.5 diff --git a/src/pieces.rs b/src/pieces.rs index 727141ef..2cb8fd18 100644 --- a/src/pieces.rs +++ b/src/pieces.rs @@ -17,12 +17,17 @@ struct SimpleShape { path: Html, colours: ColourMap, #[serde(default)] edges: ColourMap, + #[serde(default="default_edge_width")] edge_width: f64, itemname: String, outline: Box, } pub const SELECT_SCALE: f64 = 1.1; +pub const DEFAULT_EDGE_WIDTH: f64 = 0.2; + +fn default_edge_width() -> f64 { DEFAULT_EDGE_WIDTH } + #[derive(Copy,Clone,Debug,Error,Serialize,Deserialize)] pub enum SVGProcessingError { UnknownOperator, @@ -117,6 +122,7 @@ impl Outline for SimpleShape { } } } +// let edge_attrs = format!(r##"stroke-width="" stroke"## #[typetag::serde] impl Piece for SimpleShape { @@ -125,7 +131,7 @@ impl Piece for SimpleShape { let f = &mut f.0; let ef = |f: &mut String, cmap: &ColourMap, attrname: &str, otherwise| { if let Some(colour) = cmap.get(pri.face) { - write!(f, r##"{}="{}""##, attrname, colour.0) + write!(f, r##" {}="{}""##, attrname, colour.0) } else { write!(f, "{}", otherwise) } @@ -136,9 +142,12 @@ impl Piece for SimpleShape { stroke-width="2" stroke="transparent" d="{}"/>"##, &self.path.0)?; } - write!(f, r##""##, &self.path.0)?; } fn describe_html(&self, face: Option) -> Html { @@ -174,10 +183,15 @@ impl SimpleShape { .collect::>()? ); + if common.edge_width.is_some() && common.edges.len() == 0 { + throw!(SpecError::SpecifiedWidthOfNoEdges); + } + let shape = SimpleShape { desc, path, itemname, outline, colours: cmap(&common.faces)?, edges: cmap(&common.edges)?, + edge_width: common.edge_width.unwrap_or(DEFAULT_EDGE_WIDTH), }; let count = shape.count_faces(); diff --git a/src/spec.rs b/src/spec.rs index 1b20ff35..879cca40 100644 --- a/src/spec.rs +++ b/src/spec.rs @@ -79,6 +79,7 @@ pub enum SpecError { CompassAngleInvalid, ZeroFaces, InconsistentFacesEdgecoloursCount, + SpecifiedWidthOfNoEdges, } display_as_debug!{SpecError} @@ -201,6 +202,7 @@ pub mod piece_specs { pub itemname: Option, pub faces: IndexVec, #[serde(default)] pub edges: IndexVec, + pub edge_width: Option, } #[derive(Debug,Serialize,Deserialize)]