Bump edition and appease Clippy.
This commit is contained in:
parent
a49e9d019b
commit
0d5624fe4c
|
@ -8,7 +8,7 @@ license = "MIT OR Apache-2.0"
|
|||
repository = "https://github.com/klangner/mapgen.rs"
|
||||
homepage = "https://github.com/klangner/mapgen.rs"
|
||||
documentation = "https://docs.rs/mapgen"
|
||||
edition = "2018"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
rand = "0.8"
|
||||
|
|
|
@ -49,8 +49,7 @@ impl<D: Clone + Default> BspInterior<D> {
|
|||
|
||||
fn build(&self, rng: &mut StdRng, map: &Map<D>) -> Map<D> {
|
||||
let mut new_map = map.clone();
|
||||
let mut rects: Vec<Rect> = Vec::new();
|
||||
rects.push(Rect::new(1, 1, new_map.width - 2, new_map.height - 2));
|
||||
let mut rects = vec![Rect::new(1, 1, new_map.width - 2, new_map.height - 2)];
|
||||
let first_room = rects[0];
|
||||
// Divide the first room
|
||||
self.add_subrects(first_room, rng, &mut rects);
|
||||
|
|
|
@ -47,9 +47,8 @@ impl<D: Clone + Default> BspRooms<D> {
|
|||
|
||||
fn build_rooms(&self, map: &Map<D>, rng: &mut StdRng) -> Map<D> {
|
||||
let mut new_map = map.clone();
|
||||
let mut rects: Vec<Rect> = Vec::new();
|
||||
// Start with a single map-sized rectangle
|
||||
rects.push(Rect::new(2, 2, new_map.width - 5, new_map.height - 5));
|
||||
let mut rects = vec![Rect::new(2, 2, new_map.width - 5, new_map.height - 5)];
|
||||
let first_room = rects[0];
|
||||
rects.append(&mut self.split_into_subrects(first_room)); // Divide the first room
|
||||
|
||||
|
@ -98,7 +97,7 @@ impl<D: Clone + Default> BspRooms<D> {
|
|||
rects
|
||||
}
|
||||
|
||||
fn get_random_rect(&self, rng: &mut StdRng, rects: &Vec<Rect>) -> Rect {
|
||||
fn get_random_rect(&self, rng: &mut StdRng, rects: &[Rect]) -> Rect {
|
||||
if rects.len() == 1 {
|
||||
return rects[0];
|
||||
}
|
||||
|
|
|
@ -114,6 +114,6 @@ mod tests {
|
|||
|
||||
assert_eq!(map.width, 80);
|
||||
assert_eq!(map.height, 50);
|
||||
assert_eq!(map.starting_point.is_some(), true);
|
||||
assert!(map.starting_point.is_some());
|
||||
}
|
||||
}
|
||||
|
|
13
src/map.rs
13
src/map.rs
|
@ -84,11 +84,12 @@ impl<D: Clone + Default> Map<D> {
|
|||
}
|
||||
|
||||
/// Create map from given string
|
||||
#[allow(clippy::needless_range_loop)]
|
||||
pub fn from_string(map_string: &str) -> Map<D> {
|
||||
let lines: Vec<&str> = map_string
|
||||
.split("\n")
|
||||
.split('\n')
|
||||
.map(|l| l.trim())
|
||||
.filter(|l| l.len() > 0)
|
||||
.filter(|l| !l.is_empty())
|
||||
.collect();
|
||||
let cols = lines
|
||||
.iter()
|
||||
|
@ -157,7 +158,7 @@ impl<D: Clone + Default> Map<D> {
|
|||
|
||||
// Check if given tile can be accessed
|
||||
fn is_exit_valid(&self, x: usize, y: usize) -> bool {
|
||||
self.at(x, y).is_blocked == false
|
||||
!self.at(x, y).is_blocked
|
||||
}
|
||||
|
||||
/// Modify tile at the given location
|
||||
|
@ -276,7 +277,7 @@ impl<D: Clone + Default> fmt::Display for Map<D> {
|
|||
.map(|x| if self.at(x, y).is_blocked { '#' } else { ' ' } as u8)
|
||||
.collect();
|
||||
let line = String::from_utf8(bytes).expect("Can't convert map to string");
|
||||
let _ = write!(f, "{}\n", line);
|
||||
let _ = writeln!(f, "{}", line);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -316,7 +317,7 @@ mod tests {
|
|||
if i == 0 || i == 9 {
|
||||
assert!(map.at(i, 1).is_blocked);
|
||||
} else {
|
||||
assert!(map.at(i, 1).is_blocked == false);
|
||||
assert!(map.at(i, 1).is_walkable());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -344,7 +345,7 @@ mod tests {
|
|||
if x == 0 || y == 0 || x == 4 || y == 4 {
|
||||
assert!(map.at(x, y).is_blocked);
|
||||
} else {
|
||||
assert!(map.at(x, y).is_blocked == false);
|
||||
assert!(map.at(x, y).is_walkable());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ mod tests {
|
|||
fn test_range() {
|
||||
let mut rng = StdRng::seed_from_u64(100);
|
||||
let x = rng.random_range(5, 8);
|
||||
assert!(x >= 5 && x < 8);
|
||||
assert!((5..8).contains(&x));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Reference in New Issue
Block a user