diff --git a/editor/src/plugins/diff_worlds.rs b/editor/src/plugins/diff_worlds.rs index 3779bcc880..6ffd7423fb 100644 --- a/editor/src/plugins/diff_worlds.rs +++ b/editor/src/plugins/diff_worlds.rs @@ -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 ctx - .input - .key_pressed(Key::B, &format!("Show {}'s parallel world", id)) - { - new_state = Some(diff_world(ctx.primary.sim.agent_to_trip(id), ctx)); + 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", agent)) + { + new_state = Some(diff_world(trip, ctx)); + } } } } diff --git a/editor/src/plugins/follow.rs b/editor/src/plugins/follow.rs index 71ab2c298f..4bccc61467 100644 --- a/editor/src/plugins/follow.rs +++ b/editor/src/plugins/follow.rs @@ -19,12 +19,11 @@ 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)); - return true; + 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; + } } } } diff --git a/editor/src/plugins/show_route.rs b/editor/src/plugins/show_route.rs index eb9cf4db04..1d88439450 100644 --- a/editor/src/plugins/show_route.rs +++ b/editor/src/plugins/show_route.rs @@ -25,17 +25,14 @@ 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 ctx - .input - .key_pressed(Key::R, &format!("show {}'s route", trip)) - { - new_state = Some(show_route(trip, ctx)); + 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", agent)) + { + new_state = Some(show_route(trip, ctx)); + } } }; } diff --git a/sim/src/sim.rs b/sim/src/sim.rs index 2b7b577b64..2143413173 100644 --- a/sim/src/sim.rs +++ b/sim/src/sim.rs @@ -373,7 +373,7 @@ impl Sim { } } - pub fn agent_to_trip(&self, id: AgentID) -> TripID { + pub fn agent_to_trip(&self, id: AgentID) -> Option { self.trips_state.agent_to_trip(id) } diff --git a/sim/src/trips.rs b/sim/src/trips.rs index be0b50f9fc..d4b39024c0 100644 --- a/sim/src/trips.rs +++ b/sim/src/trips.rs @@ -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 { + self.active_trip_mode.get(&id).map(|id| *id) } pub fn get_active_trips(&self) -> Vec {