fix crash when completing level with a wide machine
This commit is contained in:
parent
187020fc27
commit
2a0483c156
2 changed files with 17 additions and 7 deletions
|
@ -2,6 +2,8 @@
|
||||||
Game store page: https://crispypin.itch.io/marble-machinations
|
Game store page: https://crispypin.itch.io/marble-machinations
|
||||||
|
|
||||||
## [unreleased]
|
## [unreleased]
|
||||||
|
### fixed
|
||||||
|
- broken area calculation causing crash when completing a level with a machine wider than it is tall
|
||||||
|
|
||||||
## v0.3.0 - 2025-04-04
|
## v0.3.0 - 2025-04-04
|
||||||
### added
|
### added
|
||||||
|
|
|
@ -124,9 +124,9 @@ impl Grid {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn used_bounds_area(&self) -> usize {
|
pub fn used_bounds_area(&self) -> usize {
|
||||||
let row_clear = |a, max, f: fn(usize, usize) -> (usize, usize)| {
|
let row_clear = |y| {
|
||||||
for b in 0..max {
|
for x in 0..self.width {
|
||||||
if !self.get_unchecked(f(a, b).into()).is_blank() {
|
if !self.get_unchecked((x, y).into()).is_blank() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -134,29 +134,37 @@ impl Grid {
|
||||||
};
|
};
|
||||||
let mut height = self.height;
|
let mut height = self.height;
|
||||||
for y in 0..self.height {
|
for y in 0..self.height {
|
||||||
if row_clear(y, self.width, |y, x| (x, y)) {
|
if row_clear(y) {
|
||||||
height -= 1;
|
height -= 1;
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for y in (0..self.height).rev() {
|
for y in (0..self.height).rev() {
|
||||||
if row_clear(y, self.width, |y, x| (x, y)) {
|
if row_clear(y) {
|
||||||
height -= 1;
|
height -= 1;
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
let col_clear = |x| {
|
||||||
|
for y in 0..self.height {
|
||||||
|
if !self.get_unchecked((x, y).into()).is_blank() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
true
|
||||||
|
};
|
||||||
let mut width = self.width;
|
let mut width = self.width;
|
||||||
for x in 0..self.width {
|
for x in 0..self.width {
|
||||||
if row_clear(x, self.height, |x, y| (x, y)) {
|
if col_clear(x) {
|
||||||
width -= 1;
|
width -= 1;
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for x in (0..self.width).rev() {
|
for x in (0..self.width).rev() {
|
||||||
if row_clear(x, self.width, |x, y| (x, y)) {
|
if col_clear(x) {
|
||||||
width -= 1;
|
width -= 1;
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Add table
Reference in a new issue