mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-25 07:25:47 +03:00
Refactor a helper to produce EditCmd::ChangeRoad. Looked at doing the
same for ChangeIntersection, but not sure it's worth it.
This commit is contained in:
parent
e283b8944a
commit
57b5791f1f
@ -7,7 +7,7 @@ use ezgui::{
|
|||||||
Outcome, TextExt, VerticalAlignment, Widget,
|
Outcome, TextExt, VerticalAlignment, Widget,
|
||||||
};
|
};
|
||||||
use geom::Speed;
|
use geom::Speed;
|
||||||
use map_model::{EditCmd, LaneType, RoadID};
|
use map_model::{LaneType, RoadID};
|
||||||
use std::collections::BTreeSet;
|
use std::collections::BTreeSet;
|
||||||
|
|
||||||
pub struct BulkSelect {
|
pub struct BulkSelect {
|
||||||
@ -172,10 +172,11 @@ impl State for BulkEdit {
|
|||||||
let speed = self.composite.dropdown_value("speed limit");
|
let speed = self.composite.dropdown_value("speed limit");
|
||||||
let mut edits = app.primary.map.get_edits().clone();
|
let mut edits = app.primary.map.get_edits().clone();
|
||||||
for r in &self.roads {
|
for r in &self.roads {
|
||||||
let old = app.primary.map.get_r_edit(*r);
|
edits
|
||||||
let mut new = old.clone();
|
.commands
|
||||||
new.speed_limit = speed;
|
.push(app.primary.map.edit_road_cmd(*r, |new| {
|
||||||
edits.commands.push(EditCmd::ChangeRoad { r: *r, old, new });
|
new.speed_limit = speed;
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
apply_map_edits(ctx, app, edits);
|
apply_map_edits(ctx, app, edits);
|
||||||
return Transition::Keep;
|
return Transition::Keep;
|
||||||
|
@ -13,7 +13,7 @@ use ezgui::{
|
|||||||
hotkey, Btn, Color, Composite, EventCtx, GfxCtx, HorizontalAlignment, Key, Outcome,
|
hotkey, Btn, Color, Composite, EventCtx, GfxCtx, HorizontalAlignment, Key, Outcome,
|
||||||
RewriteColor, TextExt, VerticalAlignment, Widget,
|
RewriteColor, TextExt, VerticalAlignment, Widget,
|
||||||
};
|
};
|
||||||
use map_model::{EditCmd, LaneID, LaneType};
|
use map_model::{LaneID, LaneType};
|
||||||
|
|
||||||
pub struct LaneEditor {
|
pub struct LaneEditor {
|
||||||
l: LaneID,
|
l: LaneID,
|
||||||
@ -179,12 +179,13 @@ impl State for LaneEditor {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
Outcome::Changed => {
|
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();
|
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);
|
apply_map_edits(ctx, app, edits);
|
||||||
return Transition::Replace(LaneEditor::new(ctx, app, self.l, self.mode.clone()));
|
return Transition::Replace(LaneEditor::new(ctx, app, self.l, self.mode.clone()));
|
||||||
}
|
}
|
||||||
|
@ -124,10 +124,9 @@ pub fn try_change_lt(
|
|||||||
let mut edits = orig_edits.clone();
|
let mut edits = orig_edits.clone();
|
||||||
let cmd = {
|
let cmd = {
|
||||||
let r = map.get_l(l).parent;
|
let r = map.get_l(l).parent;
|
||||||
let old = map.get_r_edit(r);
|
map.edit_road_cmd(r, |new| {
|
||||||
let mut new = old.clone();
|
new.lanes_ltr[map.get_r(r).offset(l)].0 = new_lt;
|
||||||
new.lanes_ltr[map.get_r(r).offset(l)].0 = new_lt;
|
})
|
||||||
EditCmd::ChangeRoad { r, old, new }
|
|
||||||
};
|
};
|
||||||
edits.commands.push(cmd.clone());
|
edits.commands.push(cmd.clone());
|
||||||
map.try_apply_edits(edits, &mut Timer::throwaway());
|
map.try_apply_edits(edits, &mut Timer::throwaway());
|
||||||
@ -174,10 +173,9 @@ pub fn try_reverse(ctx: &mut EventCtx, map: &Map, l: LaneID) -> Result<EditCmd,
|
|||||||
// there aren't weird side effects elsewhere of doing this.
|
// there aren't weird side effects elsewhere of doing this.
|
||||||
if (idx != 0 && lanes[idx - 1].1 != dir) || (idx != lanes.len() - 1 && lanes[idx + 1].1 != dir)
|
if (idx != 0 && lanes[idx - 1].1 != dir) || (idx != lanes.len() - 1 && lanes[idx + 1].1 != dir)
|
||||||
{
|
{
|
||||||
let old = map.get_r_edit(r.id);
|
Ok(map.edit_road_cmd(r.id, |new| {
|
||||||
let mut new = old.clone();
|
new.lanes_ltr[idx].1 = dir.opposite();
|
||||||
new.lanes_ltr[idx].1 = dir.opposite();
|
}))
|
||||||
Ok(EditCmd::ChangeRoad { r: r.id, old, new })
|
|
||||||
} else {
|
} else {
|
||||||
Err(PopupMsg::new(
|
Err(PopupMsg::new(
|
||||||
ctx,
|
ctx,
|
||||||
|
@ -10,7 +10,7 @@ use ezgui::{
|
|||||||
hotkey, Btn, Color, Composite, Drawable, EventCtx, GfxCtx, HorizontalAlignment, Key, Line,
|
hotkey, Btn, Color, Composite, Drawable, EventCtx, GfxCtx, HorizontalAlignment, Key, Line,
|
||||||
Outcome, Spinner, Text, TextExt, VerticalAlignment, Widget,
|
Outcome, Spinner, Text, TextExt, VerticalAlignment, Widget,
|
||||||
};
|
};
|
||||||
use map_model::{AccessRestrictions, EditCmd, PathConstraints, RoadID};
|
use map_model::{AccessRestrictions, PathConstraints, RoadID};
|
||||||
use maplit::btreeset;
|
use maplit::btreeset;
|
||||||
use sim::TripMode;
|
use sim::TripMode;
|
||||||
use std::collections::BTreeSet;
|
use std::collections::BTreeSet;
|
||||||
@ -88,10 +88,11 @@ impl State for ZoneEditor {
|
|||||||
|
|
||||||
// Roads deleted from the zone
|
// Roads deleted from the zone
|
||||||
for r in self.orig_members.difference(&self.selector.roads) {
|
for r in self.orig_members.difference(&self.selector.roads) {
|
||||||
let old = app.primary.map.get_r_edit(*r);
|
edits
|
||||||
let mut new = old.clone();
|
.commands
|
||||||
new.access_restrictions = AccessRestrictions::new();
|
.push(app.primary.map.edit_road_cmd(*r, |new| {
|
||||||
edits.commands.push(EditCmd::ChangeRoad { r: *r, old, new });
|
new.access_restrictions = AccessRestrictions::new();
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut allow_through_traffic = self
|
let mut allow_through_traffic = self
|
||||||
@ -117,10 +118,11 @@ impl State for ZoneEditor {
|
|||||||
let old_access_restrictions =
|
let old_access_restrictions =
|
||||||
app.primary.map.get_r(*r).access_restrictions.clone();
|
app.primary.map.get_r(*r).access_restrictions.clone();
|
||||||
if old_access_restrictions != new_access_restrictions {
|
if old_access_restrictions != new_access_restrictions {
|
||||||
let old = app.primary.map.get_r_edit(*r);
|
edits
|
||||||
let mut new = old.clone();
|
.commands
|
||||||
new.access_restrictions = new_access_restrictions.clone();
|
.push(app.primary.map.edit_road_cmd(*r, |new| {
|
||||||
edits.commands.push(EditCmd::ChangeRoad { r: *r, old, new });
|
new.access_restrictions = new_access_restrictions.clone();
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -410,6 +410,13 @@ impl Map {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn edit_road_cmd<F: Fn(&mut EditRoad)>(&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
|
// Panics on borders
|
||||||
pub fn get_i_edit(&self, i: IntersectionID) -> EditIntersection {
|
pub fn get_i_edit(&self, i: IntersectionID) -> EditIntersection {
|
||||||
match self.get_i(i).intersection_type {
|
match self.get_i(i).intersection_type {
|
||||||
|
Loading…
Reference in New Issue
Block a user