mirror of
https://github.com/mat-1/azalea.git
synced 2024-09-19 22:52:32 +00:00
more reliable StopPathfindingEvent
This commit is contained in:
parent
348c71b97b
commit
929cb95db4
1 changed files with 12 additions and 3 deletions
|
@ -292,7 +292,7 @@ fn goto_listener(
|
|||
})
|
||||
});
|
||||
|
||||
commands.spawn(ComputePath(task));
|
||||
commands.entity(event.entity).insert(ComputePath(task));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -675,6 +675,9 @@ fn handle_stop_pathfinding_event(
|
|||
mut commands: Commands,
|
||||
) {
|
||||
for event in events.read() {
|
||||
// stop computing any path that's being computed
|
||||
commands.entity(event.entity).remove::<ComputePath>();
|
||||
|
||||
let Ok((mut pathfinder, mut executing_path)) = query.get_mut(event.entity) else {
|
||||
continue;
|
||||
};
|
||||
|
@ -682,13 +685,19 @@ fn handle_stop_pathfinding_event(
|
|||
if event.force {
|
||||
executing_path.path.clear();
|
||||
executing_path.queued_path = None;
|
||||
} else {
|
||||
// switch to an empty path as soon as it can
|
||||
executing_path.queued_path = Some(VecDeque::new());
|
||||
// make sure it doesn't recalculate
|
||||
executing_path.is_path_partial = false;
|
||||
}
|
||||
|
||||
if executing_path.path.is_empty() {
|
||||
walk_events.send(StartWalkEvent {
|
||||
entity: event.entity,
|
||||
direction: WalkDirection::None,
|
||||
});
|
||||
commands.entity(event.entity).remove::<ExecutingPath>();
|
||||
} else {
|
||||
executing_path.queued_path = Some(VecDeque::new());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue