diff --git a/crates/engine/src/cmd/view.rs b/crates/engine/src/cmd/view.rs index b3d5e1ba01..d16c36997e 100644 --- a/crates/engine/src/cmd/view.rs +++ b/crates/engine/src/cmd/view.rs @@ -49,7 +49,7 @@ pub fn commands() -> Vec { }).roles(&[]).effects(crate::policy::Effects::NONE) .params(r#"{"mode": "none"|"distance", "distance"?: metres from the view's centre}"#), C::new("map.terrain", "Terrain", "View › Scene", terrain).roles(&[]).effects(crate::policy::Effects::NONE.with(crate::policy::Effect::Network)).params( - r##"{"layer"?: a DEM raster layer (heights in metres; without layer or tiles, and no terrain yet, the active layer when it is a raster) | "tiles"?: elevation tile URL with {z}/{x}/{y}, "encoding"?: "terrarium"|"mapbox" (tiles; default terrarium), "exaggeration"?: 0 to 20 (default 1, or the terrain's), "block"?: a block diagram {"extent"?: "layer" (the DEM's extent, default) | [xmin, ymin, xmax, ymax] in map units (needed over tiles), "depth"?: metres from the lowest ground to the base (default half the relief, at least 100), "walls"?: "#RRGGBB" (default #C8B89A), "shape"?: "box" (default) | "circle" (the largest circle in the box, its walls round it) | {"layer": a polygon layer, "where"?: sql (picks its polygons, as a definition query)} (the ground inside the polygons' outer rings, holes not cut, the box round them: no extent), "radius"?: a circle's radius in map units (default: the largest in the box), "water"?: the terrain's water shown in the walls' section {"depth"?: metres from the level to the floor, "field"?: a numeric field of the water layer holding each one's depth} (one of them needed), or false}, or false to take it off (default: as it was), "water"?: water bodies drawn flat at their level {"layer": a polygon layer, "level"?: a numeric field of levels in metres (default: each polygon's lowest height along its shore), "glint"?: 0 to 1, how brightly a tilted view's water shines where it reflects the sun toward the eye (default 0.3; 0: none), "shore"?: 0 to 1, how dark the band along the water's shore is at the outline, fading a few pixels inside it (default 0.35; 0: none)}, or false to take it off (default: as it was), "off"?: true}"##, + r##"{"layer"?: a DEM raster layer (heights in metres; without layer or tiles, and no terrain yet, the active layer when it is a raster) | "tiles"?: elevation tile URL with {z}/{x}/{y}, "encoding"?: "terrarium"|"mapbox" (tiles; default terrarium), "exaggeration"?: 0 to 20 (default 1, or the terrain's), "block"?: a block diagram {"extent"?: "layer" (the DEM's extent, default) | [xmin, ymin, xmax, ymax] in map units (needed over tiles), "depth"?: metres from the lowest ground to the base (default half the relief, at least 100), "walls"?: "#RRGGBB" (default #C8B89A) | {"color"?: "#RRGGBB" (default #C8B89A), "layer"?: a polygon layer that holds all its features (not one read a view at a time; it may be hidden): its symbology colours the walls where its polygons meet the block's edge, and the walls are color off its polygons}, "shape"?: "box" (default) | "circle" (the largest circle in the box, its walls round it) | {"layer": a polygon layer, "where"?: sql (picks its polygons, as a definition query)} (the ground inside the polygons' outer rings, holes not cut, the box round them: no extent), "radius"?: a circle's radius in map units (default: the largest in the box), "water"?: the terrain's water shown in the walls' section {"depth"?: metres from the level to the floor, "field"?: a numeric field of the water layer holding each one's depth} (one of them needed), or false}, or false to take it off (default: as it was), "water"?: water bodies drawn flat at their level {"layer": a polygon layer, "level"?: a numeric field of levels in metres (default: each polygon's lowest height along its shore), "glint"?: 0 to 1, how brightly a tilted view's water shines where it reflects the sun toward the eye (default 0.3; 0: none), "shore"?: 0 to 1, how dark the band along the water's shore is at the outline, fading a few pixels inside it (default 0.35; 0: none)}, or false to take it off (default: as it was), "off"?: true}"##, ), C::new("map.exportOrbit", "Export Orbit", "View › Scene", |s, p| super::exports::write_here(s, p, "map.exportOrbit")).inputs(orbit_inputs).roles(&[]).effects(crate::policy::Effects::NONE.with(crate::policy::Effect::Files)) .view() @@ -524,7 +524,7 @@ fn terrain(s: &mut Session, p: &Value) -> CmdResult { Some(Value::Null | Value::Bool(false)) => Some(None), Some(Value::Bool(true)) => Some(Some(terrain_block(s, &serde_json::Map::new())?)), Some(Value::Object(b)) => Some(Some(terrain_block(s, b)?)), - Some(_) => return Err("block is an object {\"extent\"?, \"depth\"?, \"walls\"?, \"water\"?}, or false to take it off".into()), + Some(_) => return Err("block is an object (extent, depth, walls, shape, radius, water), or false to take it off".into()), }; // Left out (or null, as for the exaggeration), the water stays as it was; false takes it off // (#1915). @@ -532,7 +532,7 @@ fn terrain(s: &mut Session, p: &Value) -> CmdResult { None | Some(Value::Null) => None, Some(Value::Bool(false)) => Some(None), Some(Value::Object(w)) => Some(Some(terrain_water(s, w)?)), - Some(_) => return Err("water is an object {\"layer\", \"level\"?}, or false to take it off".into()), + Some(_) => return Err("water is an object (layer, level, glint, shore), or false to take it off".into()), }; let exaggeration = match p.get("exaggeration").filter(|v| !v.is_null()) { Some(_) => { diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index a65189680e..fae9e30615 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -14371,6 +14371,44 @@ fn terrain_block_walls_follow_a_polygon_layer() { assert!(s.map().view.terrain.is_none()); } +/// #2605: `map.terrain`'s help names every key the block's parts and the water take, each in its +/// own part of the text, as the parser lists them when it refuses one it doesn't know (the walls' +/// object form of #2173 was missing); so do the errors for a block or water that isn't an object. +#[test] +fn terrain_help_names_every_block_key() { + let mut s = Session::new(Project::default()); + let help = s.registry.get("map.terrain").map(|c| c.params).unwrap(); + // The text between `from` and the next `to` after it. + let part = |from: &str, to: &str| { + let at = help.find(from).unwrap_or_else(|| panic!("no {from} in {help}")); + let rest = &help[at..]; + rest[..rest.find(to).unwrap_or_else(|| panic!("no {to} after {from}"))].to_string() + }; + // The keys an error lists at its end, "(a, b, c)". + let listed = |e: &str| -> Vec { + let keys = e.rsplit_once('(').and_then(|(_, k)| k.strip_suffix(')')).unwrap_or_else(|| panic!("{e}")); + keys.split(", ").map(str::to_string).collect() + }; + for (params, from, to) in [ + (json!({"block": {"bogus": 1}}), r#""block"?:"#, ", or false to take it off"), + (json!({"block": {"walls": {"bogus": 1}}}), r#""walls"?:"#, r#", "shape"?:"#), + (json!({"block": {"shape": {"bogus": 1}}}), r#""shape"?:"#, r#", "radius"?:"#), + (json!({"block": {"water": {"bogus": 1}}}), r#""water"?: the terrain's water"#, ", or false}"), + (json!({"water": {"bogus": 1}}), r#""water"?: water bodies"#, ", or false to take it off"), + ] { + let e = s.run("map.terrain", ¶ms).unwrap_err(); + let text = part(from, to); + for k in listed(&e) { + assert!(text.contains(&format!("\"{k}\"")), "{params}: the help's {from} part doesn't name \"{k}\": {text}"); + } + } + for (what, wrong) in [("block", json!({"block": {"bogus": 1}})), ("water", json!({"water": {"bogus": 1}}))] { + let keys = listed(&s.run("map.terrain", &wrong).unwrap_err()); + let e = s.run("map.terrain", &json!({what: 3})).unwrap_err(); + assert_eq!(listed(e.split_once(", or false").map_or(e.as_str(), |(head, _)| head)), keys, "{e}"); + } +} + #[test] fn terrain_block_water_needs_the_terrains_water_and_a_depth() { // #2317: the water a block's walls cut through, deep by a number or a numeric field.