mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-29 17:34:58 +03:00
woops, agent_to_trip isn't defined for parked cars
This commit is contained in:
parent
08cc4124fb
commit
ac00e24dda
@ -33,12 +33,15 @@ impl Plugin for DiffWorldsState {
|
||||
match self {
|
||||
DiffWorldsState::Inactive => {
|
||||
if ctx.secondary.is_some() {
|
||||
if let Some(id) = ctx.primary.current_selection.and_then(|id| id.agent_id()) {
|
||||
if let Some(agent) = ctx.primary.current_selection.and_then(|id| id.agent_id())
|
||||
{
|
||||
if let Some(trip) = ctx.primary.sim.agent_to_trip(agent) {
|
||||
if ctx
|
||||
.input
|
||||
.key_pressed(Key::B, &format!("Show {}'s parallel world", id))
|
||||
.key_pressed(Key::B, &format!("Show {}'s parallel world", agent))
|
||||
{
|
||||
new_state = Some(diff_world(ctx.primary.sim.agent_to_trip(id), ctx));
|
||||
new_state = Some(diff_world(trip, ctx));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,15 +19,14 @@ impl Plugin for FollowState {
|
||||
fn event(&mut self, ctx: PluginCtx) -> bool {
|
||||
if *self == FollowState::Empty {
|
||||
if let Some(agent) = ctx.primary.current_selection.and_then(|id| id.agent_id()) {
|
||||
if ctx
|
||||
.input
|
||||
.key_pressed(Key::F, &format!("follow {:?}", agent))
|
||||
{
|
||||
*self = FollowState::Active(ctx.primary.sim.agent_to_trip(agent));
|
||||
if let Some(trip) = ctx.primary.sim.agent_to_trip(agent) {
|
||||
if ctx.input.key_pressed(Key::F, &format!("follow {}", agent)) {
|
||||
*self = FollowState::Active(trip);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let mut quit = false;
|
||||
if let FollowState::Active(trip) = self {
|
||||
|
@ -25,18 +25,15 @@ impl Plugin for ShowRouteState {
|
||||
|
||||
match self {
|
||||
ShowRouteState::Inactive => {
|
||||
if let Some(trip) = ctx
|
||||
.primary
|
||||
.current_selection
|
||||
.and_then(|id| id.agent_id())
|
||||
.map(|agent| ctx.primary.sim.agent_to_trip(agent))
|
||||
{
|
||||
if let Some(agent) = ctx.primary.current_selection.and_then(|id| id.agent_id()) {
|
||||
if let Some(trip) = ctx.primary.sim.agent_to_trip(agent) {
|
||||
if ctx
|
||||
.input
|
||||
.key_pressed(Key::R, &format!("show {}'s route", trip))
|
||||
.key_pressed(Key::R, &format!("show {}'s route", agent))
|
||||
{
|
||||
new_state = Some(show_route(trip, ctx));
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
ShowRouteState::Active(time, trip, _) => {
|
||||
|
@ -373,7 +373,7 @@ impl Sim {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn agent_to_trip(&self, id: AgentID) -> TripID {
|
||||
pub fn agent_to_trip(&self, id: AgentID) -> Option<TripID> {
|
||||
self.trips_state.agent_to_trip(id)
|
||||
}
|
||||
|
||||
|
@ -288,8 +288,9 @@ impl TripManager {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn agent_to_trip(&self, id: AgentID) -> TripID {
|
||||
self.active_trip_mode[&id]
|
||||
// This will be None for parked cars
|
||||
pub fn agent_to_trip(&self, id: AgentID) -> Option<TripID> {
|
||||
self.active_trip_mode.get(&id).map(|id| *id)
|
||||
}
|
||||
|
||||
pub fn get_active_trips(&self) -> Vec<TripID> {
|
||||
|
Loading…
Reference in New Issue
Block a user