Skip to content

Commit

Permalink
Make remove-doors-and-walls tool also delete secret doors.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcglincy committed Dec 1, 2021
1 parent 32260d6 commit 9e71adc
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions scripts/dungeon.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { DungeonDraw } from "./dungeondraw.js";
import { DungeonLayer } from "./dungeonlayer.js";
import { DungeonState } from "./dungeonstate.js";
import { render } from "./renderer.js";
import * as geo from "./geo-utils.js";
Expand Down Expand Up @@ -219,13 +217,20 @@ export class Dungeon extends PlaceableObject {
const doorPoly = geo.twoPointsToLineString(d[0], d[1], d[2], d[3]);
return !rectPoly.intersects(doorPoly);
});
const secretDoorsToKeep = oldState.secretDoors.filter(d => {
const doorPoly = geo.twoPointsToLineString(d[0], d[1], d[2], d[3]);
return !rectPoly.intersects(doorPoly);
});
const wallsToKeep = oldState.interiorWalls.filter(w => {
const wallPoly = geo.twoPointsToLineString(w[0], w[1], w[2], w[3]);
return !rectPoly.intersects(wallPoly);
});
if (doorsToKeep.length != oldState.doors.length || wallsToKeep.length != oldState.interiorWalls.length) {
if (doorsToKeep.length != oldState.doors.length
|| secretDoorsToKeep.length != oldState.secretDoors.length
|| wallsToKeep.length != oldState.interiorWalls.length) {
const newState = oldState.clone();
newState.doors = doorsToKeep;
newState.secretDoors = secretDoorsToKeep;
newState.interiorWalls = wallsToKeep;
await this.pushState(newState);
}
Expand Down

0 comments on commit 9e71adc

Please sign in to comment.