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 mod pathfinding;
|
||||||
pub use rand;
|
pub use rand;
|
||||||
pub mod sound;
|
pub mod sound;
|
||||||
|
pub mod utils;
|
||||||
pub mod visibility;
|
pub mod visibility;
|
||||||
|
|
61
src/map.rs
61
src/map.rs
|
@ -12,6 +12,7 @@ use crate::{
|
||||||
core::{Area, Coordinates, Player, PointLike},
|
core::{Area, Coordinates, Player, PointLike},
|
||||||
exploration::{ExplorationType, Mappable},
|
exploration::{ExplorationType, Mappable},
|
||||||
log::Log,
|
log::Log,
|
||||||
|
utils::target_and_other,
|
||||||
visibility::BlocksVisibility,
|
visibility::BlocksVisibility,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -296,50 +297,38 @@ fn portal_spawner(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn area_description(
|
fn area_description(
|
||||||
|
mut events: EventReader<IntersectionEvent>,
|
||||||
|
areas: Query<&AreaTag>,
|
||||||
|
players: Query<&Player>,
|
||||||
|
names: Query<&Name>,
|
||||||
config: Res<MapConfig>,
|
config: Res<MapConfig>,
|
||||||
mut prev_area: Local<Option<Area>>,
|
shapes: Query<&ColliderShape>,
|
||||||
query: Query<(&Player, &Coordinates), Changed<Coordinates>>,
|
|
||||||
map: Query<(&Map, &Areas)>,
|
|
||||||
mut log: Query<&mut Log>,
|
mut log: Query<&mut Log>,
|
||||||
) {
|
) {
|
||||||
for (_, coordinates) in query.iter() {
|
for event in events.iter() {
|
||||||
for (_, areas) in map.iter() {
|
if event.intersecting {
|
||||||
let mut should_describe_area = false;
|
if let Some((area, other)) =
|
||||||
let mut current_area: Option<Area> = None;
|
target_and_other(event.collider1.entity(), event.collider2.entity(), &|v| {
|
||||||
for area in areas.iter() {
|
areas.get(v).is_ok()
|
||||||
if area.contains(&*coordinates) {
|
})
|
||||||
current_area = Some(area.clone());
|
{
|
||||||
if let Some(prev_area) = &*prev_area {
|
if players.get(other).is_ok() {
|
||||||
if prev_area != area {
|
if let Ok(mut log) = log.single_mut() {
|
||||||
should_describe_area = true;
|
if let Ok(name) = names.get(area) {
|
||||||
}
|
log.push(name.to_string());
|
||||||
} 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 {
|
} else if config.describe_undescribed_areas {
|
||||||
Some(format!(
|
if let Ok(shape) = shapes.get(area) {
|
||||||
"{} by {} area.",
|
let aabb = shape.compute_local_aabb();
|
||||||
area.rect.width(),
|
log.push(format!(
|
||||||
area.rect.height()
|
"{}-by-{} area",
|
||||||
))
|
aabb.extents().x,
|
||||||
} else {
|
aabb.extents().y
|
||||||
None
|
));
|
||||||
};
|
}
|
||||||
if let Some(description) = description {
|
|
||||||
for mut log in log.iter_mut() {
|
|
||||||
log.push(description.clone());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*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