describe map edits in GUI

This commit is contained in:
Dustin Carlino 2018-10-04 11:13:57 -07:00
parent bed2c604f3
commit 2c8aa62f97
3 changed files with 41 additions and 16 deletions

View File

@ -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(&current_flags.edits_name, map, control_map, road_editor);
abstutil::write_json(
&format!(
"../data/edits/{}/{}.json",
map.get_name(),
&current_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");
}

View File

@ -37,6 +37,10 @@ impl RoadEdits {
}
false
}
pub fn len(&self) -> usize {
self.roads.len()
}
}
#[derive(Serialize, Deserialize, Debug, Clone, Copy)]

View File

@ -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()
)
}
}