diff options
Diffstat (limited to 'dungeon/src/map.rs')
| -rw-r--r-- | dungeon/src/map.rs | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/dungeon/src/map.rs b/dungeon/src/map.rs index 6daa3c7..eda467c 100644 --- a/dungeon/src/map.rs +++ b/dungeon/src/map.rs @@ -162,6 +162,13 @@ impl Floor { &mut *self.tiles } + /// Returns the neighbors of a tile inside the floor, checking + /// that the neighbor positions are the same tile type as in `pos`. + pub fn neighbors(&self, pos: &Pos) -> impl Iterator<Item = Pos> { + let tile = self.get(*pos); + pos.neighbors().filter(move |p| self.get(*p) == tile) + } + /// Computes the hash of the tile map #[must_use] pub fn hash(&self) -> u64 { |