Ceremonial PR: fix map gen (#39)
improve errors merge state debug dumper use detailed debugging in map gen more distinct wall chars not all sealed walls are walls. okay handle negative region IDs also catches some missed semis stop using the "dark shade" character for standard walls now uses inverse bullet for sealed walls and full block otherwise also show final result with region numbers fix fencepost error when merging regions map connectedness checker (floodfill) check for connectedness in mapgen add commented-out cheat and test buttons looks like mapgen is now fixed. here are the buttons I used to test it autoformat code Merge branch 'main' into fix-mapgen Co-authored-by: Kistaro Windrider <kistaro@gmail.com> Reviewed-on: #39
This commit is contained in:
@ -111,6 +111,15 @@ export class Point {
|
||||
let dy = other.y - this.y;
|
||||
return Math.sqrt(dx * dx + dy * dy);
|
||||
}
|
||||
|
||||
neighbors(): Point[] {
|
||||
return [
|
||||
new Point(this.x, this.y - 1),
|
||||
new Point(this.x - 1, this.y),
|
||||
new Point(this.x, this.y + 1),
|
||||
new Point(this.x + 1, this.y),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
export class Size {
|
||||
@ -264,19 +273,29 @@ export class Grid<T> {
|
||||
return new Grid(this.size, (xy) => cbCell(this.get(xy), xy));
|
||||
}
|
||||
|
||||
#checkPosition(position: Point) {
|
||||
if (
|
||||
#invalidPosition(position: Point): boolean {
|
||||
return (
|
||||
position.x < 0 ||
|
||||
position.x >= this.size.w ||
|
||||
Math.floor(position.x) != position.x ||
|
||||
position.y < 0 ||
|
||||
position.y >= this.size.h ||
|
||||
Math.floor(position.y) != position.y
|
||||
) {
|
||||
);
|
||||
}
|
||||
#checkPosition(position: Point) {
|
||||
if (this.#invalidPosition(position)) {
|
||||
throw new Error(`invalid position for ${this.size}: ${position}`);
|
||||
}
|
||||
}
|
||||
|
||||
maybeGet(position: Point): T | null {
|
||||
if (this.#invalidPosition(position)) {
|
||||
return null;
|
||||
}
|
||||
return this.#data[position.y][position.x];
|
||||
}
|
||||
|
||||
get(position: Point): T {
|
||||
this.#checkPosition(position);
|
||||
return this.#data[position.y][position.x];
|
||||
|
Reference in New Issue
Block a user