mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-27 00:12:55 +03:00
track when map edits are dirty
This commit is contained in:
parent
b192bda583
commit
abf14e1fac
@ -143,6 +143,7 @@ fn launch_test(test: &ABTest, ui: &mut UI, ctx: &mut EventCtx) -> ABTestMode {
|
||||
ctx,
|
||||
MapEdits::load(&test.map_name, &test.edits1_name, &mut timer),
|
||||
);
|
||||
ui.primary.map.mark_edits_fresh();
|
||||
ui.primary
|
||||
.map
|
||||
.recalculate_pathfinding_after_edits(&mut timer);
|
||||
@ -194,6 +195,7 @@ fn launch_test(test: &ABTest, ui: &mut UI, ctx: &mut EventCtx) -> ABTestMode {
|
||||
ctx,
|
||||
MapEdits::load(&test.map_name, &test.edits2_name, &mut timer),
|
||||
);
|
||||
secondary.map.mark_edits_fresh();
|
||||
secondary
|
||||
.map
|
||||
.recalculate_pathfinding_after_edits(&mut timer);
|
||||
|
@ -64,6 +64,9 @@ impl State for EditMode {
|
||||
{
|
||||
let mut txt = Text::new();
|
||||
txt.add(Line(format!("Edits: {}", orig_edits.edits_name)));
|
||||
if orig_edits.dirty {
|
||||
txt.append(Line("*"));
|
||||
}
|
||||
txt.add(Line(format!("{} lanes", orig_edits.lane_overrides.len())));
|
||||
txt.add(Line(format!(
|
||||
"{} stop signs ",
|
||||
@ -98,8 +101,7 @@ impl State for EditMode {
|
||||
return Transition::KeepWithMode(EventLoopMode::ScreenCaptureCurrentShot);
|
||||
}
|
||||
|
||||
// TODO Only if current edits are unsaved
|
||||
if self.menu.action("save edits") {
|
||||
if orig_edits.dirty && self.menu.action("save edits") {
|
||||
return Transition::Push(WizardState::new(Box::new(save_edits)));
|
||||
} else if self.menu.action("load different edits") {
|
||||
return Transition::Push(WizardState::new(Box::new(load_edits)));
|
||||
@ -328,7 +330,7 @@ fn save_edits(wiz: &mut Wizard, ctx: &mut EventCtx, ui: &mut UI) -> Option<Trans
|
||||
edits.edits_name = name;
|
||||
map.apply_edits(edits, &mut Timer::new("name map edits"));
|
||||
}
|
||||
map.get_edits().save();
|
||||
map.save_edits();
|
||||
}
|
||||
Some(Transition::Pop)
|
||||
}
|
||||
@ -345,6 +347,7 @@ fn load_edits(wiz: &mut Wizard, ctx: &mut EventCtx, ui: &mut UI) -> Option<Trans
|
||||
list
|
||||
})?;
|
||||
apply_map_edits(&mut ui.primary, &ui.cs, ctx, new_edits);
|
||||
ui.primary.map.mark_edits_fresh();
|
||||
Some(Transition::Pop)
|
||||
}
|
||||
|
||||
@ -437,8 +440,9 @@ pub fn apply_map_edits(
|
||||
bundle: &mut PerMapUI,
|
||||
cs: &ColorScheme,
|
||||
ctx: &mut EventCtx,
|
||||
edits: MapEdits,
|
||||
mut edits: MapEdits,
|
||||
) {
|
||||
edits.dirty = true;
|
||||
let mut timer = Timer::new("apply map edits");
|
||||
|
||||
let (lanes_changed, roads_changed, turns_deleted, turns_added) =
|
||||
|
@ -99,10 +99,13 @@ impl State for SandboxMode {
|
||||
txt.add(Line(format!("{} active (+{} buses)", active, buses)));
|
||||
txt.add(Line(format!("{} unfinished", unfinished)));
|
||||
txt.add(Line(""));
|
||||
txt.add(Line(format!(
|
||||
"Edits: {}",
|
||||
ui.primary.map.get_edits().edits_name
|
||||
)));
|
||||
{
|
||||
let edits = ui.primary.map.get_edits();
|
||||
txt.add(Line(format!("Edits: {}", edits.edits_name)));
|
||||
if edits.dirty {
|
||||
txt.append(Line("*"));
|
||||
}
|
||||
}
|
||||
self.menu.set_info(ctx, txt);
|
||||
}
|
||||
self.menu.event(ctx);
|
||||
@ -141,7 +144,8 @@ impl State for SandboxMode {
|
||||
}
|
||||
|
||||
if self.general_tools.action("back to title screen") {
|
||||
// TODO Clear edits?
|
||||
// TODO Clear edits? Warn about unsaved?
|
||||
ui.primary.clear_sim();
|
||||
return Transition::Pop;
|
||||
}
|
||||
if self.general_tools.action("debug mode") {
|
||||
|
@ -14,6 +14,9 @@ pub struct MapEdits {
|
||||
// TODO Storing the entire thing is maybe a bit dramatic, but works for now.
|
||||
pub stop_sign_overrides: BTreeMap<IntersectionID, ControlStopSign>,
|
||||
pub traffic_signal_overrides: BTreeMap<IntersectionID, ControlTrafficSignal>,
|
||||
|
||||
#[serde(skip_serializing, skip_deserializing)]
|
||||
pub dirty: bool,
|
||||
}
|
||||
|
||||
impl MapEdits {
|
||||
@ -26,6 +29,7 @@ impl MapEdits {
|
||||
contraflow_lanes: BTreeMap::new(),
|
||||
stop_sign_overrides: BTreeMap::new(),
|
||||
traffic_signal_overrides: BTreeMap::new(),
|
||||
dirty: false,
|
||||
}
|
||||
}
|
||||
|
||||
@ -40,7 +44,10 @@ impl MapEdits {
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
pub fn save(&self) {
|
||||
// TODO Version these
|
||||
pub(crate) fn save(&mut self) {
|
||||
assert!(self.dirty);
|
||||
abstutil::save_json_object(abstutil::EDITS, &self.map_name, &self.edits_name, self);
|
||||
self.dirty = false;
|
||||
}
|
||||
}
|
||||
|
@ -623,6 +623,15 @@ impl Map {
|
||||
&self.edits
|
||||
}
|
||||
|
||||
pub fn mark_edits_fresh(&mut self) {
|
||||
assert!(self.edits.dirty);
|
||||
self.edits.dirty = false;
|
||||
}
|
||||
|
||||
pub fn save_edits(&mut self) {
|
||||
self.edits.save();
|
||||
}
|
||||
|
||||
// new_edits assumed to be valid. Returns actual lanes that changed, roads changed, turns
|
||||
// deleted, turns added. Doesn't update pathfinding yet.
|
||||
pub fn apply_edits(
|
||||
|
@ -73,6 +73,7 @@ impl SimFlags {
|
||||
MapEdits::load(map.get_name(), &sim.edits_name, timer),
|
||||
timer,
|
||||
);
|
||||
map.mark_edits_fresh();
|
||||
map.recalculate_pathfinding_after_edits(timer);
|
||||
|
||||
(map, sim, rng)
|
||||
|
Loading…
Reference in New Issue
Block a user