More robust area descriptions.

This commit is contained in:
Nolan Darilek 2021-07-19 12:16:47 -05:00
parent 9a2495d9de
commit a591326734

View File

@ -445,25 +445,30 @@ fn area_description(
mut log: Query<&mut Log>, mut log: Query<&mut Log>,
) { ) {
for event in events.iter() { for event in events.iter() {
if event.intersecting { if let Some((area, other)) =
if let Some((area, other)) = target_and_other(event.collider1.entity(), event.collider2.entity(), &|v| {
target_and_other(event.collider1.entity(), event.collider2.entity(), &|v| { areas.get(v).is_ok()
areas.get(v).is_ok() })
}) {
{ if players.get(other).is_ok() {
if players.get(other).is_ok() { if let Ok(mut log) = log.single_mut() {
if let Ok(mut log) = log.single_mut() { let name = if let Ok(name) = names.get(area) {
if let Ok(name) = names.get(area) { Some(name.to_string())
log.push(name.to_string()); } else if config.describe_undescribed_areas {
} else if config.describe_undescribed_areas { if let Ok(shape) = shapes.get(area) {
if let Ok(shape) = shapes.get(area) { let aabb = shape.compute_local_aabb();
let aabb = shape.compute_local_aabb(); Some(format!("{}-by-{} area", aabb.extents().x, aabb.extents().y))
log.push(format!( } else {
"{}-by-{} area", None
aabb.extents().x, }
aabb.extents().y } else {
)); None
} };
if let Some(name) = name {
if event.intersecting {
log.push(format!("Entering {}.", name));
} else {
log.push(format!("Leaving {}.", name));
} }
} }
} }