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