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