From 2c8aa62f97a21f5aebb4cb151ed583226aa65f89 Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Thu, 4 Oct 2018 11:13:57 -0700 Subject: [PATCH] describe map edits in GUI --- editor/src/plugins/map_edits.rs | 43 +++++++++++++++++++++------------ map_model/src/edits.rs | 4 +++ sim/src/edits.rs | 10 ++++++++ 3 files changed, 41 insertions(+), 16 deletions(-) diff --git a/editor/src/plugins/map_edits.rs b/editor/src/plugins/map_edits.rs index 3ac738d596..437e98fd0e 100644 --- a/editor/src/plugins/map_edits.rs +++ b/editor/src/plugins/map_edits.rs @@ -94,16 +94,40 @@ fn manage_edits( } else { vec![save_existing, load] }; - match wizard.choose_string("Manage map edits", choices)?.as_str() { + + // Slow to create this every tick just to get the description? It's actually frozen once the + // wizard is started... + let edits = MapEdits { + edits_name: current_flags.edits_name.to_string(), + map_name: map.get_name().to_string(), + road_edits: road_editor.get_edits().clone(), + stop_signs: control_map.get_changed_stop_signs(), + traffic_signals: control_map.get_changed_traffic_signals(), + }; + + match wizard + .choose_string(&format!("Manage {}", edits.describe()), choices)? + .as_str() + { x if x == save_new => { let name = wizard.input_string("Name the map edits")?; - save(&name, map, control_map, road_editor); + abstutil::write_json( + &format!("../data/edits/{}/{}.json", map.get_name(), name), + &edits, + ).expect("Saving map edits failed"); // No need to reload everything current_flags.edits_name = name; Some(()) } x if x == save_existing => { - save(¤t_flags.edits_name, map, control_map, road_editor); + abstutil::write_json( + &format!( + "../data/edits/{}/{}.json", + map.get_name(), + ¤t_flags.edits_name + ), + &edits, + ).expect("Saving map edits failed"); Some(()) } x if x == load => { @@ -119,16 +143,3 @@ fn manage_edits( _ => unreachable!(), } } - -fn save(edits_name: &str, map: &Map, control_map: &ControlMap, road_editor: &RoadEditor) { - abstutil::write_json( - &format!("../data/edits/{}/{}.json", map.get_name(), edits_name), - &MapEdits { - edits_name: edits_name.to_string(), - map_name: map.get_name().to_string(), - road_edits: road_editor.get_edits().clone(), - stop_signs: control_map.get_changed_stop_signs(), - traffic_signals: control_map.get_changed_traffic_signals(), - }, - ).expect("Saving map edits failed"); -} diff --git a/map_model/src/edits.rs b/map_model/src/edits.rs index 2d17287b3a..e5ad44334e 100644 --- a/map_model/src/edits.rs +++ b/map_model/src/edits.rs @@ -37,6 +37,10 @@ impl RoadEdits { } false } + + pub fn len(&self) -> usize { + self.roads.len() + } } #[derive(Serialize, Deserialize, Debug, Clone, Copy)] diff --git a/sim/src/edits.rs b/sim/src/edits.rs index efa81c638a..272ce28e1c 100644 --- a/sim/src/edits.rs +++ b/sim/src/edits.rs @@ -22,4 +22,14 @@ impl MapEdits { traffic_signals: BTreeMap::new(), } } + + pub fn describe(&self) -> String { + format!( + "map edits \"{}\" ({} roads, {} stop signs, {} traffic signals", + self.edits_name, + self.road_edits.len(), + self.stop_signs.len(), + self.traffic_signals.len() + ) + } }