mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-03-07 06:26:13 +01:00
Compare commits
2 commits
c2ea68ea77
...
c0451ee023
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c0451ee023 | ||
|
|
5dfc678561 |
1 changed files with 21 additions and 16 deletions
|
|
@ -54,21 +54,22 @@ export default class DhTokenPlaceable extends foundry.canvas.placeables.Token {
|
|||
if (this === target) return 0;
|
||||
|
||||
const originPoint = this.center;
|
||||
const destinationPoint = target.center;
|
||||
const targetPoint = target.center;
|
||||
const thisBounds = this.bounds;
|
||||
const targetBounds = target.bounds;
|
||||
|
||||
// Figure out the elevation difference
|
||||
// Figure out the elevation difference.
|
||||
// This intends to return "grid distance" for adjacent ones, so we add that number if not overlapping.
|
||||
const sizePerUnit = canvas.grid.size / canvas.grid.distance;
|
||||
const thisHeight = Math.max(thisBounds.width, thisBounds.height) / sizePerUnit;
|
||||
const targetHeight = Math.max(targetBounds.width, targetBounds.height) / sizePerUnit;
|
||||
const thisElevation = [this.document.elevation, this.document.elevation + thisHeight];
|
||||
const targetElevation = [target.document.elevation, target.document.elevation + targetHeight];
|
||||
const isSameAltitude =
|
||||
thisElevation[0] <= targetElevation[1] && // bottom of this must be at or below the top of target
|
||||
thisElevation[1] >= targetElevation[0]; // top of this must be at or above the bottom of target
|
||||
thisElevation[0] < targetElevation[1] && // bottom of this must be at or below the top of target
|
||||
thisElevation[1] > targetElevation[0]; // top of this must be at or above the bottom of target
|
||||
const [lower, higher] = [targetElevation, thisElevation].sort((a, b) => a[1] - b[1]);
|
||||
const elevation = isSameAltitude ? 0 : higher[0] - lower[1];
|
||||
const elevation = isSameAltitude ? 0 : higher[0] - lower[1] + canvas.grid.distance;
|
||||
|
||||
// Compute for gridless. This version returns circular edge to edge + grid distance,
|
||||
// so that tokens that are touching return 5.
|
||||
|
|
@ -78,22 +79,26 @@ export default class DhTokenPlaceable extends foundry.canvas.placeables.Token {
|
|||
const targetRadius = (targetBounds.width * boundsCorrection) / 2;
|
||||
const distance = canvas.grid.measurePath([
|
||||
{ ...originPoint, elevation: 0 },
|
||||
{ ...destinationPoint, elevation }
|
||||
{ ...targetPoint, elevation }
|
||||
]).distance;
|
||||
return Math.floor(distance - originRadius - targetRadius + canvas.grid.distance);
|
||||
}
|
||||
|
||||
// Compute what the closest grid space of each token is, then compute that distance
|
||||
const originEdge = this.#getEdgeBoundary(thisBounds, originPoint, destinationPoint);
|
||||
const targetEdge = this.#getEdgeBoundary(targetBounds, originPoint, destinationPoint);
|
||||
const adjustedOriginPoint = canvas.grid.getTopLeftPoint({
|
||||
const originEdge = this.#getEdgeBoundary(thisBounds, originPoint, targetPoint);
|
||||
const targetEdge = this.#getEdgeBoundary(targetBounds, originPoint, targetPoint);
|
||||
const adjustedOriginPoint = originEdge
|
||||
? canvas.grid.getTopLeftPoint({
|
||||
x: originEdge.x + Math.sign(originPoint.x - originEdge.x),
|
||||
y: originEdge.y + Math.sign(originPoint.y - originEdge.y)
|
||||
});
|
||||
const adjustDestinationPoint = canvas.grid.getTopLeftPoint({
|
||||
x: targetEdge.x + Math.sign(destinationPoint.x - targetEdge.x),
|
||||
y: targetEdge.y + Math.sign(destinationPoint.y - targetEdge.y)
|
||||
});
|
||||
})
|
||||
: originPoint;
|
||||
const adjustDestinationPoint = targetEdge
|
||||
? canvas.grid.getTopLeftPoint({
|
||||
x: targetEdge.x + Math.sign(targetPoint.x - targetEdge.x),
|
||||
y: targetEdge.y + Math.sign(targetPoint.y - targetEdge.y)
|
||||
})
|
||||
: targetPoint;
|
||||
return canvas.grid.measurePath([
|
||||
{ ...adjustedOriginPoint, elevation: 0 },
|
||||
{ ...adjustDestinationPoint, elevation }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue