diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a2b8a0..f34f827 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/scripts/dungeon.js b/scripts/dungeon.js index db20cf9..2d9e6ed 100644 --- a/scripts/dungeon.js +++ b/scripts/dungeon.js @@ -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); diff --git a/scripts/geo-utils.js b/scripts/geo-utils.js index f818eea..045a706 100644 --- a/scripts/geo-utils.js +++ b/scripts/geo-utils.js @@ -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)); -}; \ No newline at end of file +}; + +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]; +};