woops, agent_to_trip isn't defined for parked cars

This commit is contained in:
Dustin Carlino 2018-12-03 10:54:10 -08:00
parent 08cc4124fb
commit ac00e24dda
5 changed files with 26 additions and 26 deletions

View File

@ -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));
}
}
}
}

View File

@ -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;
}
}
}
}

View File

@ -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));
}
}
};
}

View File

@ -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)
}

View File

@ -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> {