From 557b7095b9e2455a3f31fe1f6913c8f758b9a12e Mon Sep 17 00:00:00 2001 From: Llywelwyn Date: Sun, 13 Aug 2023 08:23:22 +0100 Subject: [PATCH] warnings cleanup and MasterDungeonMap class --- src/map/dungeon.rs | 29 +++++++++++++++++++++++++++++ src/map/glyphs.rs | 1 + src/map/mod.rs | 1 + src/map/themes.rs | 4 ++++ 4 files changed, 35 insertions(+) create mode 100644 src/map/dungeon.rs diff --git a/src/map/dungeon.rs b/src/map/dungeon.rs new file mode 100644 index 0000000..df6611d --- /dev/null +++ b/src/map/dungeon.rs @@ -0,0 +1,29 @@ +use super::Map; +use serde::{Deserialize, Serialize}; +use std::collections::HashMap; + +#[derive(Default, Serialize, Deserialize, Clone)] +pub struct MasterDungeonMap { + maps: HashMap, +} + +impl MasterDungeonMap { + /// Initialises a blank MasterDungeonMap + pub fn new() -> MasterDungeonMap { + return MasterDungeonMap { maps: HashMap::new() }; + } + /// Stores the given map in the MasterDungeonMap + pub fn store_map(&mut self, map: &Map) { + self.maps.insert(map.id, map.clone()); + } + /// Gets a map by ID from the MasterDungeonMap + pub fn get_map(&self, id: i32) -> Option { + if self.maps.contains_key(&id) { + let mut result = self.maps[&id].clone(); + result.tile_content = vec![Vec::new(); (result.width * result.height) as usize]; + return Some(result); + } else { + return None; + } + } +} diff --git a/src/map/glyphs.rs b/src/map/glyphs.rs index 8bd0474..be16fe7 100644 --- a/src/map/glyphs.rs +++ b/src/map/glyphs.rs @@ -1,4 +1,5 @@ // DEFAULT THEME +#[allow(dead_code)] pub const WALL_GLYPH: char = '#'; pub const FLOOR_GLYPH: char = '.'; pub const DOWN_STAIR_GLYPH: char = '>'; diff --git a/src/map/mod.rs b/src/map/mod.rs index 31fcd3c..7142321 100644 --- a/src/map/mod.rs +++ b/src/map/mod.rs @@ -8,6 +8,7 @@ mod tiletype; pub use tiletype::{tile_cost, tile_opaque, tile_walkable, TileType}; mod interval_spawning_system; pub use interval_spawning_system::try_spawn_interval; +pub mod dungeon; pub mod themes; // FIXME: If the map size gets too small, entities stop being rendered starting from the right. diff --git a/src/map/themes.rs b/src/map/themes.rs index 071b4ed..fb294a1 100644 --- a/src/map/themes.rs +++ b/src/map/themes.rs @@ -26,7 +26,9 @@ pub fn get_tile_renderables_for_id(idx: usize, map: &Map) -> (rltk::FontCharType #[rustfmt::skip] pub fn get_default_theme_renderables(idx: usize, map: &Map) -> (rltk::FontCharType, RGB, RGB) { let glyph: rltk::FontCharType; + #[allow(unused_assignments)] let mut fg: RGB = RGB::new(); + #[allow(unused_assignments)] let mut bg: RGB = RGB::new(); match map.tiles[idx] { @@ -52,7 +54,9 @@ pub fn get_default_theme_renderables(idx: usize, map: &Map) -> (rltk::FontCharTy #[rustfmt::skip] fn get_forest_theme_renderables(idx:usize, map: &Map) -> (rltk::FontCharType, RGB, RGB) { let glyph; + #[allow(unused_assignments)] let mut fg = RGB::new(); + #[allow(unused_assignments)] let mut bg = RGB::new(); match map.tiles[idx] {