Compare commits
No commits in common. "579d94bc036755a1cf698462a59b32d4512c6669" and "56884ead38f103f2600f945d8660bd6bed851fa2" have entirely different histories.
579d94bc03
...
56884ead38
|
@ -10,7 +10,7 @@ steps:
|
||||||
- cargo fmt --check
|
- cargo fmt --check
|
||||||
- cargo build --all
|
- cargo build --all
|
||||||
- cargo build --examples --all
|
- cargo build --examples --all
|
||||||
- cargo test --all
|
- cargo test --verbose --all
|
||||||
- cargo clippy
|
- cargo clippy
|
||||||
- name: release
|
- name: release
|
||||||
image: rust
|
image: rust
|
||||||
|
|
|
@ -15,5 +15,3 @@ rand = "0.8"
|
||||||
[package.metadata.release]
|
[package.metadata.release]
|
||||||
tag-prefix = ""
|
tag-prefix = ""
|
||||||
publish = false
|
publish = false
|
||||||
push = false
|
|
||||||
pre-release-hook = ["git-cliff", "-o", "CHANGELOG.md", "--tag", "{{version}}"]
|
|
|
@ -130,12 +130,12 @@ mod tests {
|
||||||
let gen = BspInterior::<NoData>::new();
|
let gen = BspInterior::<NoData>::new();
|
||||||
let map = gen.modify_map(&mut rng, &Map::new(80, 50));
|
let map = gen.modify_map(&mut rng, &Map::new(80, 50));
|
||||||
for i in 0..80 {
|
for i in 0..80 {
|
||||||
assert!(map.at(i, 0).unwrap().is_blocked());
|
assert!(map.at(i, 0).is_blocked());
|
||||||
assert!(map.at(i, 49).unwrap().is_blocked());
|
assert!(map.at(i, 49).is_blocked());
|
||||||
}
|
}
|
||||||
for j in 0..50 {
|
for j in 0..50 {
|
||||||
assert!(map.at(0, j).unwrap().is_blocked());
|
assert!(map.at(0, j).is_blocked());
|
||||||
assert!(map.at(79, j).unwrap().is_blocked());
|
assert!(map.at(79, j).is_blocked());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -150,12 +150,8 @@ impl<D: Clone + Default> BspRooms<D> {
|
||||||
if y < 1 {
|
if y < 1 {
|
||||||
can_build = false;
|
can_build = false;
|
||||||
}
|
}
|
||||||
if can_build {
|
if can_build && map.at(x as usize, y as usize).is_walkable() {
|
||||||
if let Some(tile) = map.at(x as usize, y as usize) {
|
can_build = false;
|
||||||
if tile.is_walkable() {
|
|
||||||
can_build = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -178,12 +174,12 @@ mod tests {
|
||||||
let gen = BspRooms::<NoData>::new();
|
let gen = BspRooms::<NoData>::new();
|
||||||
let map = gen.modify_map(&mut rng, &Map::new(80, 50));
|
let map = gen.modify_map(&mut rng, &Map::new(80, 50));
|
||||||
for i in 0..80 {
|
for i in 0..80 {
|
||||||
assert!(map.at(i, 0).unwrap().is_blocked());
|
assert!(map.at(i, 0).is_blocked());
|
||||||
assert!(map.at(i, 49).unwrap().is_blocked());
|
assert!(map.at(i, 49).is_blocked());
|
||||||
}
|
}
|
||||||
for j in 0..50 {
|
for j in 0..50 {
|
||||||
assert!(map.at(0, j).unwrap().is_blocked());
|
assert!(map.at(0, j).is_blocked());
|
||||||
assert!(map.at(79, j).unwrap().is_blocked());
|
assert!(map.at(79, j).is_blocked());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,7 +76,7 @@ fn apply_iteration<D: Clone + Default>(map: &Map<D>) -> Map<D> {
|
||||||
];
|
];
|
||||||
let neighbors = idxs
|
let neighbors = idxs
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|(x, y)| map.at(*x, *y).unwrap().is_blocked())
|
.filter(|(x, y)| map.at(*x, *y).is_blocked())
|
||||||
.count();
|
.count();
|
||||||
|
|
||||||
if neighbors > 4 || neighbors == 0 {
|
if neighbors > 4 || neighbors == 0 {
|
||||||
|
@ -103,7 +103,7 @@ mod tests {
|
||||||
fn test_iteration_wal() {
|
fn test_iteration_wal() {
|
||||||
let map = Map::<NoData>::new(3, 3);
|
let map = Map::<NoData>::new(3, 3);
|
||||||
let new_map = apply_iteration(&map);
|
let new_map = apply_iteration(&map);
|
||||||
assert!(new_map.at(1, 1).unwrap().is_blocked());
|
assert!(new_map.at(1, 1).is_blocked());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -115,6 +115,6 @@ mod tests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let new_map = apply_iteration(&map);
|
let new_map = apply_iteration(&map);
|
||||||
assert!(new_map.at(1, 1).unwrap().is_walkable());
|
assert!(new_map.at(1, 1).is_walkable());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
40
src/map.rs
40
src/map.rs
|
@ -112,9 +112,13 @@ impl<D: Clone + Default> Map<D> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get TileType at the given location
|
/// Get TileType at the given location
|
||||||
pub fn at(&self, x: usize, y: usize) -> Option<&Tile> {
|
pub fn at(&self, x: usize, y: usize) -> Tile {
|
||||||
let idx = (y as usize) * self.width + (x as usize);
|
if x >= self.width || y >= self.height {
|
||||||
self.tiles.get(idx)
|
Tile::wall()
|
||||||
|
} else {
|
||||||
|
let idx = (y as usize) * self.width + (x as usize);
|
||||||
|
self.tiles[idx]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get available exists from the given tile
|
/// Get available exists from the given tile
|
||||||
|
@ -154,11 +158,7 @@ impl<D: Clone + Default> Map<D> {
|
||||||
|
|
||||||
// Check if given tile can be accessed
|
// Check if given tile can be accessed
|
||||||
fn is_exit_valid(&self, x: usize, y: usize) -> bool {
|
fn is_exit_valid(&self, x: usize, y: usize) -> bool {
|
||||||
if let Some(tile) = self.at(x, y) {
|
!self.at(x, y).is_blocked
|
||||||
!tile.is_blocked
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Modify tile at the given location
|
/// Modify tile at the given location
|
||||||
|
@ -200,11 +200,9 @@ impl<D: Clone + Default> Map<D> {
|
||||||
y -= 1;
|
y -= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(tile) = self.at(x, y) {
|
if self.at(x, y).is_blocked {
|
||||||
if tile.is_blocked {
|
corridor.push(Point::new(x, y));
|
||||||
corridor.push(Point::new(x, y));
|
self.set_tile(x, y, Tile::floor());
|
||||||
self.set_tile(x, y, Tile::floor());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -276,7 +274,7 @@ impl<D: Clone + Default> fmt::Display for Map<D> {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
for y in 0..self.height {
|
for y in 0..self.height {
|
||||||
let bytes: Vec<u8> = (0..self.width)
|
let bytes: Vec<u8> = (0..self.width)
|
||||||
.map(|x| if self.at(x, y).unwrap().is_blocked { '#' } else { ' ' } as u8)
|
.map(|x| if self.at(x, y).is_blocked { '#' } else { ' ' } as u8)
|
||||||
.collect();
|
.collect();
|
||||||
let line = String::from_utf8(bytes).expect("Can't convert map to string");
|
let line = String::from_utf8(bytes).expect("Can't convert map to string");
|
||||||
let _ = writeln!(f, "{}", line);
|
let _ = writeln!(f, "{}", line);
|
||||||
|
@ -297,7 +295,7 @@ mod tests {
|
||||||
let map = Map::<NoData>::new(10, 10);
|
let map = Map::<NoData>::new(10, 10);
|
||||||
for i in 0..10 {
|
for i in 0..10 {
|
||||||
for j in 0..10 {
|
for j in 0..10 {
|
||||||
assert!(map.at(i, j).unwrap().is_blocked);
|
assert!(map.at(i, j).is_blocked);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -314,12 +312,12 @@ mod tests {
|
||||||
assert_eq!(map.width, 10);
|
assert_eq!(map.width, 10);
|
||||||
assert_eq!(map.height, 3);
|
assert_eq!(map.height, 3);
|
||||||
for i in 0..10 {
|
for i in 0..10 {
|
||||||
assert!(map.at(i, 0).unwrap().is_blocked);
|
assert!(map.at(i, 0).is_blocked);
|
||||||
assert!(map.at(i, 2).unwrap().is_blocked);
|
assert!(map.at(i, 2).is_blocked);
|
||||||
if i == 0 || i == 9 {
|
if i == 0 || i == 9 {
|
||||||
assert!(map.at(i, 1).unwrap().is_blocked);
|
assert!(map.at(i, 1).is_blocked);
|
||||||
} else {
|
} else {
|
||||||
assert!(map.at(i, 1).unwrap().is_walkable());
|
assert!(map.at(i, 1).is_walkable());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -345,9 +343,9 @@ mod tests {
|
||||||
for x in 0..map.width {
|
for x in 0..map.width {
|
||||||
for y in 0..map.height {
|
for y in 0..map.height {
|
||||||
if x == 0 || y == 0 || x == 4 || y == 4 {
|
if x == 0 || y == 0 || x == 4 || y == 4 {
|
||||||
assert!(map.at(x, y).unwrap().is_blocked);
|
assert!(map.at(x, y).is_blocked);
|
||||||
} else {
|
} else {
|
||||||
assert!(map.at(x, y).unwrap().is_walkable());
|
assert!(map.at(x, y).is_walkable());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user