diff --git a/game/src/edit/bulk.rs b/game/src/edit/bulk.rs index c6d8ee6f66..c86ed9d626 100644 --- a/game/src/edit/bulk.rs +++ b/game/src/edit/bulk.rs @@ -7,7 +7,7 @@ use ezgui::{ Outcome, TextExt, VerticalAlignment, Widget, }; use geom::Speed; -use map_model::{EditCmd, LaneType, RoadID}; +use map_model::{LaneType, RoadID}; use std::collections::BTreeSet; pub struct BulkSelect { @@ -172,10 +172,11 @@ 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 { - 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 }); + edits + .commands + .push(app.primary.map.edit_road_cmd(*r, |new| { + new.speed_limit = speed; + })); } apply_map_edits(ctx, app, edits); return Transition::Keep; diff --git a/game/src/edit/lanes.rs b/game/src/edit/lanes.rs index db49df4828..3cf88f6232 100644 --- a/game/src/edit/lanes.rs +++ b/game/src/edit/lanes.rs @@ -13,7 +13,7 @@ use ezgui::{ hotkey, Btn, Color, Composite, EventCtx, GfxCtx, HorizontalAlignment, Key, Outcome, RewriteColor, TextExt, VerticalAlignment, Widget, }; -use map_model::{EditCmd, LaneID, LaneType}; +use map_model::{LaneID, LaneType}; pub struct LaneEditor { l: LaneID, @@ -179,12 +179,13 @@ impl State for LaneEditor { } }, Outcome::Changed => { - 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::ChangeRoad { r, new, old }); + edits.commands.push(app.primary.map.edit_road_cmd( + app.primary.map.get_l(self.l).parent, + |new| { + new.speed_limit = self.composite.dropdown_value("speed limit"); + }, + )); apply_map_edits(ctx, app, edits); return Transition::Replace(LaneEditor::new(ctx, app, self.l, self.mode.clone())); } diff --git a/game/src/edit/validate.rs b/game/src/edit/validate.rs index 0496631eb3..cd99e0bb10 100644 --- a/game/src/edit/validate.rs +++ b/game/src/edit/validate.rs @@ -124,10 +124,9 @@ pub fn try_change_lt( let mut edits = orig_edits.clone(); 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 } + map.edit_road_cmd(r, |new| { + new.lanes_ltr[map.get_r(r).offset(l)].0 = new_lt; + }) }; edits.commands.push(cmd.clone()); map.try_apply_edits(edits, &mut Timer::throwaway()); @@ -174,10 +173,9 @@ pub fn try_reverse(ctx: &mut EventCtx, map: &Map, l: LaneID) -> Result(&self, r: RoadID, f: F) -> EditCmd { + let old = self.get_r_edit(r); + let mut new = old.clone(); + f(&mut new); + EditCmd::ChangeRoad { r, old, new } + } + // Panics on borders pub fn get_i_edit(&self, i: IntersectionID) -> EditIntersection { match self.get_i(i).intersection_type {