diff options
Diffstat (limited to 'src/resources/ground.rs')
| -rw-r--r-- | src/resources/ground.rs | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/resources/ground.rs b/src/resources/ground.rs index 7411a15..7868be9 100644 --- a/src/resources/ground.rs +++ b/src/resources/ground.rs @@ -9,7 +9,8 @@ use specs::{ use crate::{ components::{Visible, Flags, Flag}, - Pos + Pos, + controls::Direction }; #[derive(Default)] @@ -43,6 +44,19 @@ impl Ground { .collect() } + pub fn components_near<'a, C: Component>(&self, pos: Pos, directions: &[Direction], component_type: &'a ReadStorage<C>) -> Vec<(Entity, &'a C)> { + let mut nearby_components: Vec<(Entity, &'a C)> = Vec::new(); + for direction in directions { + let pos = pos + direction.to_position(); + for ent in self.cells.get(&pos).unwrap_or(&HashSet::new()) { + if let Some(comp) = component_type.get(*ent) { + nearby_components.push((*ent, comp)); + } + } + } + nearby_components + } + pub fn by_height(&self, pos: &Pos, visibles: &ReadStorage<Visible>, ignore: &Entity) -> Vec<Entity> { let mut entities: Vec<Entity> = self.cells .get(&pos).unwrap_or(&HashSet::new()) |
