summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock29
-rw-r--r--dungeon/Cargo.toml2
-rw-r--r--dungeon/src/map.rs17
-rw-r--r--dungeon/src/pos.rs11
4 files changed, 52 insertions, 7 deletions
diff --git a/Cargo.lock b/Cargo.lock
index cf97153..73e2671 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -87,6 +87,8 @@ name = "dungeon"
version = "0.1.0"
dependencies = [
"rand",
+ "strum",
+ "strum_macros",
]
[[package]]
@@ -136,6 +138,12 @@ dependencies = [
]
[[package]]
+name = "heck"
+version = "0.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
+
+[[package]]
name = "itertools"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -338,6 +346,27 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
[[package]]
+name = "strum"
+version = "0.27.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "af23d6f6c1a224baef9d3f61e287d2761385a5b88fdab4eb4c6f11aeb54c4bcf"
+dependencies = [
+ "strum_macros",
+]
+
+[[package]]
+name = "strum_macros"
+version = "0.27.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7695ce3845ea4b33927c055a39dc438a45b059f7c1b3d91d38d10355fb8cbca7"
+dependencies = [
+ "heck",
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
name = "syn"
version = "2.0.106"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/dungeon/Cargo.toml b/dungeon/Cargo.toml
index 5548248..b50412b 100644
--- a/dungeon/Cargo.toml
+++ b/dungeon/Cargo.toml
@@ -5,6 +5,8 @@ edition = "2024"
[dependencies]
rand = "0.9"
+strum = { version = "0.27", features = ["derive"] }
+strum_macros = "0.27"
[lints]
workspace = true
diff --git a/dungeon/src/map.rs b/dungeon/src/map.rs
index a2cdd9a..fb42a77 100644
--- a/dungeon/src/map.rs
+++ b/dungeon/src/map.rs
@@ -1,6 +1,9 @@
//! The `map` module contains structures of the dungeon game map
//! including the current `Floor`, and map `Tile`.
+use strum::IntoEnumIterator;
+use strum_macros::EnumIter;
+
use crate::wfc::Wfc;
use std::{
cell::RefCell,
@@ -20,7 +23,7 @@ pub const TILE_COUNT: usize = MAP_SIZE_USIZE * MAP_SIZE_USIZE;
/// The `Tile` enum represents what is (or is not) at
/// any given spot in the dungeon grid.
-#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
+#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, EnumIter)]
pub enum Tile {
/// `Wall` represents an impassible wall
Wall,
@@ -29,13 +32,15 @@ pub enum Tile {
/// `Stairs` represents stairs to another floor
Stairs,
}
-
impl Tile {
/// Returns a list of all possible tiles
- /// TODO! Use a crate for enum itterator
- #[must_use]
- pub fn all_tiles() -> Vec<Tile> {
- vec![Tile::Wall, Tile::Air, Tile::Stairs]
+ pub fn values() -> impl Iterator<Item = Self> {
+ Self::iter()
+ }
+}
+impl Default for Tile {
+ fn default() -> Self {
+ Self::Air
}
}
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.
///