summaryrefslogtreecommitdiff
path: root/dungeon/src/pos.rs
diff options
context:
space:
mode:
authorFreya Murphy <freya@freyacat.org>2025-10-23 15:01:10 -0400
committerFreya Murphy <freya@freyacat.org>2025-10-23 15:01:10 -0400
commitbdede767f3e5208eb78103f5fbdb83ec1255f293 (patch)
tree3c6ce828d8b1c8ddb02380a592a4210c9d3b97d9 /dungeon/src/pos.rs
parentgraphics: refactor Assets, and add tile drawing! (diff)
downloadDungeonCrawl-bdede767f3e5208eb78103f5fbdb83ec1255f293.tar.gz
DungeonCrawl-bdede767f3e5208eb78103f5fbdb83ec1255f293.tar.bz2
DungeonCrawl-bdede767f3e5208eb78103f5fbdb83ec1255f293.zip
dungon: use EnumIter from strum to add values methods to enums
Diffstat (limited to 'dungeon/src/pos.rs')
-rw-r--r--dungeon/src/pos.rs11
1 files changed, 10 insertions, 1 deletions
diff --git a/dungeon/src/pos.rs b/dungeon/src/pos.rs
index dc1bd2d..27d9b8f 100644
--- a/dungeon/src/pos.rs
+++ b/dungeon/src/pos.rs
@@ -2,6 +2,9 @@
//! entity or objects position and facing direction inside the
//! dungeon grid.
+use strum::IntoEnumIterator;
+use strum_macros::EnumIter;
+
use std::ops::{AddAssign, SubAssign};
use crate::{MAP_SIZE_USIZE, map::MAP_SIZE};
@@ -29,13 +32,19 @@ macro_rules! const_pos {
/// or any position object is facing inside the dungeon map.
/// Since the dungeon lives on a grid, there are only four
/// possible directions.
-#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
+#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, EnumIter)]
pub enum Direction {
North,
South,
East,
West,
}
+impl Direction {
+ /// Returns an iterator over all possible directions
+ pub fn values() -> impl Iterator<Item = Self> {
+ Self::iter()
+ }
+}
/// The `Pos` type represents a 2D position inside the dungeon grid.
///