Fix visibility logging.

This commit is contained in:
Nolan Darilek 2021-06-16 13:09:21 -05:00
parent 98bca77f66
commit 822e60e722

View File

@ -241,9 +241,8 @@ fn log_visible(
query_pipeline: Res<QueryPipeline>,
collider_query: QueryPipelineColliderComponentsQuery,
mut log: Query<&mut Log>,
viewers: Query<(&Viewshed, &Coordinates, &Transform), With<Player>>,
viewers: Query<(Entity, &Viewshed, &Coordinates, &Transform), With<Player>>,
names: Query<&Name>,
players: Query<&Player>,
dont_log_when_visible: Query<&DontLogWhenVisible>,
) {
for timer in recently_lost.values_mut() {
@ -257,9 +256,9 @@ fn log_visible(
}
let mut new_seen = HashSet::new();
if let Ok(mut log) = log.single_mut() {
for (viewshed, coordinates, transform) in viewers.iter() {
for (viewer_entity, viewshed, coordinates, transform) in viewers.iter() {
let collider_set = QueryPipelineColliderComponentsSet(&collider_query);
let shape = Cuboid::new(Vec2::new(0.5, 0.5).into());
let shape = Cuboid::new(Vec2::new(0.49, 0.49).into());
for viewed_coordinates in &viewshed.visible {
let shape_pos = (
Vec2::new(viewed_coordinates.x() + 0.5, viewed_coordinates.y() + 0.5),
@ -271,15 +270,17 @@ fn log_visible(
&shape_pos,
&shape,
InteractionGroups::all(),
None,
Some(&|v| v.entity() != viewer_entity),
|handle| {
let entity = handle.entity();
if recently_lost.contains_key(&entity) {
new_seen.insert(entity);
recently_lost.remove(&entity);
return true;
}
if let Ok(name) = names.get(entity) {
if players.get(entity).is_err() {
if !seen.contains(&entity)
&& !new_seen.contains(&entity)
&& dont_log_when_visible.get(entity).is_err()
{
let name = name.to_string();
@ -291,7 +292,6 @@ fn log_visible(
}
new_seen.insert(entity);
}
}
true
},
);