include option for no_edits in menus and make sure we revert things when

loading no_edits
This commit is contained in:
Dustin Carlino 2019-03-20 18:01:02 -07:00
parent 5f297163db
commit b0035cde08
3 changed files with 19 additions and 10 deletions

View File

@ -68,6 +68,8 @@ fn manage_edits(ctx: &mut PluginCtx, raw_wizard: &mut Wizard) -> Option<()> {
x if x == load => {
let edits = load_edits(&ctx.primary.map, &mut wizard, "Load which map edits?")?;
apply_map_edits(ctx, edits);
// Argue why it's safe to not reset PluginsPerMap. In short -- there shouldn't be any
// interesting state there if the EditsManager plugin is active.
Some(())
}
_ => unreachable!(),

View File

@ -124,13 +124,16 @@ pub fn choose_scenario(map: &Map, wizard: &mut WrappedWizard, query: &str) -> Op
.map(|(n, _)| n)
}
// TODO Implicitly need a blank edits entry
pub fn choose_edits(map: &Map, wizard: &mut WrappedWizard, query: &str) -> Option<String> {
let map_name = map.get_name().to_string();
wizard
.choose_something::<String>(
query,
Box::new(move || abstutil::list_all_objects("edits", &map_name)),
Box::new(move || {
let mut list = abstutil::list_all_objects("edits", &map_name);
list.push(("no_edits".to_string(), "no_edits".to_string()));
list
}),
)
.map(|(n, _)| n)
}
@ -140,7 +143,11 @@ pub fn load_edits(map: &Map, wizard: &mut WrappedWizard, query: &str) -> Option<
wizard
.choose_something::<MapEdits>(
query,
Box::new(move || abstutil::load_all_objects("edits", &map_name)),
Box::new(move || {
let mut list = abstutil::load_all_objects("edits", &map_name);
list.push(("no_edits".to_string(), MapEdits::new(map_name.clone())));
list
}),
)
.map(|(_, e)| e)
}

View File

@ -568,13 +568,6 @@ impl Map {
}
}
if all_lane_edits.is_empty() {
timer.note("No edits to actually apply".to_string());
// Except maybe edits_name.
self.edits = new_edits;
return Vec::new();
}
// May need to revert some previous changes
for id in self.edits.lane_overrides.keys() {
if !new_edits.lane_overrides.contains_key(id) {
@ -582,6 +575,13 @@ impl Map {
}
}
if all_lane_edits.is_empty() {
timer.note("No edits to actually apply".to_string());
// Except maybe edits_name.
self.edits = new_edits;
return Vec::new();
}
let mut changed_lanes = Vec::new();
let mut changed_intersections = BTreeSet::new();
for (id, lt) in all_lane_edits {