More modernization.

This commit is contained in:
Nolan Darilek 2021-09-23 13:36:39 -05:00
parent ad60bd7a40
commit ef35478b34

View File

@ -12,7 +12,7 @@ use crate::{
error::error_handler,
map::Map,
pathfinding::Destination,
visibility::{RevealedTiles, Viewshed, VisibleTiles},
visibility::{RevealedTiles, Viewshed, VisibleEntities, VisibleTiles},
};
#[derive(Clone, Copy, Debug, Default, PartialEq, Reflect)]
@ -34,7 +34,7 @@ pub enum ExplorationType {
impl Into<String> for ExplorationType {
fn into(self) -> String {
match self {
ExplorationType::Portal => "Portal".into(),
ExplorationType::Portal => "Exit".into(),
ExplorationType::Item => "Item".into(),
ExplorationType::Character => "Character".into(),
ExplorationType::Ally => "Ally".into(),
@ -74,8 +74,8 @@ fn exploration_type_change<S, A: 'static>(
config: Res<ExplorationConfig<S, A>>,
mut tts: ResMut<Tts>,
input: Res<InputMap<A>>,
mut explorers: Query<(&Player, &Viewshed, &mut FocusedExplorationType)>,
features: Query<(&Coordinates, &ExplorationType)>,
mut explorers: Query<(&VisibleEntities, &mut FocusedExplorationType)>,
features: Query<&ExplorationType>,
) -> Result<(), Box<dyn Error>>
where
S: bevy::ecs::component::Component + Clone + Debug + Eq + Hash,
@ -90,13 +90,10 @@ where
if !changed {
return Ok(());
}
for (_, viewshed, mut focused) in explorers.iter_mut() {
for (visible, mut focused) in explorers.iter_mut() {
let mut types: Vec<ExplorationType> = vec![];
for (coordinates, t) in features.iter() {
let (x, y) = **coordinates;
let x = x as i32;
let y = y as i32;
if viewshed.is_point_visible(&(x, y)) {
for e in visible.iter() {
if let Ok(t) = features.get(*e) {
types.push(*t);
}
}
@ -151,12 +148,11 @@ fn exploration_type_focus<S, A: 'static>(
mut tts: ResMut<Tts>,
explorers: Query<(
Entity,
&Player,
&Viewshed,
&VisibleEntities,
&FocusedExplorationType,
Option<&Exploring>,
)>,
features: Query<(&Coordinates, &ExplorationType)>,
features: Query<(Entity, &Coordinates, &ExplorationType)>,
) -> Result<(), Box<dyn Error>>
where
S: bevy::ecs::component::Component + Clone + Debug + Eq + Hash,
@ -171,15 +167,11 @@ where
if !changed {
return Ok(());
}
for (entity, _, viewshed, focused, exploring) in explorers.iter() {
for (entity, visible_entities, focused, exploring) in explorers.iter() {
let mut features = features
.iter()
.filter(|(coordinates, _)| {
let (x, y) = ***coordinates;
let x = x as i32;
let y = y as i32;
viewshed.is_point_visible(&(x, y))
})
.filter(|v| visible_entities.contains(&v.0))
.map(|v| (v.1, v.2))
.collect::<Vec<(&Coordinates, &ExplorationType)>>();
features.sort_by(|(c1, _), (c2, _)| c1.partial_cmp(c2).unwrap());
if let Some(focused) = &focused.0 {