If an entity has coordinates and a collider hits a space that isn't equal to the coordinates, mark it as visible.

Yes this is an ugly hack, but it works for now.
This commit is contained in:
Nolan Darilek 2021-07-21 15:27:38 -05:00
parent fee446cb7d
commit 12b7ecd2ea

View File

@ -102,6 +102,7 @@ fn update_viewshed(
collider_query: &QueryPipelineColliderComponentsQuery,
map: &Map,
blocks_visibility: &Query<&BlocksVisibility>,
coordinates: &Query<&Coordinates>,
) {
let mut context: Context<u8> = Context::default();
let vision_distance = vision_distance::Circle::new(viewshed.range);
@ -122,9 +123,18 @@ fn update_viewshed(
&shape,
InteractionGroups::all(),
Some(&|v| v.entity() != *viewer_entity && blocks_visibility.get(v.entity()).is_ok()),
|_| {
opacity = 255;
false
|handle| {
if let Ok(coordinates) = coordinates.get(handle.entity()) {
if coordinates.i32() == (coord.x, coord.y) {
opacity = 255;
false
} else {
true
}
} else {
opacity = 255;
false
}
},
);
opacity
@ -148,6 +158,7 @@ fn update_viewshed_for_coordinates(
query_pipeline: Res<QueryPipeline>,
collider_query: QueryPipelineColliderComponentsQuery,
blocks_visibility: Query<&BlocksVisibility>,
coordinates_query: Query<&Coordinates>,
) {
for (coordinates, _) in visible.iter() {
for (viewer_entity, mut viewshed, start) in viewers.iter_mut() {
@ -163,6 +174,7 @@ fn update_viewshed_for_coordinates(
&collider_query,
map,
&blocks_visibility,
&coordinates_query,
);
}
}
@ -175,6 +187,7 @@ fn update_viewshed_for_start(
query_pipeline: Res<QueryPipeline>,
collider_query: QueryPipelineColliderComponentsQuery,
blocks_visibility: Query<&BlocksVisibility>,
coordinates_query: Query<&Coordinates>,
) {
for (viewer_entity, mut viewshed, start) in viewers.iter_mut() {
if let Ok(map) = map.single() {
@ -186,6 +199,7 @@ fn update_viewshed_for_start(
&collider_query,
map,
&blocks_visibility,
&coordinates_query,
);
}
}
@ -198,6 +212,7 @@ fn remove_blocks_visibility(
query_pipeline: Res<QueryPipeline>,
collider_query: QueryPipelineColliderComponentsQuery,
blocks_visibility: Query<&BlocksVisibility>,
coordinates_query: Query<&Coordinates>,
) {
for _ in removed.iter() {
for (viewer_entity, mut viewshed, start) in viewers.iter_mut() {
@ -210,6 +225,7 @@ fn remove_blocks_visibility(
&collider_query,
map,
&blocks_visibility,
&coordinates_query,
);
}
}