From c7fbaaf7e1c02e6bbd9a591a1bc3477c5bd576d2 Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Tue, 19 Nov 2019 11:47:40 -0800 Subject: [PATCH] reset edits when leaving sandbox mode --- game/src/sandbox/mod.rs | 19 +++++++++++++++++++ map_model/src/edits.rs | 4 ++++ 2 files changed, 23 insertions(+) diff --git a/game/src/sandbox/mod.rs b/game/src/sandbox/mod.rs index ac170f4599..823b13babc 100644 --- a/game/src/sandbox/mod.rs +++ b/game/src/sandbox/mod.rs @@ -5,16 +5,19 @@ mod score; use crate::common::{time_controls, AgentTools, CommonState, SpeedControls}; use crate::debug::DebugMode; +use crate::edit::apply_map_edits; use crate::edit::EditMode; use crate::game::{msg, State, Transition, WizardState}; use crate::helpers::ID; use crate::ui::{ShowEverything, UI}; +use abstutil::Timer; use ezgui::{ hotkey, layout, lctrl, Choice, EventCtx, EventLoopMode, GfxCtx, Key, Line, MenuUnderButton, ModalMenu, Text, Wizard, }; pub use gameplay::GameplayMode; use geom::Duration; +use map_model::MapEdits; use sim::Sim; pub struct SandboxMode { @@ -163,13 +166,29 @@ impl State for SandboxMode { choices }, )?; + let map_name = ui.primary.map.get_name().to_string(); match resp.as_str() { "save edits and quit" => { 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(); Some(Transition::PopTwice) } "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(); Some(Transition::PopTwice) } diff --git a/map_model/src/edits.rs b/map_model/src/edits.rs index bcbb015570..689ab1c378 100644 --- a/map_model/src/edits.rs +++ b/map_model/src/edits.rs @@ -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 { if edits_name == "no_edits" { return MapEdits::new(map_name.to_string());