From 79fb877fd9a3f16f2daa7a5c69f0b40748895c48 Mon Sep 17 00:00:00 2001 From: Lobstery_v2 Date: Mon, 16 Nov 2026 16:58:21 +0800 Subject: [PATCH 1/3] AI paths: take a snapped lane's height out of the new path's own offset --- src/editor.rs | 31 ++++- src/editor/path_snap_tests.rs | 209 ++++++++++++++++++++++++++++++++++ 2 files changed, 238 insertions(+), 2 deletions(-) create mode 100644 src/editor/path_snap_tests.rs diff --git a/src/editor.rs b/src/editor.rs index cbb7d8a..5333685 100644 --- a/src/editor.rs +++ b/src/editor.rs @@ -4168,7 +4168,8 @@ impl Editor { .filter(|(d, _)| *d < 4.0) .min_by(|a, b| a.0.total_cmp(&b.0)); if let Some((_, e)) = end { - return Some((Anchor { pos: e.pos, heading: e.heading, ..Default::default() }, file)); + let anchor = self.lane_anchor(assets, kind, Anchor { pos: e.pos, heading: e.heading, ..Default::default() }, starting); + return Some((anchor, file)); } let along = lanes .iter() @@ -4181,10 +4182,33 @@ impl Editor { // (on a spline's lane: the spline is cut there when the path is built, so the lane // has an end there for the path to join - openOMSI joins lanes only end to end) let mid = sp.zip(at).filter(|((_, _, len), at)| *at > 0.6 && *at < len - 0.6).map(|((k, id, _), at)| (k, id, at, 0.0)); - (Anchor { pos: q, heading: roads::norm_deg(if starting { flow } else { flow + 180.0 }), mid, ..Default::default() }, file) + let anchor = Anchor { pos: q, heading: roads::norm_deg(if starting { flow } else { flow + 180.0 }), mid, ..Default::default() }; + (self.lane_anchor(assets, kind, anchor, starting), file) }) } + /// A lane's point made the start or end of a new path of the type being drawn: the lane + /// lies on the road's line, the new path's own line lies its `[path]` z above (or below) + /// that, so the height is brought back by as much. Only the height: a path set to the + /// side of its spline (`x`) is left as it is (with a note), and x is not corrected. + fn lane_anchor(&self, assets: &mut Assets, kind: i32, mut a: Anchor, starting: bool) -> Anchor { + let Some(rel) = self.path_type.clone() else { return a }; + let Some(m) = assets.spline(&rel) else { return a }; + let Some(p) = m.def.paths.iter().find(|p| p.kind == kind) else { return a }; + if p.start[0].abs() > 1e-6 { + log::warn!("AI path {rel}: its {kind} path lies {} m to the side of the spline; only the height is taken from the lane", p.start[0]); + } + let before = a.pos.z; + a.pos.z -= p.start[2] as f64; + log::info!( + "AI path {rel}: lane of kind {kind} (path z {:.3}) snapped at the {}: anchor z {before:.3} -> {:.3}", + p.start[2], + if starting { "start" } else { "end" }, + a.pos.z + ); + a + } + /// A path starts at a lane end of its own kind: near the end of a footway lane the path type /// becomes the footpath, near a street lane's the street. fn follow_lane_kind(&mut self, assets: &mut Assets, p: DVec2) { @@ -17131,4 +17155,7 @@ mod tests { #[cfg(test)] mod bus_lane_tests; +#[cfg(test)] +mod path_snap_tests; + mod bus_rule_batch; diff --git a/src/editor/path_snap_tests.rs b/src/editor/path_snap_tests.rs new file mode 100644 index 0000000..4644e71 --- /dev/null +++ b/src/editor/path_snap_tests.rs @@ -0,0 +1,209 @@ +use super::*; +use crate::selection::tests::flat_map; + +/// The AI path types, a crossing object with a path, and a map of flat ground with the +/// editor drawing AI paths on it. +struct Paths { + dir: std::path::PathBuf, + street: String, + walk: String, + cross: String, + assets: Assets, + editor: Editor, +} + +impl Paths { + fn new(tag: &str) -> Self { + let dir = std::env::temp_dir().join(format!("om-path-snap-{tag}-{}", std::process::id())); + let _ = std::fs::remove_dir_all(&dir); + std::fs::create_dir_all(&dir).unwrap(); + let content = dir.join("content"); + std::fs::create_dir_all(&content).unwrap(); + let street = "Splines\\Marcel\\invis_street.sli".to_string(); + let walk = "Splines\\invis_sidewalk.sli".to_string(); + let cross = "Sceneryobjects\\cross.sco".to_string(); + // (`[path]` of a `.sli`: kind, x to the right, z up, width, direction; of a `.sco`: + // its start, heading / radius / length, and the same kind, width and direction) + for (rel, text) in [ + (&street, "[path]\n0\n0\n0.1\n3\n0\n"), + (&walk, "[path]\n1\n0\n-2\n2\n2\n"), + (&cross, "[path]\n0\n0\n0.1\n0\n0\n50\n0\n0\n0\n3\n0\n0\n"), + ] { + let p = omsi_cfg::resolve_path(&content, rel); + std::fs::create_dir_all(p.parent().unwrap()).unwrap(); + std::fs::write(&p, text).unwrap(); + } + let mut assets = Assets::new(dir.join("omsi"), content.clone()); + for rel in [&street, &walk] { + assert!(assets.spline_wait(rel, 5000).is_some(), "{rel} loads"); + } + assert!(assets.object_wait(&cross, 5000).is_some(), "{cross} loads"); + let mut doc = flat_map(1); + doc.dir = content.join("maps/Test"); + let mut editor = Editor::default(); + editor.content_dir = Some(content.clone()); + editor.open(doc); + editor.tool = Tool::Logic; + editor.logic = LogicMode::Paths; + editor.auto_junctions = false; + Self { dir, street, walk, cross, assets, editor } + } + + /// A spline of `file` laid from (`x`, `y`), heading, along the ground at z 0. + fn lane(&mut self, id: i64, file: &str, x: f64, y: f64, heading: f64, length: f64) { + let doc = self.editor.doc.as_mut().unwrap(); + let t = doc.tiles.get_mut(&(0, 0)).unwrap(); + t.tile.splines.push(MapSpline { file: file.to_string(), id, pos: [x, y, 0.0], heading, length, ..Default::default() }); + t.touch_content(); + } + + /// A crossing object of `file` standing at (`x`, `y`) on the ground. + fn object(&mut self, id: i64, file: &str, x: f64, y: f64) { + let doc = self.editor.doc.as_mut().unwrap(); + let t = doc.tiles.get_mut(&(0, 0)).unwrap(); + t.tile.objects.push(MapObject { file: file.to_string(), id, pos: [x, y, 0.0], ..Default::default() }); + t.touch_content(); + } + + fn type_of(&mut self, file: &str) { + self.editor.path_type = Some(file.to_string()); + self.editor.road_type = Some(file.to_string()); + } + + /// A click at (`x`, `y`) on the ground: starts the path, or builds it. + fn click(&mut self, x: f64, y: f64) { + self.editor.cursor = Some(DVec3::new(x, y, 0.0)); + self.editor.plan_road(&mut self.assets); + self.editor.road_click(&mut self.assets, &Library::default()); + } + + /// The plan drawn to (`x`, `y`) as (start height, end height). + fn plan(&mut self, x: f64, y: f64) -> (f64, f64) { + self.editor.cursor = Some(DVec3::new(x, y, 0.0)); + self.editor.plan_road(&mut self.assets); + let p = self.editor.road_plan.as_ref().expect("a plan"); + (p.1, p.2) + } + + /// The spline of `file` made in the map, starting nearest (`x`, `y`). + fn made(&self, file: &str, x: f64, y: f64) -> Option<(TileKey, MapSpline)> { + let doc = self.editor.doc.as_ref().unwrap(); + let mut best: Option<(f64, TileKey, MapSpline)> = None; + for (k, t) in &doc.tiles { + for s in t.tile.splines.iter().filter(|s| !s.deleted && s.file.eq_ignore_ascii_case(file)) { + let c = omsi_geometry::SplineCurve::from_map(s, tile_origin(*k)); + let d = (c.point_at(0.0).truncate() - DVec2::new(x, y)).length(); + if d < 1.0 && best.as_ref().map(|b| d < b.0).unwrap_or(true) { + best = Some((d, *k, s.clone())); + } + } + } + best.map(|b| (b.1, b.2)) + } +} + +impl Drop for Paths { + fn drop(&mut self) { + let _ = std::fs::remove_dir_all(&self.dir); + } +} + +/// The path's own height along a spline, at its start and at its end (world). +fn world_heights(k: TileKey, s: &MapSpline, file: &str, assets: &mut Assets) -> (f64, f64) { + let z = assets.spline(file).and_then(|m| m.def.paths.first().map(|p| p.start[2] as f64)).unwrap_or_else(|| panic!("{file} loads")); + let c = omsi_geometry::SplineCurve::from_map(s, tile_origin(k)); + (c.point_at(0.0).z + z, c.end_point().z + z) +} + +#[test] +fn a_path_started_on_a_street_lane_keeps_the_lane_height() { + let mut f = Paths::new("street"); + let street = f.street.clone(); + f.lane(1, &street, 100.0, 100.0, 0.0, 50.0); + f.lane(2, &street, 100.0, 160.0, 0.0, 50.0); + f.type_of(&street); + // from the far end of one lane to the near end of another: both lie 0.1 m above + // the ground, so the new path's line is laid 0.1 m below them + f.click(100.0, 150.0); + let (start, _) = f.editor.road_start.expect("started on the lane's end"); + assert!((start.pos.z - 0.0).abs() < 1e-9, "started at {}", start.pos.z); + let (z0, z1) = f.plan(100.0, 160.0); + assert!((z0 - 0.0).abs() < 1e-9, "z0 {z0}"); + assert!((z1 - 0.0).abs() < 1e-9, "z1 {z1}"); + f.click(100.0, 160.0); + let (k, s) = f.made(&street, 100.0, 150.0).expect("the path is made"); + let (at_start, at_end) = world_heights(k, &s, &street, &mut f.assets); + assert!((at_start - 0.1).abs() < 0.001, "start path height {at_start}"); + assert!((at_end - 0.1).abs() < 0.001, "end path height {at_end}"); +} + +#[test] +fn a_path_started_on_a_footway_lane_keeps_the_lane_height() { + let mut f = Paths::new("walk"); + let walk = f.walk.clone(); + f.lane(1, &walk, 100.0, 100.0, 0.0, 50.0); + f.lane(2, &walk, 100.0, 160.0, 0.0, 50.0); + f.type_of(&walk); + // the footpath's line lies 2 m below the lane's + f.click(100.0, 150.0); + let (start, _) = f.editor.road_start.expect("started on the lane's end"); + assert!((start.pos.z - 0.0).abs() < 1e-9, "started at {}", start.pos.z); + let (z0, z1) = f.plan(100.0, 160.0); + assert!((z0 - 0.0).abs() < 1e-9, "z0 {z0}"); + assert!((z1 - 0.0).abs() < 1e-9, "z1 {z1}"); + f.click(100.0, 160.0); + let (k, s) = f.made(&walk, 100.0, 150.0).expect("the path is made"); + let (at_start, at_end) = world_heights(k, &s, &walk, &mut f.assets); + assert!((at_start + 2.0).abs() < 0.001, "start path height {at_start}"); + assert!((at_end + 2.0).abs() < 0.001, "end path height {at_end}"); +} + +#[test] +fn a_path_started_on_the_ground_keeps_the_ground_height() { + let mut f = Paths::new("ground"); + let walk = f.walk.clone(); + // (a lane 10 m away: no end and no place of it is taken) + f.lane(1, &walk, 100.0, 100.0, 0.0, 50.0); + f.type_of(&walk); + f.click(250.0, 250.0); + let (start, _) = f.editor.road_start.expect("started on the ground"); + assert!((start.pos.z - 0.0).abs() < 1e-9, "started at {}", start.pos.z); + let (z0, _) = f.plan(250.0, 280.0); + assert!((z0 - 0.0).abs() < 1e-9, "z0 {z0}"); +} + +#[test] +fn a_path_started_in_the_middle_of_a_lane_keeps_the_lane_height() { + let mut f = Paths::new("mid"); + let street = f.street.clone(); + f.lane(1, &street, 100.0, 100.0, 0.0, 50.0); + f.type_of(&street); + f.click(100.0, 125.0); + let (start, fixed) = f.editor.road_start.expect("started in the lane"); + assert!(start.mid.is_some(), "a place along the lane"); + assert!(fixed, "the lane's way kept"); + assert!((start.pos.z - 0.0).abs() < 1e-9, "started at {}", start.pos.z); + let (z0, _) = f.plan(150.0, 125.0); + assert!((z0 - 0.0).abs() < 1e-9, "z0 {z0}"); +} + +#[test] +fn a_path_started_on_a_crossing_objects_lane_keeps_the_lane_height() { + let mut f = Paths::new("object"); + let cross = f.cross.clone(); + let street = f.street.clone(); + f.object(1, &cross, 250.0, 100.0); + f.type_of(&street); + // the object's path runs from (250, 100) to (250, 150) 0.1 m above the ground + f.click(250.0, 150.0); + let (start, _) = f.editor.road_start.expect("started on the object's path end"); + assert!((start.pos.z - 0.0).abs() < 1e-9, "started at {}", start.pos.z); + let (z0, z1) = f.plan(250.0, 160.0); + assert!((z0 - 0.0).abs() < 1e-9, "z0 {z0}"); + assert!((z1 - 0.0).abs() < 1e-9, "z1 {z1}"); + f.click(250.0, 160.0); + let (k, s) = f.made(&street, 250.0, 150.0).expect("the path is made"); + let (at_start, at_end) = world_heights(k, &s, &street, &mut f.assets); + assert!((at_start - 0.1).abs() < 0.001, "start path height {at_start}"); + assert!((at_end - 0.1).abs() < 0.001, "end path height {at_end}"); +} From 19b3c7fefbb504f697101dae085d8e9e8dc8b26d Mon Sep 17 00:00:00 2001 From: Lobstery_v2 Date: Mon, 16 Nov 2026 17:00:13 +0800 Subject: [PATCH 2/3] AI paths: Shift and typed numbers while drawing a path --- src/editor.rs | 13 ++++-- src/editor/path_snap_tests.rs | 83 +++++++++++++++++++++++++++++++++++ src/ui_edit.rs | 2 +- 3 files changed, 94 insertions(+), 4 deletions(-) diff --git a/src/editor.rs b/src/editor.rs index 5333685..1fd2b52 100644 --- a/src/editor.rs +++ b/src/editor.rs @@ -4398,12 +4398,19 @@ impl Editor { let typed = self.typed(); let z0 = start.pos.z; // numbers typed or the straight lock: the road is drawn by them, not to what the - // cursor is near - if (typed.any() || self.straight_lock) && !self.drawing_paths() { + // cursor is near. An AI path is a line of its own, not the ground's: it rises only + // as far as the rise typed for it. + if typed.any() || self.straight_lock { let Some(segs) = crate::draw::plan(start.pos.truncate(), fixed.then_some(start.heading), self.snap_point(c.truncate()), &typed, self.straight_lock) else { return }; self.road_snap = None; let end = segs.last().unwrap().end(); - let z1 = if self.keep_height { z0 + self.typed_rise() } else if !self.auto_terrain { z0 } else { self.doc.as_ref().map(|d| d.ground(end)).unwrap_or(c.z) }; + let z1 = if self.drawing_paths() || self.keep_height { + z0 + self.typed_rise() + } else if !self.auto_terrain { + z0 + } else { + self.doc.as_ref().map(|d| d.ground(end)).unwrap_or(c.z) + }; self.road_plan = Some((segs, z0, z1, None)); return; } diff --git a/src/editor/path_snap_tests.rs b/src/editor/path_snap_tests.rs index 4644e71..b8ee710 100644 --- a/src/editor/path_snap_tests.rs +++ b/src/editor/path_snap_tests.rs @@ -207,3 +207,86 @@ fn a_path_started_on_a_crossing_objects_lane_keeps_the_lane_height() { assert!((at_start - 0.1).abs() < 0.001, "start path height {at_start}"); assert!((at_end - 0.1).abs() < 0.001, "end path height {at_end}"); } + +#[test] +fn a_straight_lock_draws_an_ai_path_straight_from_a_lane_end() { + let mut f = Paths::new("straight"); + let street = f.street.clone(); + f.lane(1, &street, 100.0, 100.0, 0.0, 50.0); + f.type_of(&street); + f.click(100.0, 150.0); + let (start, _) = f.editor.road_start.expect("started on the lane's end"); + // Shift held while drawing a path: a straight on from the lane, at its height + f.editor.straight_lock = true; + let (z0, z1) = f.plan(100.0, 165.0); + assert!((z0 - 0.0).abs() < 1e-9, "z0 {z0}"); + assert!((z1 - z0).abs() < 1e-9, "z1 {z1} follows z0 {z0}"); + let (segs, _, _, _) = f.editor.road_plan.as_ref().expect("a plan"); + let last = segs.last().expect("a piece"); + assert!(last.radius.abs() < 1e-9, "radius {}", last.radius); + assert!((roads::norm_deg(last.end_heading()) - roads::norm_deg(start.heading)).abs() < 1e-9, "heading {} from {}", last.end_heading(), start.heading); + f.click(100.0, 165.0); + let (k, s) = f.made(&street, 100.0, 150.0).expect("the path is made"); + assert!(s.radius.abs() < 1e-9, "built radius {}", s.radius); + assert!((s.heading - start.heading).abs() < 1e-9, "built heading {} from {}", s.heading, start.heading); + let (at_start, at_end) = world_heights(k, &s, &street, &mut f.assets); + assert!((at_start - 0.1).abs() < 0.001, "start path height {at_start}"); + assert!((at_end - 0.1).abs() < 0.001, "end path height {at_end}"); +} + +#[test] +fn a_typed_length_and_radius_draw_an_ai_path_straight() { + let mut f = Paths::new("typed"); + let street = f.street.clone(); + f.lane(1, &street, 100.0, 100.0, 0.0, 50.0); + f.type_of(&street); + f.click(100.0, 150.0); + f.editor.typed_text[0] = "5".to_string(); + f.editor.typed_text[1] = "0".to_string(); + let (z0, z1) = f.plan(100.0, 180.0); + assert!((z0 - 0.0).abs() < 1e-9, "z0 {z0}"); + assert!((z1 - z0).abs() < 1e-9, "z1 {z1} follows z0 {z0}"); + let facts = f.editor.road_plan_facts().expect("a plan"); + assert!((facts.0 - 5.0).abs() < 0.001, "length {}", facts.0); + assert!(facts.1.abs() < 1e-9, "radius {}", facts.1); + f.click(100.0, 180.0); + let (k, s) = f.made(&street, 100.0, 150.0).expect("the path is made"); + assert!((s.length - 5.0).abs() < 0.001, "built length {}", s.length); + assert!(s.radius.abs() < 1e-9, "built radius {}", s.radius); + let (at_start, at_end) = world_heights(k, &s, &street, &mut f.assets); + assert!((at_start - 0.1).abs() < 0.001, "start path height {at_start}"); + assert!((at_end - 0.1).abs() < 0.001, "end path height {at_end}"); +} + +#[test] +fn a_typed_rise_lifts_an_ai_path() { + let mut f = Paths::new("rise"); + let street = f.street.clone(); + f.lane(1, &street, 100.0, 100.0, 0.0, 50.0); + f.type_of(&street); + f.click(100.0, 150.0); + f.editor.typed_text[0] = "5".to_string(); + f.editor.typed_text[3] = "2".to_string(); + let (z0, z1) = f.plan(100.0, 180.0); + assert!((z0 - 0.0).abs() < 1e-9, "z0 {z0}"); + assert!((z1 - z0 - 2.0).abs() < 1e-9, "z1 {z1} from z0 {z0}"); + f.click(100.0, 180.0); + let (k, s) = f.made(&street, 100.0, 150.0).expect("the path is made"); + let (_, at_end) = world_heights(k, &s, &street, &mut f.assets); + assert!((at_end - 2.1).abs() < 0.001, "end path height {at_end}"); +} + +#[test] +fn a_typed_road_still_follows_the_ground() { + let mut f = Paths::new("road-typed"); + let street = f.street.clone(); + f.type_of(&street); + f.editor.tool = Tool::Roads; + f.click(200.0, 200.0); + f.editor.typed_text[0] = "5".to_string(); + f.editor.typed_text[3] = "2".to_string(); + let (z0, z1) = f.plan(200.0, 215.0); + assert!((z0 - 0.0).abs() < 1e-9, "z0 {z0}"); + // (a road takes the ground at its end, not the rise typed for a path) + assert!((z1 - 0.0).abs() < 1e-9, "z1 {z1}"); +} diff --git a/src/ui_edit.rs b/src/ui_edit.rs index fa99b90..eae0194 100644 --- a/src/ui_edit.rs +++ b/src/ui_edit.rs @@ -1068,7 +1068,7 @@ pub fn pocket_options(ui: &mut egui::Ui, ed: &mut Editor) { /// Numbers for the road being drawn, in the view's corner: what is typed is kept to, what is /// left empty follows the cursor (its value shown greyed). pub fn road_entry(ctx: &egui::Context, ed: &mut Editor, view: egui::Rect, actions: &mut Vec) { - if !ed.road_start_active() || ed.drawing_paths() || !view.is_positive() { + if !ed.road_start_active() || !view.is_positive() { return; } let facts = ed.road_plan_facts(); From a0eb5a3b607f338d98f7e4019e000e659305824f Mon Sep 17 00:00:00 2001 From: Lobstery_v2 Date: Mon, 16 Nov 2026 17:07:33 +0800 Subject: [PATCH 3/3] Roads: turn one round about its start and reverse it in one step --- locales/be.tsv | 4 +++ locales/ca.tsv | 4 +++ locales/cs.tsv | 4 +++ locales/de.tsv | 4 +++ locales/es.tsv | 4 +++ locales/fr.tsv | 4 +++ locales/hi.tsv | 4 +++ locales/hu.tsv | 4 +++ locales/id.tsv | 4 +++ locales/it.tsv | 4 +++ locales/ja.tsv | 4 +++ locales/kk.tsv | 4 +++ locales/ko.tsv | 4 +++ locales/ms.tsv | 4 +++ locales/nl.tsv | 4 +++ locales/pl.tsv | 4 +++ locales/pt-pt.tsv | 4 +++ locales/pt.tsv | 4 +++ locales/sv.tsv | 4 +++ locales/th.tsv | 4 +++ locales/tl.tsv | 4 +++ locales/tr.tsv | 4 +++ locales/uk.tsv | 4 +++ locales/vi.tsv | 4 +++ locales/zh-tw.tsv | 4 +++ locales/zh.tsv | 4 +++ src/app.rs | 1 + src/controls.rs | 9 ++++- src/editor.rs | 74 ++++++++++++++++++++++++++++++++++---- src/editor/flip_tests.rs | 76 ++++++++++++++++++++++++++++++++++++++++ src/ui.rs | 8 +++++ src/ui_edit.rs | 8 +++++ 32 files changed, 272 insertions(+), 8 deletions(-) create mode 100644 src/editor/flip_tests.rs diff --git a/locales/be.tsv b/locales/be.tsv index 9e3371e..d3fc5b1 100644 --- a/locales/be.tsv +++ b/locales/be.tsv @@ -2964,3 +2964,7 @@ Choose file… Выберыце файл… BUS Аўтобус Hand-picked routes kept: {count} Ручна абраныя маршруты захоўваюцца: {count} Overwrite hand-picked routes Перапішыце ручна абраныя маршруты +Turn round and reverse Развярнуць кругам і змяніць кірунак +Turn the road round and reverse it Развярнуць дарогу кругам і змяніць яе кірунак +Select one road to turn round Выберыце адну дарогу для развароту +One road turned half round about its start and reversed: it lies on the other side of the start, its end on the start, its traffic coming back to it Дарога паварочваецца на паўабарота вакол свайго пачатку і разгортваецца: яна ляжыць з іншага боку пачатку, яе канец — на пачатку, рух ідзе назад да яго diff --git a/locales/ca.tsv b/locales/ca.tsv index 9f0970b..25bd084 100644 --- a/locales/ca.tsv +++ b/locales/ca.tsv @@ -2964,3 +2964,7 @@ Choose file… Elegir el fitxer… BUS BUS Hand-picked routes kept: {count} Rutes seleccionades manualment conservades: {count} Overwrite hand-picked routes Reescriure les rutes seleccionades manualment +Turn round and reverse Girar i invertir el sentit +Turn the road round and reverse it Girar la carretera i invertir-ne el sentit +Select one road to turn round Seleccioneu una carretera per girar +One road turned half round about its start and reversed: it lies on the other side of the start, its end on the start, its traffic coming back to it Una carretera gira mitja volta al voltant del seu inici i s'inverteix: queda a l'altre costat de l'inici, el seu final sobre l'inici i el trànsit torna cap a ell diff --git a/locales/cs.tsv b/locales/cs.tsv index 91ff2ea..057819c 100644 --- a/locales/cs.tsv +++ b/locales/cs.tsv @@ -2964,3 +2964,7 @@ Choose file… Vyber si složku… BUS Autobus Hand-picked routes kept: {count} Ručně vybrané trasy: {count} Overwrite hand-picked routes Přepis ručně vybraných tras +Turn round and reverse Otočit a obrátit směr +Turn the road round and reverse it Otočit cestu a obrátit její směr +Select one road to turn round Vyberte jednu cestu k otočení +One road turned half round about its start and reversed: it lies on the other side of the start, its end on the start, its traffic coming back to it Cesta se otočí o půl otáčky kolem svého začátku a obrátí: leží na druhé straně začátku, její konec na začátku, provoz se k němu vrací diff --git a/locales/de.tsv b/locales/de.tsv index 7789f95..832b01e 100644 --- a/locales/de.tsv +++ b/locales/de.tsv @@ -2962,3 +2962,7 @@ Choose file… Datei auswählen… BUS BUS Hand-picked routes kept: {count} Beibehaltene manuell gewählte Routen: {count} Overwrite hand-picked routes Manuell gewählte Routen überschreiben +Turn round and reverse Umdrehen und Richtung wechseln +Turn the road round and reverse it Die Straße umdrehen und ihre Richtung wechseln +Select one road to turn round Wählen Sie eine Straße zum Umdrehen +One road turned half round about its start and reversed: it lies on the other side of the start, its end on the start, its traffic coming back to it Eine Straße wird um ihren Anfang halb herumgedreht und umgekehrt: Sie liegt auf der anderen Seite des Anfangs, ihr Ende am Anfang, der Verkehr kommt zu ihm zurück diff --git a/locales/es.tsv b/locales/es.tsv index 5e6f983..85f5ca0 100644 --- a/locales/es.tsv +++ b/locales/es.tsv @@ -2964,3 +2964,7 @@ Choose file… Elige el archivo… BUS Autobús Hand-picked routes kept: {count} Rutas seleccionadas manualmente mantenidas: {count} Overwrite hand-picked routes Sobrescribir las rutas seleccionadas manualmente +Turn round and reverse Girar e invertir el sentido +Turn the road round and reverse it Girar la carretera e invertir su sentido +Select one road to turn round Seleccione una carretera para girar +One road turned half round about its start and reversed: it lies on the other side of the start, its end on the start, its traffic coming back to it Una carretera gira media vuelta alrededor de su inicio y se invierte: queda al otro lado del inicio, su final sobre el inicio y el tráfico vuelve hacia él diff --git a/locales/fr.tsv b/locales/fr.tsv index 1990bea..850fadb 100644 --- a/locales/fr.tsv +++ b/locales/fr.tsv @@ -2962,3 +2962,7 @@ Choose file… Choisissez le dossier… BUS Autobus Hand-picked routes kept: {count} Route sélectionnée manuellement: {count} Overwrite hand-picked routes Supprimer les itinéraires sélectionnés manuellement +Turn round and reverse Retourner et inverser le sens +Turn the road round and reverse it Retourner la route et inverser son sens +Select one road to turn round Sélectionnez une route à retourner +One road turned half round about its start and reversed: it lies on the other side of the start, its end on the start, its traffic coming back to it Une route est tournée d'un demi-tour autour de son début puis inversée : elle se trouve de l'autre côté du début, sa fin sur le début, la circulation revenant vers lui diff --git a/locales/hi.tsv b/locales/hi.tsv index 6c909a6..c36bd25 100644 --- a/locales/hi.tsv +++ b/locales/hi.tsv @@ -2964,3 +2964,7 @@ Choose file… फ़ाइल चुनें… BUS बस Hand-picked routes kept: {count} मैन्युअल रूप से चुने गए मार्ग बनाए रखे जाते हैंः: {count} Overwrite hand-picked routes मैन्युअल रूप से चयनित मार्गों को ओवरराइट करें +Turn round and reverse पलटें और दिशा उलटें +Turn the road round and reverse it सड़क को पलटें और उसकी दिशा उलटें +Select one road to turn round पलटने के लिए एक सड़क चुनें +One road turned half round about its start and reversed: it lies on the other side of the start, its end on the start, its traffic coming back to it एक सड़क अपने आरंभ के चारों ओर आधा घूमकर उलट दी जाती है: वह आरंभ के दूसरी ओर होती है, उसका अंत आरंभ पर, यातायात उसकी ओर वापस आता है diff --git a/locales/hu.tsv b/locales/hu.tsv index 76ef4c0..b79e35f 100644 --- a/locales/hu.tsv +++ b/locales/hu.tsv @@ -2964,3 +2964,7 @@ Choose file… Válassza ki a fájlt… BUS BUS Hand-picked routes kept: {count} Kézilag kiválasztott útvonalak: {count} Overwrite hand-picked routes Kézilag kiválasztott útvonalak átírása +Turn round and reverse Fordítsd meg és fordítsd vissza az irányt +Turn the road round and reverse it Fordítsd meg az utat és az irányát +Select one road to turn round Válassz egy utat a megfordításhoz +One road turned half round about its start and reversed: it lies on the other side of the start, its end on the start, its traffic coming back to it Az út fél fordulattal elfordul a kezdete körül, majd megfordul: a kezdet másik oldalán fekszik, a vége a kezdeten, a forgalom visszafelé halad rajta diff --git a/locales/id.tsv b/locales/id.tsv index 4c483b8..94c4ffc 100644 --- a/locales/id.tsv +++ b/locales/id.tsv @@ -2964,3 +2964,7 @@ Choose file… Pilih file… BUS BUS Hand-picked routes kept: {count} Lalu lintas yang dipilih secara manual disimpan: {count} Overwrite hand-picked routes Menulis ulang rute yang dipilih secara manual +Turn round and reverse Putar balik dan balik arah +Turn the road round and reverse it Putar balik jalan dan balik arahnya +Select one road to turn round Pilih satu jalan untuk diputar balik +One road turned half round about its start and reversed: it lies on the other side of the start, its end on the start, its traffic coming back to it Satu jalan diputar setengah putaran mengelilingi awalnya lalu dibalik: jalan berada di sisi lain awal, ujungnya di awal, lalu lintas kembali ke arahnya diff --git a/locales/it.tsv b/locales/it.tsv index 73000c6..adb81d8 100644 --- a/locales/it.tsv +++ b/locales/it.tsv @@ -2964,3 +2964,7 @@ Choose file… Scegliete il file… BUS Autobus Hand-picked routes kept: {count} rotte selezionate manualmente conservate: {count} Overwrite hand-picked routes Soprascrivere le rotte selezionate manualmente +Turn round and reverse Gira e inverti il senso +Turn the road round and reverse it Gira la strada e inverti il senso +Select one road to turn round Seleziona una strada da girare +One road turned half round about its start and reversed: it lies on the other side of the start, its end on the start, its traffic coming back to it Una strada viene ruotata di mezzo giro attorno al suo inizio e invertita: si trova dall'altra parte dell'inizio, la sua fine sull'inizio, il traffico torna verso di esso diff --git a/locales/ja.tsv b/locales/ja.tsv index b268255..96d3423 100644 --- a/locales/ja.tsv +++ b/locales/ja.tsv @@ -2964,3 +2964,7 @@ Choose file… ファイルを選択… BUS バス Hand-picked routes kept: {count} 保持した手動選択経路:{count} 件 Overwrite hand-picked routes 手動で選択した経路を上書き +Turn round and reverse 反転して向きを変える +Turn the road round and reverse it 道路を反転して向きを変える +Select one road to turn round 向きを変える道路を1本選んでください +One road turned half round about its start and reversed: it lies on the other side of the start, its end on the start, its traffic coming back to it 道路を始点を中心に半回転させてから反転します。道路は始点の反対側にあり、終点は始点の上、進行方向は始点へ向きます diff --git a/locales/kk.tsv b/locales/kk.tsv index d78720c..daf6bb4 100644 --- a/locales/kk.tsv +++ b/locales/kk.tsv @@ -2964,3 +2964,7 @@ Choose file… Файлды таңдаңыз… BUS Автобус Hand-picked routes kept: {count} Қолмен таңдалған бағыттар: {count} Overwrite hand-picked routes Қолмен таңдалған бағыттарды қайта жазу +Turn round and reverse Айналдырып, бағытын өзгерту +Turn the road round and reverse it Жолды айналдырып, бағытын өзгерту +Select one road to turn round Айналдыратын бір жолды таңдаңыз +One road turned half round about its start and reversed: it lies on the other side of the start, its end on the start, its traffic coming back to it Жол өзінің басынан жарты айналым бұрылып, кейін кері айналады: ол бастың екінші жағында жатыр, соңы баста, қозғалыс оған қарай жүреді diff --git a/locales/ko.tsv b/locales/ko.tsv index 0e35827..2968ea5 100644 --- a/locales/ko.tsv +++ b/locales/ko.tsv @@ -2964,3 +2964,7 @@ Choose file… 파일 선택… BUS 버스 Hand-picked routes kept: {count} 수동으로 선택된 경로: {count} Overwrite hand-picked routes 수동으로 선택된 경로를 덮어쓰기 +Turn round and reverse 돌려서 방향 바꾸기 +Turn the road round and reverse it 도로를 돌려서 방향 바꾸기 +Select one road to turn round 돌릴 도로 하나를 선택하세요 +One road turned half round about its start and reversed: it lies on the other side of the start, its end on the start, its traffic coming back to it 도로를 시작점을 중심으로 반 바퀴 돌린 뒤 방향을 바꿉니다. 도로는 시작점 반대편에 놓이고 끝점은 시작점 위에 있으며 진행 방향은 시작점을 향합니다 diff --git a/locales/ms.tsv b/locales/ms.tsv index d9fb5c8..f61f9da 100644 --- a/locales/ms.tsv +++ b/locales/ms.tsv @@ -2964,3 +2964,7 @@ Choose file… Pilih fail… BUS BUS Hand-picked routes kept: {count} Laluan yang dipilih secara manual disimpan: {count} Overwrite hand-picked routes Menulis ulang laluan yang dipilih secara manual +Turn round and reverse Putar balik dan songsang arah +Turn the road round and reverse it Putar balik jalan dan songsang arahnya +Select one road to turn round Pilih satu jalan untuk diputar balik +One road turned half round about its start and reversed: it lies on the other side of the start, its end on the start, its traffic coming back to it Satu jalan diputar separuh pusingan mengelilingi permulaannya lalu disongsangkan: jalan terletak di sisi lain permulaan, hujungnya di permulaan, trafik kembali ke arahnya diff --git a/locales/nl.tsv b/locales/nl.tsv index 7205a85..8a00c47 100644 --- a/locales/nl.tsv +++ b/locales/nl.tsv @@ -2965,3 +2965,7 @@ Choose file… Kies het bestand… BUS BUS Hand-picked routes kept: {count} Handmatig geselecteerde routes: {count} Overwrite hand-picked routes Handmatig geselecteerde routes overschrijven +Turn round and reverse Omkeren en richting omdraaien +Turn the road round and reverse it De weg omkeren en de richting omdraaien +Select one road to turn round Kies één weg om om te keren +One road turned half round about its start and reversed: it lies on the other side of the start, its end on the start, its traffic coming back to it Een weg wordt een halve slag om zijn begin gedraaid en omgekeerd: hij ligt aan de andere kant van het begin, zijn einde op het begin, het verkeer komt er terug naartoe diff --git a/locales/pl.tsv b/locales/pl.tsv index 0695b98..4316f71 100644 --- a/locales/pl.tsv +++ b/locales/pl.tsv @@ -2964,3 +2964,7 @@ Choose file… Wybierz plik… BUS BUS Hand-picked routes kept: {count} Wykrywane ręcznie trasy: {count} Overwrite hand-picked routes Przepisanie ręcznie wybranych tras +Turn round and reverse Obróć i odwróć kierunek +Turn the road round and reverse it Obróć drogę i odwróć jej kierunek +Select one road to turn round Wybierz jedną drogę do obrócenia +One road turned half round about its start and reversed: it lies on the other side of the start, its end on the start, its traffic coming back to it Droga zostaje obrócona o pół obrotu wokół swojego początku i odwrócona: leży po drugiej stronie początku, jej koniec na początku, ruch wraca do niego diff --git a/locales/pt-pt.tsv b/locales/pt-pt.tsv index bc5ce1b..a8aa728 100644 --- a/locales/pt-pt.tsv +++ b/locales/pt-pt.tsv @@ -2964,3 +2964,7 @@ Choose file… Escolha o arquivo… BUS BUS Hand-picked routes kept: {count} rotas manuais selecionadas: {count} Overwrite hand-picked routes Reescrever rotas selecionadas manualmente +Turn round and reverse Rodar e inverter o sentido +Turn the road round and reverse it Rodar a estrada e inverter o sentido +Select one road to turn round Selecione uma estrada para rodar +One road turned half round about its start and reversed: it lies on the other side of the start, its end on the start, its traffic coming back to it Uma estrada é rodada meia volta em torno do seu início e invertida: fica do outro lado do início, o seu fim sobre o início, o trânsito a voltar para ele diff --git a/locales/pt.tsv b/locales/pt.tsv index a9d3750..ae469ab 100644 --- a/locales/pt.tsv +++ b/locales/pt.tsv @@ -2964,3 +2964,7 @@ Choose file… Escolha o arquivo… BUS BUS Hand-picked routes kept: {count} rotas manuais selecionadas: {count} Overwrite hand-picked routes Reescrever rotas selecionadas manualmente +Turn round and reverse Rodar e inverter o sentido +Turn the road round and reverse it Rodar a estrada e inverter o sentido +Select one road to turn round Selecione uma estrada para rodar +One road turned half round about its start and reversed: it lies on the other side of the start, its end on the start, its traffic coming back to it Uma estrada é rodada meia volta em torno de seu início e invertida: fica do outro lado do início, seu fim sobre o início, o trânsito voltando para ele diff --git a/locales/sv.tsv b/locales/sv.tsv index 2fc7712..e759d38 100644 --- a/locales/sv.tsv +++ b/locales/sv.tsv @@ -2964,3 +2964,7 @@ Choose file… Välj filen… BUS BUS Hand-picked routes kept: {count} Manuellt utvalda vägar som hålls: {count} Overwrite hand-picked routes Överskriva manuellt utvalda rutter +Turn round and reverse Vänd och byt riktning +Turn the road round and reverse it Vänd vägen och byt riktning +Select one road to turn round Välj en väg att vända +One road turned half round about its start and reversed: it lies on the other side of the start, its end on the start, its traffic coming back to it En väg vrids ett halvt varv kring sin början och vänds: den ligger på andra sidan början, dess slut på början, trafiken kommer tillbaka till den diff --git a/locales/th.tsv b/locales/th.tsv index d176cd5..18586df 100644 --- a/locales/th.tsv +++ b/locales/th.tsv @@ -2964,3 +2964,7 @@ Choose file… เลือกไฟล์… BUS รถโดยสาร Hand-picked routes kept: {count} เส้นทางที่ได้รับการเลือกด้วยมือ: {count} Overwrite hand-picked routes กรอกเส้นทางที่เลือกด้วยมือ +Turn round and reverse หมุนกลับและกลับทิศทาง +Turn the road round and reverse it หมุนถนนกลับและกลับทิศทาง +Select one road to turn round เลือกถนนหนึ่งเส้นเพื่อหมุนกลับ +One road turned half round about its start and reversed: it lies on the other side of the start, its end on the start, its traffic coming back to it ถนนจะหมุนครึ่งรอบรอบจุดเริ่มต้นแล้วกลับทิศทาง: ถนนอยู่คนละด้านของจุดเริ่มต้น ปลายอยู่ที่จุดเริ่มต้น การจราจรวิ่งกลับมาที่จุดเริ่มต้น diff --git a/locales/tl.tsv b/locales/tl.tsv index 54fd31e..040de30 100644 --- a/locales/tl.tsv +++ b/locales/tl.tsv @@ -2964,3 +2964,7 @@ Choose file… Pumili ng file… BUS BUS Hand-picked routes kept: {count} Ang mga itinuturing na manu-manually selected routes: {count} Overwrite hand-picked routes I-overwrite ang mga manually selected na ruta +Turn round and reverse Ikot at baliktarin +Turn the road round and reverse it Ikutin ang kalsada at baliktarin ang direksyon +Select one road to turn round Pumili ng isang kalsada na ikukot +One road turned half round about its start and reversed: it lies on the other side of the start, its end on the start, its traffic coming back to it Ang isang kalsada ay iikot nang kalahating ikot sa paligid ng simula nito at babaliktarin: ito ay nasa kabilang panig ng simula, ang dulo nito ay nasa simula, bumabalik ang trapiko patungo rito diff --git a/locales/tr.tsv b/locales/tr.tsv index 3af09f7..dd5401b 100644 --- a/locales/tr.tsv +++ b/locales/tr.tsv @@ -2964,3 +2964,7 @@ Choose file… Dosyayı seç… BUS BUS Hand-picked routes kept: {count} Elle seçilen yollar: {count} Overwrite hand-picked routes Elle seçilen yolları yazma +Turn round and reverse Yana döndür ve yönünü tersine çevir +Turn the road round and reverse it Yolu yana döndür ve yönünü tersine çevir +Select one road to turn round Döndürülecek bir yol seçin +One road turned half round about its start and reversed: it lies on the other side of the start, its end on the start, its traffic coming back to it Bir yol başlangıcı etrafında yarım tur döndürülüp ters çevrilir: başlangıcın diğer tarafında durur, sonu başlangıçta, trafik ona geri gelir diff --git a/locales/uk.tsv b/locales/uk.tsv index 14748d5..9222d19 100644 --- a/locales/uk.tsv +++ b/locales/uk.tsv @@ -2962,3 +2962,7 @@ Choose file… Виберіть файл… BUS Автобус Hand-picked routes kept: {count} Ручно обрані маршрути: {count} Overwrite hand-picked routes Перезаписати ручно обрані маршрути +Turn round and reverse Розвернути кругом і змінити напрям +Turn the road round and reverse it Розвернути дорогу кругом і змінити її напрям +Select one road to turn round Виберіть одну дорогу для розвороту +One road turned half round about its start and reversed: it lies on the other side of the start, its end on the start, its traffic coming back to it Дорога повертається на півоберта навколо свого початку й розвертається: вона лежить з іншого боку початку, її кінець — на початку, рух іде назад до нього diff --git a/locales/vi.tsv b/locales/vi.tsv index 291fef1..16e45cb 100644 --- a/locales/vi.tsv +++ b/locales/vi.tsv @@ -2964,3 +2964,7 @@ Choose file… Chọn tập tin… BUS BUS Hand-picked routes kept: {count} Các tuyến đường được lựa chọn bằng tay: {count} Overwrite hand-picked routes Viết lại các tuyến đường được chọn bằng tay +Turn round and reverse Xoay vòng và đảo chiều +Turn the road round and reverse it Xoay đường và đảo chiều +Select one road to turn round Chọn một con đường để xoay vòng +One road turned half round about its start and reversed: it lies on the other side of the start, its end on the start, its traffic coming back to it Một con đường được xoay nửa vòng quanh điểm đầu rồi đảo chiều: nó nằm ở phía bên kia điểm đầu, điểm cuối nằm trên điểm đầu, giao thông quay lại về phía đó diff --git a/locales/zh-tw.tsv b/locales/zh-tw.tsv index 4b623b7..32de2e1 100644 --- a/locales/zh-tw.tsv +++ b/locales/zh-tw.tsv @@ -2963,3 +2963,7 @@ Some characters in the road name cannot be used. File: {file} 道路名稱含有 Another road already uses this file: {file} 這個檔案已由另一條道路使用:{file} Hand-picked routes kept: {count} 已保留手動選取的路徑:{count} 條 Overwrite hand-picked routes 覆蓋手動選取的路徑 +Turn round and reverse 轉向並反轉 +Turn the road round and reverse it 將道路轉向並反轉 +Select one road to turn round 請選取一條要轉向的道路 +One road turned half round about its start and reversed: it lies on the other side of the start, its end on the start, its traffic coming back to it 一條道路以其起點為中心轉半圈再反轉:道路位於起點另一側,終點落在起點上,行進方向朝向起點 diff --git a/locales/zh.tsv b/locales/zh.tsv index 94c3765..5c6d602 100644 --- a/locales/zh.tsv +++ b/locales/zh.tsv @@ -2960,3 +2960,7 @@ Choose file… 选择文件… BUS 公交 Hand-picked routes kept: {count} 已保留手动选择的路径:{count} 条 Overwrite hand-picked routes 覆盖手动选择的路径 +Turn round and reverse 转向并反转 +Turn the road round and reverse it 将道路转向并反转 +Select one road to turn round 请选择一条要转向的道路 +One road turned half round about its start and reversed: it lies on the other side of the start, its end on the start, its traffic coming back to it 一条道路以其起点为中心转半圈再反转:道路位于起点另一侧,终点落在起点上,行进方向朝向起点 diff --git a/src/app.rs b/src/app.rs index c35b5c0..5b6319c 100644 --- a/src/app.rs +++ b/src/app.rs @@ -2393,6 +2393,7 @@ impl App { self.ed.rot_begin(self.mouse.pos); } } + Cmd::FlipPath => self.ed.flip_selected(), Cmd::Ruler => self.ed.toggle_ruler(), Cmd::Knife => self.ed.toggle_cutting(), Cmd::CompleteTo => self.ed.complete_to(), diff --git a/src/controls.rs b/src/controls.rs index 75d7a29..64e7ec5 100644 --- a/src/controls.rs +++ b/src/controls.rs @@ -151,6 +151,8 @@ impl Preset { // (Enter confirms; the road is built on Ctrl+Enter the same way) (Preset::Omsi, Confirm) => Some(Chord::key(KeyCode::Enter)), (Preset::Omsi, BuildRoad) => Some(Chord::ctrl(KeyCode::Enter)), + // (a new command, on no key in any set until one is chosen) + (_, Cmd::FlipPath) => None, _ => Some(c.default()), } } @@ -183,6 +185,7 @@ pub enum Cmd { ToolTiles, NewObject, Rotate, + FlipPath, XformMove, XformRotate, XformScale, @@ -217,7 +220,7 @@ use Cmd::*; pub const ALL: &[Cmd] = &[ Forward, Back, Left, Right, TurnLeft, TurnRight, LookDown, View2d, Focus, TileGrid, Overview, Assets, Lines, Traffic, Imagery, ToolSelect, ToolRoads, ToolObjects, ToolLogic, - ToolTerrain, ToolPaint, ToolTiles, NewObject, XformMove, XformRotate, XformScale, EditMesh, JoinObjects, Rotate, Ruler, Knife, CompleteTo, BuildRoad, Confirm, BrushSmaller, BrushLarger, Delete, Group, Ungroup, Copy, Cut, Paste, Duplicate, SelectAll, Undo, + ToolTerrain, ToolPaint, ToolTiles, NewObject, FlipPath, XformMove, XformRotate, XformScale, EditMesh, JoinObjects, Rotate, Ruler, Knife, CompleteTo, BuildRoad, Confirm, BrushSmaller, BrushLarger, Delete, Group, Ungroup, Copy, Cut, Paste, Duplicate, SelectAll, Undo, Redo, Save, Find, Commands, TestDrive, Picture, Polygon, PolygonClick, ]; @@ -250,6 +253,7 @@ impl Cmd { ToolTiles => "tool_tiles", NewObject => "new_object", Rotate => "rotate", + FlipPath => "flip_path", XformMove => "gizmo_move", XformRotate => "gizmo_rotate", XformScale => "gizmo_scale", @@ -308,6 +312,7 @@ impl Cmd { ToolTiles => tr("Tool: Tiles", "Инструмент: Тайлы"), NewObject => tr("Place a new object at the cursor", "Поставить новый объект у курсора"), Rotate => tr("Turn the object (Shift: the other way)", "Повернуть объект (Shift: в другую сторону)"), + FlipPath => tr("Turn the road round and reverse it", "Развернуть дорогу кругом и обратить"), Ruler => tr("Ruler", "Линейка"), Knife => tr("Knife", "Нож"), CompleteTo => tr("Complete to: a new piece between the free ends of the selected splines", "Достроить до: новый кусок между свободными концами выбранных сплайнов"), @@ -366,6 +371,8 @@ impl Cmd { ToolTiles => Chord::key(KeyCode::Digit7), NewObject => Chord::key(KeyCode::KeyN), Rotate => Chord::key(KeyCode::KeyR), + // (on no key until one is put on it in the settings) + FlipPath => Chord::key(KeyCode::F24), XformMove => Chord::key(KeyCode::KeyV), XformRotate => Chord::key(KeyCode::KeyC), XformScale => Chord::key(KeyCode::KeyX), diff --git a/src/editor.rs b/src/editor.rs index 1fd2b52..67276db 100644 --- a/src/editor.rs +++ b/src/editor.rs @@ -8380,13 +8380,7 @@ impl Editor { if splines.is_empty() { return; } - // (a row of objects is measured along its spline from the start: it would move) - let with_rows = splines.iter().any(|(k, id)| { - let Some(t) = doc.tiles.get(k) else { return false }; - let idx = t.tile.splines.iter().position(|s| s.id == *id && !s.deleted); - idx.map(|i| t.tile.spline_attachments.iter().any(|a| a.spline_index == i as i32)).unwrap_or(false) - }); - if with_rows { + if splines_with_rows(doc, &splines) { self.error(tr("Remove the rows of objects along it first (they are measured from its start)", "Сначала уберите ряды объектов вдоль неё (они отмеряются от её начала)")); return; } @@ -8413,6 +8407,60 @@ impl Editor { self.history.commit(); } + /// The one selected road turned half round about its start and then reversed: it lies + /// on the other side of the start, its end on the start, its traffic coming back to it. + /// One step: Ctrl+Z puts it back as it was. Not with a row of objects along it. + pub fn flip_selected(&mut self) { + let sels = self.selection(); + let (k, id) = match sels.as_slice() { + [Sel::Spline(k, id)] => (*k, *id), + _ => { + self.toast(tr("Select one road to turn round", "Выберите одну дорогу для разворота")); + return; + } + }; + let Some(doc) = self.doc.as_mut() else { return }; + if splines_with_rows(doc, &[(k, id)]) { + self.error(tr("Remove the rows of objects along it first (they are measured from its start)", "Сначала уберите ряды объектов вдоль неё (они отмеряются от её начала)")); + return; + } + let Some(sp) = doc.spline(k, id).cloned() else { return }; + let org = tile_origin(k); + let before = omsi_geometry::SplineCurve::from_map(&sp, org); + let (b0, b1) = (before.point_at(0.0), before.end_point()); + let bh = before.heading_at(sp.length); + let Some(pivot) = road_start(doc, &sels).map(|p| p.truncate()) else { return }; + let from: Vec = sels.iter().filter_map(|s| selection::origin_of(doc, *s)).collect(); + if from.is_empty() { + return; + } + self.history.begin(tr("Turn round and reverse", "Развернуть кругом и обратить")); + let now = selection::transform(doc, &mut self.history, &from, pivot, 180.0, DVec2::ZERO); + selection::unlink_outside(doc, &mut self.history, &now); + self.history.touch_tile(doc, k); + { + let org = tile_origin(k); + let t = doc.tiles.get_mut(&k).unwrap(); + if let Some(s) = t.tile.splines.iter_mut().find(|s| s.id == id && !s.deleted) { + // (its textures start again where it now starts, as a reversal keeps them) + *s = reshape::reversed(s, org, 0.0); + t.touch_content(); + } + } + self.set_selection_unique(now); + self.finish_step(); + if let Some(s) = self.doc.as_ref().and_then(|d| d.spline(k, id)) { + let after = omsi_geometry::SplineCurve::from_map(s, org); + let (a0, a1) = (after.point_at(0.0), after.end_point()); + let ah = after.heading_at(s.length); + log::info!( + "road {id} turned round: start ({:.3}, {:.3}, {:.3}) end ({:.3}, {:.3}, {:.3}) heading {:.3} -> start ({:.3}, {:.3}, {:.3}) end ({:.3}, {:.3}, {:.3}) heading {:.3}", + b0.x, b0.y, b0.z, b1.x, b1.y, b1.z, bh, + a0.x, a0.y, a0.z, a1.x, a1.y, a1.z, ah + ); + } + } + /// The knife on or off (K); on, the Select tool takes over and the ruler goes. pub fn toggle_cutting(&mut self) { let on = !self.cutting; @@ -11178,6 +11226,16 @@ fn cover_z(doc: &Document, assets: &mut Assets, hide_roads: bool, p: DVec2) -> f best } +/// Whether a row of objects is measured along any of these splines from its start (a +/// reversal or a turn would move it). +fn splines_with_rows(doc: &Document, splines: &[(TileKey, i64)]) -> bool { + splines.iter().any(|(k, id)| { + let Some(t) = doc.tiles.get(k) else { return false }; + let idx = t.tile.splines.iter().position(|s| s.id == *id && !s.deleted); + idx.map(|i| t.tile.spline_attachments.iter().any(|a| a.spline_index == i as i32)).unwrap_or(false) + }) +} + fn road_profile(pieces: &[Seg], z0: f64, z1: f64, at: &mut dyn FnMut(DVec2) -> f64, limit_slope: bool) -> Vec<(f64, f64)> { let mut nodes = vec![0.0]; let mut where_at = vec![pieces.first().map(|p| p.start).unwrap_or(DVec2::ZERO)]; @@ -17164,5 +17222,7 @@ mod bus_lane_tests; #[cfg(test)] mod path_snap_tests; +#[cfg(test)] +mod flip_tests; mod bus_rule_batch; diff --git a/src/editor/flip_tests.rs b/src/editor/flip_tests.rs new file mode 100644 index 0000000..b11c6fa --- /dev/null +++ b/src/editor/flip_tests.rs @@ -0,0 +1,76 @@ +use super::*; +use crate::selection::tests::{add_spline, flat_map}; + +/// A road's start, end and heading as the map has them. +fn shape(doc: &Document, k: TileKey, id: i64) -> (DVec3, DVec3, f64) { + let s = doc.spline(k, id).expect("the road"); + let c = omsi_geometry::SplineCurve::from_map(s, tile_origin(k)); + (c.point_at(0.0), c.end_point(), c.heading_at(s.length)) +} + +fn editor_with(id: i64, heading: f64) -> Editor { + let mut doc = flat_map(1); + add_spline(&mut doc, (0, 0), id, 100.0, 100.0, heading, 5.0, 0, 0); + let mut ed = Editor::default(); + ed.open(doc); + ed.set_selection(vec![Sel::Spline((0, 0), id)]); + ed +} + +#[test] +fn one_road_turns_round_about_its_start() { + let mut ed = editor_with(1, 30.0); + ed.flip_selected(); + let doc = ed.doc.as_ref().unwrap(); + let (start, end, heading) = shape(doc, (0, 0), 1); + let p = DVec2::new(100.0, 100.0); + assert!((end.truncate() - p).length() < 0.001, "end {:?}", end.truncate()); + assert!((heading - 30.0).abs() < 1e-6, "heading {heading}"); + let wanted = p - roads::dir(30.0) * 5.0; + assert!((start.truncate() - wanted).length() < 0.001, "start {:?}, wanted {wanted:?}", start.truncate()); +} + +#[test] +fn angle_snapping_does_not_stop_the_half_turn() { + let mut ed = editor_with(1, 37.0); + ed.snap_angle = true; + ed.flip_selected(); + let doc = ed.doc.as_ref().unwrap(); + let (start, end, heading) = shape(doc, (0, 0), 1); + let p = DVec2::new(100.0, 100.0); + assert!((end.truncate() - p).length() < 0.001, "end {:?}", end.truncate()); + assert!((heading - 37.0).abs() < 1e-6, "heading {heading}"); + let wanted = p - roads::dir(37.0) * 5.0; + assert!((start.truncate() - wanted).length() < 0.001, "start {:?}, wanted {wanted:?}", start.truncate()); +} + +#[test] +fn one_undo_puts_the_road_back() { + let mut ed = editor_with(1, 30.0); + let before = shape(ed.doc.as_ref().unwrap(), (0, 0), 1); + ed.flip_selected(); + ed.history.undo(ed.doc.as_mut().unwrap()); + let after = shape(ed.doc.as_ref().unwrap(), (0, 0), 1); + assert!((after.0 - before.0).length() < 1e-9, "start {:?} from {:?}", after.0, before.0); + assert!((after.1 - before.1).length() < 1e-9, "end {:?} from {:?}", after.1, before.1); + assert!((after.2 - before.2).abs() < 1e-9, "heading {} from {}", after.2, before.2); +} + +#[test] +fn two_roads_are_left_alone() { + let mut doc = flat_map(1); + add_spline(&mut doc, (0, 0), 1, 100.0, 100.0, 30.0, 5.0, 0, 0); + add_spline(&mut doc, (0, 0), 2, 200.0, 100.0, 60.0, 5.0, 0, 0); + let mut ed = Editor::default(); + ed.open(doc); + ed.set_selection(vec![Sel::Spline((0, 0), 1), Sel::Spline((0, 0), 2)]); + let before = (shape(ed.doc.as_ref().unwrap(), (0, 0), 1), shape(ed.doc.as_ref().unwrap(), (0, 0), 2)); + ed.flip_selected(); + let after = (shape(ed.doc.as_ref().unwrap(), (0, 0), 1), shape(ed.doc.as_ref().unwrap(), (0, 0), 2)); + for (a, b) in [(after.0, before.0), (after.1, before.1)] { + assert!((a.0 - b.0).length() < 1e-12, "start {:?} from {:?}", a.0, b.0); + assert!((a.1 - b.1).length() < 1e-12, "end {:?} from {:?}", a.1, b.1); + assert!((a.2 - b.2).abs() < 1e-12, "heading {} from {}", a.2, b.2); + } + assert_eq!(ed.selection(), vec![Sel::Spline((0, 0), 1), Sel::Spline((0, 0), 2)]); +} diff --git a/src/ui.rs b/src/ui.rs index d878c2d..697c480 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -2345,6 +2345,7 @@ fn properties(ui: &mut egui::Ui, st: &mut UiState, ed: &mut Editor, lib: &Librar let mut knife = false; let mut join_next = false; let mut reverse = false; + let mut flip = false; let mut lay = false; let mut align_road = false; let mut lean = false; @@ -2739,6 +2740,9 @@ fn properties(ui: &mut egui::Ui, st: &mut UiState, ed: &mut Editor, lib: &Librar if ui.small_button(tr("Reverse direction", "Развернуть направление")).on_hover_text(crate::ui_edit::reverse_help()).clicked() { reverse = true; } + if ui.small_button(tr("Turn round and reverse", "Развернуть кругом и обратить")).on_hover_text(crate::ui_edit::flip_help()).clicked() { + flip = true; + } if s.prev_id != 0 || s.next_id != 0 { if ui.small_button(tr("Select the whole road", "Выбрать всю дорогу")).on_hover_text(tr("Every piece linked on from this one (or double-click the road)", "Все куски, связанные с этим (или двойной клик по дороге)")).clicked() { whole_road = true; @@ -3048,6 +3052,10 @@ fn properties(ui: &mut egui::Ui, st: &mut UiState, ed: &mut Editor, lib: &Librar ed.reverse_selected(); return; } + if flip { + ed.flip_selected(); + return; + } if lay { ed.lay_selected_on_ground(); return; diff --git a/src/ui_edit.rs b/src/ui_edit.rs index eae0194..68989bc 100644 --- a/src/ui_edit.rs +++ b/src/ui_edit.rs @@ -468,6 +468,9 @@ pub fn group_properties(ui: &mut egui::Ui, ed: &mut Editor, lib: &Library, paren if ui.button(tr("Reverse their direction", "Развернуть их направление")).on_hover_text(reverse_help()).clicked() { ed.reverse_selected(); } + if ui.button(tr("Turn round and reverse", "Развернуть кругом и обратить")).on_hover_text(flip_help()).clicked() { + ed.flip_selected(); + } if ui.button(icons::labelled(Icon::Route, tr("Complete to", "Достроить до"))).on_hover_text(crate::complete::help()).clicked() { ed.complete_to(); } @@ -777,6 +780,11 @@ pub(crate) fn reverse_help() -> &'static str { tr("Each starts where it ended: the traffic on it goes the other way (a one-way street, a track's direction), the road itself stays where it is", "Каждый начинается там, где кончался: движение по нему идёт в обратную сторону (улица с односторонним движением, направление пути), сама дорога остаётся на месте") } +/// What "Turn round and reverse" does to one road. +pub(crate) fn flip_help() -> &'static str { + tr("One road turned half round about its start and reversed: it lies on the other side of the start, its end on the start, its traffic coming back to it", "Одна дорога повёрнута на пол-оборота вокруг своего начала и развёрнута: она лежит по другую сторону начала, её конец — на начале, движение идёт обратно к нему") +} + /// A copy of the selected road(s) or track(s) alongside, at a distance. pub fn parallel_section(ui: &mut egui::Ui, ed: &mut Editor, lib: &Library) { let sels = ed.selection();