mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-29 17:34:58 +03:00
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!
This commit is contained in:
parent
aacb17297d
commit
30bfe93b5c
@ -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;
|
||||
|
@ -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()));
|
||||
}
|
||||
|
@ -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()
|
||||
|
@ -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<EditCmd, Box<dyn State>> {
|
||||
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<EditCmd,
|
||||
// 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)
|
||||
{
|
||||
Ok(EditCmd::ReverseLane {
|
||||
l,
|
||||
dst_i: lane.src_i,
|
||||
})
|
||||
let old = map.get_r_edit(r.id);
|
||||
let mut new = old.clone();
|
||||
new.lanes_ltr[idx].1 = dir.opposite();
|
||||
Ok(EditCmd::ChangeRoad { r: r.id, old, new })
|
||||
} else {
|
||||
Err(PopupMsg::new(
|
||||
ctx,
|
||||
|
@ -88,11 +88,10 @@ impl State for ZoneEditor {
|
||||
|
||||
// Roads deleted from the zone
|
||||
for r in self.orig_members.difference(&self.selector.roads) {
|
||||
edits.commands.push(EditCmd::ChangeAccessRestrictions {
|
||||
id: *r,
|
||||
old: app.primary.map.get_r(*r).access_restrictions.clone(),
|
||||
new: AccessRestrictions::new(),
|
||||
});
|
||||
let old = app.primary.map.get_r_edit(*r);
|
||||
let mut new = old.clone();
|
||||
new.access_restrictions = AccessRestrictions::new();
|
||||
edits.commands.push(EditCmd::ChangeRoad { r: *r, old, new });
|
||||
}
|
||||
|
||||
let mut allow_through_traffic = self
|
||||
@ -103,7 +102,7 @@ impl State for ZoneEditor {
|
||||
// The original allow_through_traffic always includes this, and there's no way
|
||||
// to exclude it, so stay consistent.
|
||||
allow_through_traffic.insert(PathConstraints::Train);
|
||||
let new = AccessRestrictions {
|
||||
let new_access_restrictions = AccessRestrictions {
|
||||
allow_through_traffic,
|
||||
cap_vehicles_per_hour: {
|
||||
let n = self.composite.spinner("cap_vehicles") as usize;
|
||||
@ -115,13 +114,13 @@ impl State for ZoneEditor {
|
||||
},
|
||||
};
|
||||
for r in &self.selector.roads {
|
||||
let old = app.primary.map.get_r(*r).access_restrictions.clone();
|
||||
if old != new {
|
||||
edits.commands.push(EditCmd::ChangeAccessRestrictions {
|
||||
id: *r,
|
||||
old,
|
||||
new: new.clone(),
|
||||
});
|
||||
let old_access_restrictions =
|
||||
app.primary.map.get_r(*r).access_restrictions.clone();
|
||||
if old_access_restrictions != new_access_restrictions {
|
||||
let old = app.primary.map.get_r_edit(*r);
|
||||
let mut new = old.clone();
|
||||
new.access_restrictions = new_access_restrictions.clone();
|
||||
edits.commands.push(EditCmd::ChangeRoad { r: *r, old, new });
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -251,6 +251,7 @@ impl Static {
|
||||
"{} access restrictions changed",
|
||||
edits.changed_access_restrictions.len()
|
||||
)),
|
||||
Line(format!("{} roads changed", edits.original_roads.len())),
|
||||
Line(format!(
|
||||
"{} intersections changed",
|
||||
edits.original_intersections.len()
|
||||
|
@ -45,9 +45,9 @@ pub enum EditIntersection {
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct EditRoad {
|
||||
lanes_ltr: Vec<(LaneType, Direction)>,
|
||||
speed_limit: Speed,
|
||||
access_restrictions: AccessRestrictions,
|
||||
pub lanes_ltr: Vec<(LaneType, Direction)>,
|
||||
pub speed_limit: Speed,
|
||||
pub access_restrictions: AccessRestrictions,
|
||||
}
|
||||
|
||||
impl EditRoad {
|
||||
|
Loading…
Reference in New Issue
Block a user