From 30bfe93b5c532a53705420d945e694b0c3761761 Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Wed, 26 Aug 2020 16:59:25 -0700 Subject: [PATCH] Produce the new EditCmd::ChangeRoad in the UI. Tested the scenario that caused #113 (change lane types, reverse some lane, save edits, load from scratch) -- now it works! --- game/src/edit/bulk.rs | 9 ++++----- game/src/edit/lanes.rs | 13 +++++-------- game/src/edit/mod.rs | 1 + game/src/edit/validate.rs | 21 +++++++++++---------- game/src/edit/zones.rs | 25 ++++++++++++------------- game/src/layer/map.rs | 1 + map_model/src/edits/mod.rs | 6 +++--- 7 files changed, 37 insertions(+), 39 deletions(-) diff --git a/game/src/edit/bulk.rs b/game/src/edit/bulk.rs index 37c8806c9c..c6d8ee6f66 100644 --- a/game/src/edit/bulk.rs +++ b/game/src/edit/bulk.rs @@ -172,11 +172,10 @@ impl State for BulkEdit { let speed = self.composite.dropdown_value("speed limit"); let mut edits = app.primary.map.get_edits().clone(); for r in &self.roads { - edits.commands.push(EditCmd::ChangeSpeedLimit { - id: *r, - new: speed, - old: app.primary.map.get_r(*r).speed_limit, - }); + let old = app.primary.map.get_r_edit(*r); + let mut new = old.clone(); + new.speed_limit = speed; + edits.commands.push(EditCmd::ChangeRoad { r: *r, old, new }); } apply_map_edits(ctx, app, edits); return Transition::Keep; diff --git a/game/src/edit/lanes.rs b/game/src/edit/lanes.rs index 5ef7c20e7a..0848cc57ea 100644 --- a/game/src/edit/lanes.rs +++ b/game/src/edit/lanes.rs @@ -198,15 +198,12 @@ impl State for LaneEditor { } }, Outcome::Changed => { - let parent = app.primary.map.get_parent(self.l); - let new = self.composite.dropdown_value("speed limit"); - let old = parent.speed_limit; + let r = app.primary.map.get_l(self.l).parent; + let old = app.primary.map.get_r_edit(r); + let mut new = old.clone(); + new.speed_limit = self.composite.dropdown_value("speed limit"); let mut edits = app.primary.map.get_edits().clone(); - edits.commands.push(EditCmd::ChangeSpeedLimit { - id: parent.id, - new, - old, - }); + edits.commands.push(EditCmd::ChangeRoad { r, new, old }); apply_map_edits(ctx, app, edits); return Transition::Replace(LaneEditor::new(ctx, app, self.l, self.mode.clone())); } diff --git a/game/src/edit/mod.rs b/game/src/edit/mod.rs index 85b3cb1376..5a14473060 100644 --- a/game/src/edit/mod.rs +++ b/game/src/edit/mod.rs @@ -722,6 +722,7 @@ fn make_changelist(ctx: &mut EventCtx, app: &App) -> Composite { "{} access restrictions changed", edits.changed_access_restrictions.len() )), + Line(format!("{} roads changed", edits.original_roads.len())), Line(format!( "{} intersections changed", edits.original_intersections.len() diff --git a/game/src/edit/validate.rs b/game/src/edit/validate.rs index 7d1e499d8b..0496631eb3 100644 --- a/game/src/edit/validate.rs +++ b/game/src/edit/validate.rs @@ -122,10 +122,12 @@ pub fn try_change_lt( let orig_edits = map.get_edits().clone(); let mut edits = orig_edits.clone(); - let cmd = EditCmd::ChangeLaneType { - id: l, - lt: new_lt, - orig_lt: map.get_l(l).lane_type, + let cmd = { + let r = map.get_l(l).parent; + let old = map.get_r_edit(r); + let mut new = old.clone(); + new.lanes_ltr[map.get_r(r).offset(l)].0 = new_lt; + EditCmd::ChangeRoad { r, old, new } }; edits.commands.push(cmd.clone()); map.try_apply_edits(edits, &mut Timer::throwaway()); @@ -164,8 +166,7 @@ pub fn try_change_lt( } pub fn try_reverse(ctx: &mut EventCtx, map: &Map, l: LaneID) -> Result> { - let lane = map.get_l(l); - let r = map.get_r(lane.parent); + let r = map.get_parent(l); let lanes = r.lanes_ltr(); let idx = r.offset(l); let dir = lanes[idx].1; @@ -173,10 +174,10 @@ pub fn try_reverse(ctx: &mut EventCtx, map: &Map, l: LaneID) -> Result, - speed_limit: Speed, - access_restrictions: AccessRestrictions, + pub lanes_ltr: Vec<(LaneType, Direction)>, + pub speed_limit: Speed, + pub access_restrictions: AccessRestrictions, } impl EditRoad {