diff options
| author | troido <troido@protonmail.com> | 2020-09-21 02:33:19 +0200 |
|---|---|---|
| committer | troido <troido@protonmail.com> | 2020-09-21 02:33:19 +0200 |
| commit | 5ce9b012a7987f4085057f4f0b0af35e76810a7a (patch) | |
| tree | a99418b5aec06d6be28e22150bce85d3c40b8ee7 /src/resources | |
| parent | b6a4c7b2d383755402e5e2c6f60d9a75a899b809 (diff) | |
| parent | 455867294cc849bff2c0829a7464e71e79a0dcae (diff) | |
Merge branch 'interact' into master
Diffstat (limited to 'src/resources')
| -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()) |
