summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFreya Murphy <freya@freyacat.org>2025-10-16 11:06:01 -0400
committerFreya Murphy <freya@freyacat.org>2025-10-16 11:06:01 -0400
commitaaf194e209ebe55cafbf6ff266ca4567faa09e6f (patch)
tree1c9c7e054d7d3416bc5b789935b5bb320233c6ca
parentgraphics: create Renderer struct (diff)
downloadDungeonCrawl-aaf194e209ebe55cafbf6ff266ca4567faa09e6f.tar.gz
DungeonCrawl-aaf194e209ebe55cafbf6ff266ca4567faa09e6f.tar.bz2
DungeonCrawl-aaf194e209ebe55cafbf6ff266ca4567faa09e6f.zip
dungeon: add more getters and lib fns
-rw-r--r--dungeon/src/lib.rs24
-rw-r--r--dungeon/src/pos.rs22
2 files changed, 46 insertions, 0 deletions
diff --git a/dungeon/src/lib.rs b/dungeon/src/lib.rs
index 84fc339..cc15455 100644
--- a/dungeon/src/lib.rs
+++ b/dungeon/src/lib.rs
@@ -49,6 +49,30 @@ impl Dungeon {
Self { player, floor }
}
+
+ /// Returns a reference to the player
+ #[must_use]
+ pub fn player(&self) -> &Entity {
+ &self.player
+ }
+
+ /// Returns a mutable reference to the player
+ #[must_use]
+ pub fn player_mut(&mut self) -> &mut Entity {
+ &mut self.player
+ }
+
+ /// Returns a reference to the current floor
+ #[must_use]
+ pub fn floor(&self) -> &Floor {
+ &self.floor
+ }
+
+ /// Returns a mutable reference to the current floor
+ #[must_use]
+ pub fn floor_mut(&mut self) -> &mut Floor {
+ &mut self.floor
+ }
}
impl Default for Dungeon {
diff --git a/dungeon/src/pos.rs b/dungeon/src/pos.rs
index 8695d0b..a1de65e 100644
--- a/dungeon/src/pos.rs
+++ b/dungeon/src/pos.rs
@@ -188,6 +188,28 @@ impl Pos {
}
}
+ /// Computes the absolute difference between to positions
+ ///
+ /// Both values are gurenteed to be less than MAP_SIZE
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// use dungeon::Pos;
+ ///
+ /// let pos1 = Pos::new(2,7).unwrap();
+ /// let pos2 = Pos::new(1,17).unwrap();
+ /// let diff = pos1.abs_diff(pos2);
+ /// assert_eq!(diff.xy(), (1, 10));
+ /// ```
+ ///
+ #[must_use]
+ pub const fn abs_diff(self, other: Self) -> Self {
+ let x = self.0.abs_diff(other.0);
+ let y = self.1.abs_diff(other.1);
+ Self(x, y)
+ }
+
/// Returns of the given position is on the border of the map
///
/// ```