Skip to content

Commit

Permalink
Recalculate mode shift when map is edited #448
Browse files Browse the repository at this point in the history
  • Loading branch information
dabreegster committed Sep 27, 2021
1 parent e8018c9 commit 70a0965
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
3 changes: 2 additions & 1 deletion game/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,8 @@ pub struct SessionState {
// Specific to the ungap tool
pub elevation_contours: Cached<MapName, (FindClosest<Distance>, Drawable)>,
pub routing_params: RoutingParams,
pub mode_shift: Cached<MapName, crate::ungap::ModeShiftData>,
// Map and edit change key
pub mode_shift: Cached<(MapName, usize), crate::ungap::ModeShiftData>,
}

impl SessionState {
Expand Down
11 changes: 5 additions & 6 deletions game/src/ungap/predict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ impl TakeLayers for ShowGaps {
impl ShowGaps {
pub fn new_state(ctx: &mut EventCtx, app: &mut App, layers: Layers) -> Box<dyn State<App>> {
let map_name = app.primary.map.get_name().clone();
if app.session.mode_shift.key().as_ref() == Some(&map_name) {
// TODO If the map's been edited, recalculate_gaps

let change_key = app.primary.map.get_edits_change_key();
if app.session.mode_shift.key().as_ref() == Some(&(map_name.clone(), change_key)) {
return Box::new(ShowGaps {
top_panel: make_top_panel(ctx, app),
layers,
Expand All @@ -46,19 +45,19 @@ impl ShowGaps {
// entirely?
app.session
.mode_shift
.set(map_name, ModeShiftData::empty(ctx));
.set((map_name, change_key), ModeShiftData::empty(ctx));
ShowGaps::new_state(ctx, app, layers)
} else {
FileLoader::<App, Scenario>::new_state(
ctx,
abstio::path_scenario(&map_name, &scenario_name),
Box::new(|ctx, app, _, maybe_scenario| {
Box::new(move |ctx, app, _, maybe_scenario| {
// TODO Handle corrupt files
let scenario = maybe_scenario.unwrap();
let data = ctx.loading_screen("predict mode shift", |ctx, timer| {
ModeShiftData::from_scenario(ctx, app, scenario, timer)
});
app.session.mode_shift.set(map_name, data);
app.session.mode_shift.set((map_name, change_key), data);
Transition::Replace(ShowGaps::new_state(ctx, app, layers))
}),
)
Expand Down

0 comments on commit 70a0965

Please sign in to comment.