diff --git a/src/exploration.rs b/src/exploration.rs index 1e271f2..713ff43 100644 --- a/src/exploration.rs +++ b/src/exploration.rs @@ -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 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( config: Res>, mut tts: ResMut, input: Res>, - mut explorers: Query<(&Player, &Viewshed, &mut FocusedExplorationType)>, - features: Query<(&Coordinates, &ExplorationType)>, + mut explorers: Query<(&VisibleEntities, &mut FocusedExplorationType)>, + features: Query<&ExplorationType>, ) -> Result<(), Box> 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 = 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( mut tts: ResMut, explorers: Query<( Entity, - &Player, - &Viewshed, + &VisibleEntities, &FocusedExplorationType, Option<&Exploring>, )>, - features: Query<(&Coordinates, &ExplorationType)>, + features: Query<(Entity, &Coordinates, &ExplorationType)>, ) -> Result<(), Box> 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::>(); features.sort_by(|(c1, _), (c2, _)| c1.partial_cmp(c2).unwrap()); if let Some(focused) = &focused.0 {