Skip to content

Commit

Permalink
Make sure we use ordered lesser/greater points when splitting interio…
Browse files Browse the repository at this point in the history
…r walls with doors.
  • Loading branch information
mcglincy committed Nov 22, 2021
1 parent a10cd5d commit 4104520
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 7 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# 0.9.0
- Adding a rectangle alongside an existing room/wall will now preserve the interior wall.
- Adding a door within an interior wall will now split the interior wall.
- Add interior shadow on all exterior walls, interior walls, and doors.
- Reorganize floor/shadow/wall render and graphics objects for better layering and to fix some visual artifacts.
- Draw interior shadows for on all exterior walls, interior walls, and doors.
- Reorganize floor/shadow/wall render and graphics objects for better layering and to fix some shadow overlap issues.
- Fix code typo causing render errors.

# 0.8.0
- Allow Trusted Players to use Dungeon Draw tools. NOTE: updating lighting walls and scene settings still needs GM permissions. You may also need to give Trusted Player owner permissions to GM-created dungeon Journal Entries to allow editing.
Expand Down
12 changes: 8 additions & 4 deletions scripts/dungeon.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,14 @@ export class Dungeon extends PlaceableObject {
wallsToDelete.push(wall);
// TODO: how should we handle coordinate ordering? Does JTS do this for us?
// TODO: apparently not, and we have to do the reordering ourselves
const wallCoords = wallPoly.getCoordinates();
const doorCoords = doorPoly.getCoordinates();
wallsToAdd.push([wallCoords[0].x, wallCoords[0].y, doorCoords[0].x, doorCoords[0].y]);
wallsToAdd.push([doorCoords[1].x, doorCoords[1].y, wallCoords[1].x, wallCoords[1].y]);

const w1 = geo.lesserPoint(wall[0], wall[1], wall[2], wall[3]);
const w2 = geo.greaterPoint(wall[0], wall[1], wall[2], wall[3]);
const d1 = geo.lesserPoint(x1, y1, x2, y2);
const d2 = geo.greaterPoint(x1, y1, x2, y2);

wallsToAdd.push([w1[0], w1[1], d1[0], d1[1]]);
wallsToAdd.push([d2[0], d2[1], w2[0], w2[1]]);
}
}
newState.interiorWalls = newState.interiorWalls.filter(w => wallsToDelete.indexOf(w) === -1);
Expand Down
29 changes: 28 additions & 1 deletion scripts/geo-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,31 @@ export const inverseSlope = (slope) => {

export const distanceBetweenPoints = (x1, y1, x2, y2) => {
return Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
};
};

export const comparePoints = (x1, y1, x2, y2) => {
if (x1 < x2 || (x1 === x2 && y1 < y2)) {
// less than
return -1;
} else if (x1 === x2 && y1 === y2) {
// equal
return 0;
} else {
// greater than
return 1;
}
};

export const lesserPoint = (x1, y1, x2, y2) => {
if (comparePoints(x1, y1, x2, y2) === -1) {
return [x1, y1];
}
return [x2, y2];
};

export const greaterPoint = (x1, y1, x2, y2) => {
if (comparePoints(x1, y1, x2, y2) !== -1) {
return [x1, y1];
}
return [x2, y2];
};

0 comments on commit 4104520

Please sign in to comment.