mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-24 23:15:24 +03:00
add a new lane type for road closures
This commit is contained in:
parent
d757b45bff
commit
a5892daedb
@ -103,7 +103,7 @@ impl CommonState {
|
||||
ID::Lane(l) => {
|
||||
osd.append_all(vec![
|
||||
Line(l.to_string()).fg(id_color),
|
||||
Line(" is "),
|
||||
Line(format!(" is {} of ", map.get_l(l).lane_type.describe())),
|
||||
Line(map.get_parent(l).get_name()).fg(name_color),
|
||||
]);
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ use crate::game::{State, Transition};
|
||||
use crate::helpers::ID;
|
||||
use crate::ui::UI;
|
||||
use ezgui::{hotkey, Color, EventCtx, GfxCtx, Key, Line, ModalMenu, Text};
|
||||
use map_model::{LaneID, LaneType, Map};
|
||||
use map_model::{LaneID, Map};
|
||||
use petgraph::graphmap::DiGraphMap;
|
||||
use std::collections::HashSet;
|
||||
|
||||
@ -17,8 +17,7 @@ impl Floodfiller {
|
||||
let map = &ui.primary.map;
|
||||
let (reachable_lanes, is_sidewalk, title) =
|
||||
if let Some(ID::Lane(l)) = ui.primary.current_selection {
|
||||
if !map.get_l(l).is_parking()
|
||||
&& map.get_l(l).lane_type != LaneType::SharedLeftTurn
|
||||
if map.get_l(l).lane_type.supports_any_movement()
|
||||
&& ctx
|
||||
.input
|
||||
.contextual_action(Key::F, "floodfill from this lane")
|
||||
@ -65,7 +64,7 @@ impl Floodfiller {
|
||||
);
|
||||
let mut num_unreachable = 0;
|
||||
for lane in map.all_lanes() {
|
||||
if lane.is_parking() || lane.lane_type == LaneType::SharedLeftTurn {
|
||||
if !lane.lane_type.supports_any_movement() {
|
||||
continue;
|
||||
}
|
||||
if is_sidewalk != lane.is_sidewalk() {
|
||||
|
@ -140,16 +140,17 @@ impl State for EditMode {
|
||||
if lane.lane_type != LaneType::Sidewalk
|
||||
&& lane.lane_type != LaneType::SharedLeftTurn
|
||||
{
|
||||
for (lt, name, key) in &[
|
||||
(LaneType::Driving, "driving", Key::D),
|
||||
(LaneType::Parking, "parking", Key::P),
|
||||
(LaneType::Biking, "biking", Key::B),
|
||||
(LaneType::Bus, "bus", Key::T),
|
||||
for (lt, key) in &[
|
||||
(LaneType::Driving, Key::D),
|
||||
(LaneType::Parking, Key::P),
|
||||
(LaneType::Biking, Key::B),
|
||||
(LaneType::Bus, Key::T),
|
||||
(LaneType::Construction, Key::C),
|
||||
] {
|
||||
if can_change_lane_type(road, lane, *lt, &ui.primary.map)
|
||||
&& ctx
|
||||
.input
|
||||
.contextual_action(*key, format!("change to {} lane", name))
|
||||
.contextual_action(*key, format!("change to {}", lt.describe()))
|
||||
{
|
||||
let mut new_edits = orig_edits.clone();
|
||||
new_edits.lane_overrides.insert(lane.id, *lt);
|
||||
@ -374,7 +375,8 @@ fn next_type(lt: LaneType) -> LaneType {
|
||||
LaneType::Driving => LaneType::Parking,
|
||||
LaneType::Parking => LaneType::Biking,
|
||||
LaneType::Biking => LaneType::Bus,
|
||||
LaneType::Bus => LaneType::Driving,
|
||||
LaneType::Bus => LaneType::Construction,
|
||||
LaneType::Construction => LaneType::Driving,
|
||||
|
||||
LaneType::SharedLeftTurn => unreachable!(),
|
||||
LaneType::Sidewalk => unreachable!(),
|
||||
@ -519,6 +521,7 @@ fn make_bulk_edit_lanes(road: RoadID) -> Box<dyn State> {
|
||||
Choice::new("parking", LaneType::Parking),
|
||||
Choice::new("biking", LaneType::Biking),
|
||||
Choice::new("bus", LaneType::Bus),
|
||||
Choice::new("construction", LaneType::Construction),
|
||||
]
|
||||
})?;
|
||||
let (_, to) = wizard.choose("Change to all lanes of type...", || {
|
||||
@ -527,6 +530,7 @@ fn make_bulk_edit_lanes(road: RoadID) -> Box<dyn State> {
|
||||
Choice::new("parking", LaneType::Parking),
|
||||
Choice::new("biking", LaneType::Biking),
|
||||
Choice::new("bus", LaneType::Bus),
|
||||
Choice::new("construction", LaneType::Construction),
|
||||
]
|
||||
.into_iter()
|
||||
.filter(|c| c.data != from)
|
||||
|
@ -53,6 +53,7 @@ impl DrawLane {
|
||||
LaneType::Sidewalk => cs.get_def("sidewalk", Color::grey(0.8)),
|
||||
LaneType::Biking => cs.get_def("bike lane", Color::rgb(15, 125, 75)),
|
||||
LaneType::SharedLeftTurn => cs.get("driving lane"),
|
||||
LaneType::Construction => cs.get_def("construction lane", Color::rgb(255, 109, 0)),
|
||||
},
|
||||
polygon.clone(),
|
||||
);
|
||||
@ -97,6 +98,7 @@ impl DrawLane {
|
||||
.make_polygons(Distance::meters(0.25)),
|
||||
);
|
||||
}
|
||||
LaneType::Construction => {}
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -663,6 +663,7 @@ impl Model {
|
||||
LaneType::Sidewalk => Color::grey(0.8),
|
||||
LaneType::Biking => Color::rgb(15, 125, 75),
|
||||
LaneType::SharedLeftTurn => Color::YELLOW,
|
||||
LaneType::Construction => Color::rgb(255, 109, 0),
|
||||
};
|
||||
if synthetic {
|
||||
if unset {
|
||||
|
@ -28,6 +28,7 @@ pub enum LaneType {
|
||||
Biking,
|
||||
Bus,
|
||||
SharedLeftTurn,
|
||||
Construction,
|
||||
}
|
||||
|
||||
impl LaneType {
|
||||
@ -39,6 +40,31 @@ impl LaneType {
|
||||
LaneType::Parking => false,
|
||||
LaneType::Sidewalk => false,
|
||||
LaneType::SharedLeftTurn => false,
|
||||
LaneType::Construction => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn supports_any_movement(self) -> bool {
|
||||
match self {
|
||||
LaneType::Driving => true,
|
||||
LaneType::Biking => true,
|
||||
LaneType::Bus => true,
|
||||
LaneType::Parking => false,
|
||||
LaneType::Sidewalk => true,
|
||||
LaneType::SharedLeftTurn => false,
|
||||
LaneType::Construction => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn describe(self) -> &'static str {
|
||||
match self {
|
||||
LaneType::Driving => "a general-purpose driving lane",
|
||||
LaneType::Biking => "a protected bike lane",
|
||||
LaneType::Bus => "a bus-only lane",
|
||||
LaneType::Parking => "an on-street parking lane",
|
||||
LaneType::Sidewalk => "a sidewalk",
|
||||
LaneType::SharedLeftTurn => "a shared left-turn lane",
|
||||
LaneType::Construction => "a lane that's closed for construction",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -192,6 +192,7 @@ impl RoadSpec {
|
||||
LaneType::Biking => 'b',
|
||||
LaneType::Bus => 'u',
|
||||
LaneType::SharedLeftTurn => 'l',
|
||||
LaneType::Construction => 'c',
|
||||
}
|
||||
}
|
||||
|
||||
@ -203,6 +204,7 @@ impl RoadSpec {
|
||||
'b' => Some(LaneType::Biking),
|
||||
'u' => Some(LaneType::Bus),
|
||||
'l' => Some(LaneType::SharedLeftTurn),
|
||||
'c' => Some(LaneType::Construction),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
@ -41,12 +41,10 @@ pub fn make_all_turns(
|
||||
}
|
||||
|
||||
// Make sure every incoming lane has a turn originating from it, and every outgoing lane has a
|
||||
// turn leading to it. Except for parking lanes, of course.
|
||||
// turn leading to it.
|
||||
let mut incoming_missing: HashSet<LaneID> = HashSet::new();
|
||||
for l in &i.incoming_lanes {
|
||||
if lanes[l.0].lane_type != LaneType::Parking
|
||||
&& lanes[l.0].lane_type != LaneType::SharedLeftTurn
|
||||
{
|
||||
if lanes[l.0].lane_type.supports_any_movement() {
|
||||
incoming_missing.insert(*l);
|
||||
}
|
||||
}
|
||||
@ -67,9 +65,7 @@ pub fn make_all_turns(
|
||||
|
||||
let mut outgoing_missing: HashSet<LaneID> = HashSet::new();
|
||||
for l in &i.outgoing_lanes {
|
||||
if lanes[l.0].lane_type != LaneType::Parking
|
||||
&& lanes[l.0].lane_type != LaneType::SharedLeftTurn
|
||||
{
|
||||
if lanes[l.0].lane_type.supports_any_movement() {
|
||||
outgoing_missing.insert(*l);
|
||||
}
|
||||
}
|
||||
@ -121,6 +117,7 @@ fn make_vehicle_turns(
|
||||
}
|
||||
lane_types.remove(&LaneType::Parking);
|
||||
lane_types.remove(&LaneType::SharedLeftTurn);
|
||||
lane_types.remove(&LaneType::Construction);
|
||||
lane_types.remove(&LaneType::Sidewalk);
|
||||
|
||||
let mut result: Vec<Option<Turn>> = Vec::new();
|
||||
|
@ -137,9 +137,12 @@ impl Router {
|
||||
let lt = map.get_l(l).lane_type;
|
||||
let ok = match lt {
|
||||
LaneType::Driving => true,
|
||||
LaneType::Parking | LaneType::Sidewalk | LaneType::SharedLeftTurn => false,
|
||||
LaneType::Biking => vehicle.vehicle_type == VehicleType::Bike,
|
||||
LaneType::Bus => vehicle.vehicle_type == VehicleType::Bus,
|
||||
LaneType::Parking
|
||||
| LaneType::Sidewalk
|
||||
| LaneType::SharedLeftTurn
|
||||
| LaneType::Construction => false,
|
||||
};
|
||||
if !ok {
|
||||
panic!("{} just wound up on {}, a {:?}", vehicle.id, l, lt);
|
||||
|
Loading…
Reference in New Issue
Block a user