mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-01 02:33:54 +03:00
describe map edits in GUI
This commit is contained in:
parent
bed2c604f3
commit
2c8aa62f97
@ -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");
|
||||
}
|
||||
|
@ -37,6 +37,10 @@ impl RoadEdits {
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
pub fn len(&self) -> usize {
|
||||
self.roads.len()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Copy)]
|
||||
|
@ -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()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user