reset edits when leaving sandbox mode

This commit is contained in:
Dustin Carlino 2019-11-19 11:47:40 -08:00
parent c0fea0811f
commit c7fbaaf7e1
2 changed files with 23 additions and 0 deletions

View File

@ -5,16 +5,19 @@ mod score;
use crate::common::{time_controls, AgentTools, CommonState, SpeedControls}; use crate::common::{time_controls, AgentTools, CommonState, SpeedControls};
use crate::debug::DebugMode; use crate::debug::DebugMode;
use crate::edit::apply_map_edits;
use crate::edit::EditMode; use crate::edit::EditMode;
use crate::game::{msg, State, Transition, WizardState}; use crate::game::{msg, State, Transition, WizardState};
use crate::helpers::ID; use crate::helpers::ID;
use crate::ui::{ShowEverything, UI}; use crate::ui::{ShowEverything, UI};
use abstutil::Timer;
use ezgui::{ use ezgui::{
hotkey, layout, lctrl, Choice, EventCtx, EventLoopMode, GfxCtx, Key, Line, MenuUnderButton, hotkey, layout, lctrl, Choice, EventCtx, EventLoopMode, GfxCtx, Key, Line, MenuUnderButton,
ModalMenu, Text, Wizard, ModalMenu, Text, Wizard,
}; };
pub use gameplay::GameplayMode; pub use gameplay::GameplayMode;
use geom::Duration; use geom::Duration;
use map_model::MapEdits;
use sim::Sim; use sim::Sim;
pub struct SandboxMode { pub struct SandboxMode {
@ -163,13 +166,29 @@ impl State for SandboxMode {
choices choices
}, },
)?; )?;
let map_name = ui.primary.map.get_name().to_string();
match resp.as_str() { match resp.as_str() {
"save edits and quit" => { "save edits and quit" => {
ui.primary.map.save_edits(); ui.primary.map.save_edits();
// Always reset edits if we just saved edits.
apply_map_edits(&mut ui.primary, &ui.cs, ctx, MapEdits::new(map_name));
ui.primary.map.mark_edits_fresh();
ui.primary
.map
.recalculate_pathfinding_after_edits(&mut Timer::new("reset edits"));
ui.primary.clear_sim(); ui.primary.clear_sim();
Some(Transition::PopTwice) Some(Transition::PopTwice)
} }
"quit challenge" => { "quit challenge" => {
if !ui.primary.map.get_edits().is_empty() {
apply_map_edits(&mut ui.primary, &ui.cs, ctx, MapEdits::new(map_name));
ui.primary.map.mark_edits_fresh();
ui.primary
.map
.recalculate_pathfinding_after_edits(&mut Timer::new(
"reset edits",
));
}
ui.primary.clear_sim(); ui.primary.clear_sim();
Some(Transition::PopTwice) Some(Transition::PopTwice)
} }

View File

@ -65,6 +65,10 @@ impl MapEdits {
} }
} }
pub fn is_empty(&self) -> bool {
self.edits_name == "no_edits" && self.commands.is_empty()
}
pub fn load(map_name: &str, edits_name: &str, timer: &mut Timer) -> MapEdits { pub fn load(map_name: &str, edits_name: &str, timer: &mut Timer) -> MapEdits {
if edits_name == "no_edits" { if edits_name == "no_edits" {
return MapEdits::new(map_name.to_string()); return MapEdits::new(map_name.to_string());