Migrate area description logger to new areas.
This commit is contained in:
parent
80f163f65f
commit
5ff4a92c44
|
@ -20,4 +20,5 @@ pub mod navigation;
|
|||
pub mod pathfinding;
|
||||
pub use rand;
|
||||
pub mod sound;
|
||||
pub mod utils;
|
||||
pub mod visibility;
|
||||
|
|
63
src/map.rs
63
src/map.rs
|
@ -12,6 +12,7 @@ use crate::{
|
|||
core::{Area, Coordinates, Player, PointLike},
|
||||
exploration::{ExplorationType, Mappable},
|
||||
log::Log,
|
||||
utils::target_and_other,
|
||||
visibility::BlocksVisibility,
|
||||
};
|
||||
|
||||
|
@ -296,50 +297,38 @@ fn portal_spawner(
|
|||
}
|
||||
|
||||
fn area_description(
|
||||
mut events: EventReader<IntersectionEvent>,
|
||||
areas: Query<&AreaTag>,
|
||||
players: Query<&Player>,
|
||||
names: Query<&Name>,
|
||||
config: Res<MapConfig>,
|
||||
mut prev_area: Local<Option<Area>>,
|
||||
query: Query<(&Player, &Coordinates), Changed<Coordinates>>,
|
||||
map: Query<(&Map, &Areas)>,
|
||||
shapes: Query<&ColliderShape>,
|
||||
mut log: Query<&mut Log>,
|
||||
) {
|
||||
for (_, coordinates) in query.iter() {
|
||||
for (_, areas) in map.iter() {
|
||||
let mut should_describe_area = false;
|
||||
let mut current_area: Option<Area> = None;
|
||||
for area in areas.iter() {
|
||||
if area.contains(&*coordinates) {
|
||||
current_area = Some(area.clone());
|
||||
if let Some(prev_area) = &*prev_area {
|
||||
if prev_area != area {
|
||||
should_describe_area = true;
|
||||
}
|
||||
} else {
|
||||
should_describe_area = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if should_describe_area {
|
||||
if let Some(ref area) = current_area {
|
||||
let description = if area.description.is_some() {
|
||||
area.description.clone()
|
||||
} else if config.describe_undescribed_areas {
|
||||
Some(format!(
|
||||
"{} by {} area.",
|
||||
area.rect.width(),
|
||||
area.rect.height()
|
||||
))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
if let Some(description) = description {
|
||||
for mut log in log.iter_mut() {
|
||||
log.push(description.clone());
|
||||
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
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
*prev_area = current_area;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
18
src/utils.rs
Normal file
18
src/utils.rs
Normal file
|
@ -0,0 +1,18 @@
|
|||
use bevy::prelude::*;
|
||||
|
||||
pub fn target_and_other<F>(
|
||||
entity1: Entity,
|
||||
entity2: Entity,
|
||||
mut predecate: F,
|
||||
) -> Option<(Entity, Entity)>
|
||||
where
|
||||
F: FnMut(Entity) -> bool,
|
||||
{
|
||||
if predecate(entity1) {
|
||||
Some((entity1, entity2))
|
||||
} else if predecate(entity2) {
|
||||
Some((entity2, entity1))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user