From a591326734abad0ed2cb5a78ef591ec593ebfacc Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Mon, 19 Jul 2021 12:16:47 -0500 Subject: [PATCH] More robust area descriptions. --- src/map.rs | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/src/map.rs b/src/map.rs index 9b1d35c..057dd29 100644 --- a/src/map.rs +++ b/src/map.rs @@ -445,25 +445,30 @@ fn area_description( mut log: Query<&mut Log>, ) { for event in events.iter() { - if event.intersecting { - if let Some((area, other)) = - target_and_other(event.collider1.entity(), event.collider2.entity(), &|v| { - areas.get(v).is_ok() - }) - { - if players.get(other).is_ok() { - if let Ok(mut log) = log.single_mut() { - if let Ok(name) = names.get(area) { - log.push(name.to_string()); - } else if config.describe_undescribed_areas { - if let Ok(shape) = shapes.get(area) { - let aabb = shape.compute_local_aabb(); - log.push(format!( - "{}-by-{} area", - aabb.extents().x, - aabb.extents().y - )); - } + if let Some((area, other)) = + target_and_other(event.collider1.entity(), event.collider2.entity(), &|v| { + areas.get(v).is_ok() + }) + { + if players.get(other).is_ok() { + if let Ok(mut log) = log.single_mut() { + let name = if let Ok(name) = names.get(area) { + Some(name.to_string()) + } else if config.describe_undescribed_areas { + if let Ok(shape) = shapes.get(area) { + let aabb = shape.compute_local_aabb(); + Some(format!("{}-by-{} area", aabb.extents().x, aabb.extents().y)) + } else { + None + } + } else { + None + }; + if let Some(name) = name { + if event.intersecting { + log.push(format!("Entering {}.", name)); + } else { + log.push(format!("Leaving {}.", name)); } } }