diff --git a/src/exploration.rs b/src/exploration.rs index c73765d..f492507 100644 --- a/src/exploration.rs +++ b/src/exploration.rs @@ -284,9 +284,9 @@ fn exploration_focus( } if orig != exploring && exploring.0 >= 0. - && exploring.0 < map.width() as f32 + && exploring.0 < map.width as f32 && exploring.1 >= 0. - && exploring.1 < map.height() as f32 + && exploring.1 < map.height as f32 { commands.entity(entity).insert(Exploring(exploring)); } @@ -308,7 +308,7 @@ fn navigate_to_explored( for (entity, exploring) in explorers.iter() { for (map, revealed_tiles) in map.iter() { let point = **exploring; - let idx = point.to_index(map.width()); + let idx = point.to_index(map.width); let known = revealed_tiles[idx]; if input.just_active(navigate_to_explored.clone()) && known { commands @@ -338,7 +338,7 @@ fn exploration_changed_announcement( let coordinates = (coordinates.0.floor(), coordinates.1.floor()); for (map, revealed_tiles, visible_tiles) in map.iter() { let point = **exploring; - let idx = point.to_index(map.width()); + let idx = point.to_index(map.width); let shape = Cuboid::new(Vec2::new(0.5, 0.5).into()); let known = revealed_tiles[idx]; let visible = visible_tiles[idx]; @@ -374,7 +374,7 @@ fn exploration_changed_announcement( }, ); if tokens.is_empty() { - match map.base.tiles[idx] { + match map.tiles[idx] { TileType::Floor => "Floor".to_string(), TileType::Wall => "Wall".to_string(), } diff --git a/src/map.rs b/src/map.rs index 1fc5b0a..f7595d2 100644 --- a/src/map.rs +++ b/src/map.rs @@ -3,7 +3,8 @@ use std::collections::{HashMap, HashSet}; use bevy::prelude::*; use bevy_rapier2d::prelude::*; use derive_more::{Deref, DerefMut}; -use mapgen::{geometry::Rect as MRect, Map as MapgenMap, MapFilter, TileType}; +pub use mapgen::Map; +use mapgen::{geometry::Rect as MRect, MapFilter, TileType}; use maze_generator::{prelude::*, recursive_backtracking::RbGenerator}; use rand::prelude::StdRng; @@ -26,38 +27,6 @@ pub struct Areas(pub Vec); #[reflect(Component)] pub struct Portal; -#[derive(Clone, Default)] -pub struct Map { - pub base: MapgenMap, -} - -impl Map { - pub fn new(base: MapgenMap) -> Self { - let count = (base.width * base.height) as usize; - Self { base } - } - - pub fn width(&self) -> usize { - self.base.width - } - - pub fn height(&self) -> usize { - self.base.height - } - - pub fn count(&self) -> usize { - self.width() * self.height() - } - - pub fn start(&self) -> Option { - self.base.starting_point - } - - pub fn exit(&self) -> Option { - self.base.exit_point - } -} - pub trait ITileType { fn blocks_motion(&self) -> bool; fn blocks_visibility(&self) -> bool; @@ -153,7 +122,7 @@ impl GridBuilder { } impl MapFilter for GridBuilder { - fn modify_map(&self, _rng: &mut StdRng, map: &MapgenMap) -> MapgenMap { + fn modify_map(&self, _rng: &mut StdRng, map: &Map) -> Map { let mut map = map.clone(); let mut generator = RbGenerator::new(None); let maze = generator.generate(self.width_in_rooms as i32, self.height_in_rooms as i32); @@ -210,9 +179,9 @@ fn add_map_colliders(mut commands: Commands, maps: Query<(Entity, &Map), Added = vec![]; - for x in 1..map.width() { - for y in 1..map.height() { + for x in 1..map.width { + for y in 1..map.height { let mut spawn_portal = false; - if map.base.get_available_exits(x, y).len() > 2 { - let idx = (x, y).to_index(map.width()); - if map.base.tiles[idx] == TileType::Floor - && (x > 1 && map.base.tiles[idx - 1] == TileType::Floor) - && (x < map.width() - 2 && map.base.tiles[idx + 1] == TileType::Floor) - && (y > 1 - && map.base.tiles[idx - map.width() as usize] == TileType::Wall) - && (y < map.height() - 2 - && map.base.tiles[idx + map.width() as usize] == TileType::Wall) + if map.get_available_exits(x, y).len() > 2 { + let idx = (x, y).to_index(map.width); + if map.tiles[idx] == TileType::Floor + && (x > 1 && map.tiles[idx - 1] == TileType::Floor) + && (x < map.width - 2 && map.tiles[idx + 1] == TileType::Floor) + && (y > 1 && map.tiles[idx - map.width] == TileType::Wall) + && (y < map.height - 2 && map.tiles[idx + map.width] == TileType::Wall) { spawn_portal = true; } - if map.base.tiles[idx] == TileType::Floor - && (x > 1 && map.base.tiles[idx - 1] == TileType::Wall) - && (x < map.width() - 2 && map.base.tiles[idx + 1] == TileType::Wall) - && (y > 1 - && map.base.tiles[idx - map.width() as usize] == TileType::Floor) - && (y < map.height() - 2 - && map.base.tiles[idx + map.width() as usize] == TileType::Floor) + if map.tiles[idx] == TileType::Floor + && (x > 1 && map.tiles[idx - 1] == TileType::Wall) + && (x < map.width - 2 && map.tiles[idx + 1] == TileType::Wall) + && (y > 1 && map.tiles[idx - map.width] == TileType::Floor) + && (y < map.height - 2 && map.tiles[idx + map.width] == TileType::Floor) { spawn_portal = true; } @@ -357,7 +322,7 @@ fn area_description( fn add_areas(mut commands: Commands, query: Query<(Entity, &Map), (Added, Without)>) { for (entity, map) in query.iter() { let mut v = vec![]; - for room in &map.base.rooms { + for room in &map.rooms { v.push(Area { rect: *room, description: None, diff --git a/src/pathfinding.rs b/src/pathfinding.rs index 51a184f..129742b 100644 --- a/src/pathfinding.rs +++ b/src/pathfinding.rs @@ -31,7 +31,7 @@ pub fn find_path( &start.into(), |p| { let mut successors: Vec<((i32, i32), u32)> = vec![]; - for tile in map.base.get_available_exits(p.0 as usize, p.1 as usize) { + for tile in map.get_available_exits(p.0 as usize, p.1 as usize) { successors.push(((tile.0 as i32, tile.1 as i32), (tile.2 * 100.) as u32)); } successors diff --git a/src/sound.rs b/src/sound.rs index f873242..745ebc7 100644 --- a/src/sound.rs +++ b/src/sound.rs @@ -163,10 +163,10 @@ fn sound_icon( ) where S: Component + Clone + Debug + Eq + Hash, { - if !(*config).sound_icon_states.is_empty() { - if !config.sound_icon_states.contains(state.current()) { - return; - } + if !(*config).sound_icon_states.is_empty() + && !config.sound_icon_states.contains(state.current()) + { + return; } for viewer in viewers.iter() { for (mut icon, coordinates, parent, mut sound) in icons.iter_mut() { diff --git a/src/visibility.rs b/src/visibility.rs index bb322fe..508d888 100644 --- a/src/visibility.rs +++ b/src/visibility.rs @@ -55,7 +55,7 @@ fn add_visibility_indices( map_config: Res, ) { for (entity, map) in query.iter() { - let count = map.count(); + let count = map.width * map.height; commands .entity(entity) .insert(VisibleTiles(vec![false; count])); @@ -76,7 +76,7 @@ where type Opacity = u8; fn size(&self, grid: &Self::Grid) -> Size { - Size::new(grid.0.width() as u32, grid.0.height() as u32) + Size::new(grid.0.width as u32, grid.0.height as u32) } fn get_opacity(&self, _grid: &Self::Grid, coord: Coord) -> Self::Opacity { @@ -139,7 +139,7 @@ fn update_visible_and_revealed_tiles( *t = false } for v in viewshed.visible.iter() { - let idx = v.to_index(map.width()); + let idx = v.to_index(map.width); revealed_tiles[idx] = true; visible_tiles[idx] = true; }