mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-28 03:35:51 +03:00
Fix crash in the LTN and Ungap pathfinding tool, introduced in
2bf7ce232a
This commit is contained in:
parent
82dff217a5
commit
b07177c21a
@ -189,10 +189,13 @@ impl State<App> for TripPlanner {
|
||||
self.recalculate_routes(ctx, app);
|
||||
return Transition::Keep;
|
||||
}
|
||||
x => x.map_id(|id| match id {
|
||||
ID::Waypoint(id) => id,
|
||||
_ => unreachable!(),
|
||||
}),
|
||||
x => x
|
||||
.maybe_map_id(|id| match id {
|
||||
ID::Waypoint(id) => Some(id),
|
||||
// Ignore HoverChanged events
|
||||
_ => None,
|
||||
})
|
||||
.unwrap_or(WorldOutcome::Nothing),
|
||||
};
|
||||
|
||||
let panel_outcome = self.input_panel.event(ctx);
|
||||
|
@ -4,7 +4,7 @@ use map_gui::tools::{
|
||||
};
|
||||
use map_model::{PathfinderCaching, NORMAL_LANE_THICKNESS};
|
||||
use synthpop::{TripEndpoint, TripMode};
|
||||
use widgetry::mapspace::{ObjectID, ToggleZoomed, World};
|
||||
use widgetry::mapspace::{ObjectID, ToggleZoomed, World, WorldOutcome};
|
||||
use widgetry::{
|
||||
Color, EventCtx, GfxCtx, Line, Outcome, Panel, RoundedF64, Spinner, State, Text, Widget,
|
||||
};
|
||||
@ -249,10 +249,13 @@ impl State<App> for RoutePlanner {
|
||||
// Fall through. Clicking free space and other ID-less outcomes will match here, but we
|
||||
// don't want them to.
|
||||
}
|
||||
let world_outcome_for_waypoints = world_outcome.map_id(|id| match id {
|
||||
Obj::Waypoint(id) => id,
|
||||
_ => unreachable!(),
|
||||
});
|
||||
// Ignore HoverChanged events for filterable objects
|
||||
let world_outcome_for_waypoints = world_outcome
|
||||
.maybe_map_id(|id| match id {
|
||||
Obj::Waypoint(id) => Some(id),
|
||||
_ => None,
|
||||
})
|
||||
.unwrap_or(WorldOutcome::Nothing);
|
||||
|
||||
let panel_outcome = self.panel.event(ctx);
|
||||
if let Outcome::Clicked(ref x) = panel_outcome {
|
||||
|
@ -63,11 +63,6 @@ impl<I: ObjectID> WorldOutcome<I> {
|
||||
/// If the outcome references some ID, transform it to another type. This is useful when some
|
||||
/// component owns a World that contains a few different types of objects, some of which are
|
||||
/// managed by another component that only cares about its IDs.
|
||||
pub fn map_id<O: ObjectID, F: Fn(I) -> O>(self, f: F) -> WorldOutcome<O> {
|
||||
self.maybe_map_id(|id| Some(f(id))).unwrap()
|
||||
}
|
||||
|
||||
/// Like `map_id`, but the transformation may fail.
|
||||
pub fn maybe_map_id<O: ObjectID, F: Fn(I) -> Option<O>>(self, f: F) -> Option<WorldOutcome<O>> {
|
||||
match self {
|
||||
WorldOutcome::ClickedFreeSpace(pt) => Some(WorldOutcome::ClickedFreeSpace(pt)),
|
||||
|
Loading…
Reference in New Issue
Block a user