diff options
| author | Freya Murphy <freya@freyacat.org> | 2025-10-18 00:04:25 -0400 |
|---|---|---|
| committer | Freya Murphy <freya@freyacat.org> | 2025-10-18 00:04:48 -0400 |
| commit | 1be47bcbcbcfa3aa0e06342c6d1e9bb1540cbbd3 (patch) | |
| tree | 64e9b116d2b37139fd8e7dd4d598f2f254fba645 /dungeon/src/lib.rs | |
| parent | graphicsL add input functionality to (diff) | |
| download | DungeonCrawl-1be47bcbcbcfa3aa0e06342c6d1e9bb1540cbbd3.tar.gz DungeonCrawl-1be47bcbcbcfa3aa0e06342c6d1e9bb1540cbbd3.tar.bz2 DungeonCrawl-1be47bcbcbcfa3aa0e06342c6d1e9bb1540cbbd3.zip | |
dungeon: refactor into entity module, and add struct (better match proposal)
Diffstat (limited to 'dungeon/src/lib.rs')
| -rw-r--r-- | dungeon/src/lib.rs | 42 |
1 files changed, 10 insertions, 32 deletions
diff --git a/dungeon/src/lib.rs b/dungeon/src/lib.rs index cc15455..0a04ca7 100644 --- a/dungeon/src/lib.rs +++ b/dungeon/src/lib.rs @@ -1,9 +1,11 @@ //! The `dungon` crate contains the core functionality for //! interacting with a `Dungeon` and its components. +mod entity; mod map; mod pos; +pub use entity::*; pub use map::*; pub use pos::*; @@ -11,8 +13,8 @@ pub use pos::*; /// dungeon crawler. #[derive(Clone, Debug, PartialEq, Eq, Hash)] pub struct Dungeon { - player: Entity, - floor: Floor, + pub floor: Floor, + pub player: Player, } impl Dungeon { /// Creates a new `Dungeon`. @@ -27,9 +29,9 @@ impl Dungeon { #[must_use] pub fn new() -> Self { let floor = Floor::generate(); - let player = Entity::player(floor.player_start()); + let player = Player::new(floor.player_start()); - Self { player, floor } + Self { floor, player } } /// Creates a new `Dungeon` with a provided seed. @@ -45,41 +47,17 @@ impl Dungeon { #[must_use] pub fn new_seeded(seed: u64) -> Self { let floor = Floor::generate_seeded(seed); - let player = Entity::player(floor.player_start()); + let player = Player::new(floor.player_start()); - 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 + Self { floor, player } } } impl Default for Dungeon { fn default() -> Self { let floor = Floor::default(); - let player = Entity::player(floor.player_start()); + let player = Player::default(); - Self { player, floor } + Self { floor, player } } } |