Skip to content

Commit

Permalink
Merge branch 'release/0.10.16' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
caewok committed Dec 21, 2024
2 parents 87956db + e8624d8 commit 061ad89
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 16 deletions.
7 changes: 7 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# 0.10.16
Potential fix for undefined when using `toNearest`. Closes #229.
Fix for incorrect move penalty displaying for 1:2:1 diagonals with Use Grid for Movement Penalties enabled. Closes #226, #218.
Wrap pathfinding in try/catch to avoid crashing the ruler. Closes #146.
Possible fix for tiny ruler labels. #205. May also address #225.
Fix for dnd5e v4 error re "inferred source" when moving tokens into regions with terrain effects. Closes #215. May also address #230.

# 0.10.15
Fix for multiple token dragging resulting in token moving through a wall. Closes #224.
Correct error with Pathfinding when Wall Height 6.1.0 is active. Pathfinding will now assume vaulting is enabled if Wall Height is present. Closes #223. Thanks @drcormier!
Expand Down
1 change: 1 addition & 0 deletions scripts/Ruler.js
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@ function _getSegmentLabel(wrapped, segment) {
// Use cost instead of straight distance for the label.
const origSegmentDistance = segment.distance;
const origTotalDistance = this.totalDistance;
segment.waypoint.cost ??= segment.distance || 0;
segment.distance = roundMultiple(segment.waypoint.cost);
this.totalDistance = this.totalCost;

Expand Down
3 changes: 2 additions & 1 deletion scripts/const.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export const FLAGS = {
export const OTHER_MODULES = {
TERRAIN_MAPPER: { KEY: "terrainmapper" },
LEVELS: { KEY: "levels" },
WALL_HEIGHT: { KEY: "wall-height" }
WALL_HEIGHT: { KEY: "wall-height" },
DAE: { KEY: "dae" }
};

// Hook init b/c game.modules is not initialized at start.
Expand Down
2 changes: 1 addition & 1 deletion scripts/geometry
22 changes: 14 additions & 8 deletions scripts/measurement/MovePenalty.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ export class MovePenalty {
*/
#moveTokenSpeed = 0;

get moveTokenSpeed() {
get moveTokenSpeed() {
return this.#moveTokenSpeed
|| (this.#moveTokenSpeed = SPEED.tokenSpeed(this.moveToken, this.movementType) || 1);
}
Expand Down Expand Up @@ -214,8 +214,10 @@ export class MovePenalty {
// Duplicate the token clone and add the region terrain(s).
const tClone = this.#localTokenClone.duplicate();
Terrain.addToTokenLocally(tClone, [...terrains.values()], { refresh: false });
// Does not work for DAE: tClone.actor.applyActiveEffects();
tClone.actor.prepareData(); // Slower but works with DAE.
if ( game.system.id === "dnd5e"
&& OTHER_MODULES.DAE.ACTIVE
&& !foundry.utils.isNewerVersion(game.system.version, "4") ) tClone.actor.prepareData(); // Slower; fails in v4.
else tClone.actor.applyActiveEffects(); // Does not work for DAE (at least in dnd5e v3).

// Determine the speed of the token clone and cache for future reference.
const speed = SPEED.tokenSpeed(tClone, this.movementType);
Expand Down Expand Up @@ -337,7 +339,10 @@ export class MovePenalty {

// Did we already test this coordinate?
const key = centerPt.key;
if ( this.#penaltyCache.has(key) ) return this.#penaltyCache.get(key);
if ( this.#penaltyCache.has(key) ) {
const { flatPenalty, gridMult } = this.#penaltyCache.get(key);
return (flatPenalty + (gridMult * costFreeDistance));
}

const regions = [...this.regions].filter(r => r.testPoint(centerPt, centerPt.elevation));
const tokens = [...this.tokens].filter(t => t.constrainedTokenBorder.contains(centerPt.x, centerPt.y)
Expand Down Expand Up @@ -375,7 +380,7 @@ export class MovePenalty {
const speedInGrid = (speed / currentMultiplier);
const gridMult = startingSpeed / speedInGrid; // If currentMultiplier > 1, gridMult should be > 1.
const res = (flatPenalty + (gridMult * costFreeDistance));
this.#penaltyCache.set(key, res);
this.#penaltyCache.set(key, { flatPenalty, gridMult });
return res;

/* Example
Expand Down Expand Up @@ -473,8 +478,6 @@ export class MovePenalty {
cutawayIxs.push(end2d);
cutawayIxs.sort((a, b) => a.x - b.x);


let speedFn;
// Add terrains currently on the token but keep the speed based on the non-terrain token.
let currRegions = [];
if ( testRegions ) {
Expand Down Expand Up @@ -529,7 +532,10 @@ export class MovePenalty {
ix = nextIx;
}

// console.debug(`_penaltiesForIntersections|${start.x},${start.y},${start.z} -> ${end.x},${end.y},${end.z}`, calcSteps, cutawayIxs);
/* Debug
console.debug(`_penaltiesForIntersections|${start.x},${start.y},${start.z}
-> ${end.x},${end.y},${end.z}`, calcSteps, cutawayIxs);
*/

// Determine the ratio compared to a set speed
const totalDefaultTime = totalUnmodifiedDistance / startingSpeed;
Expand Down
7 changes: 3 additions & 4 deletions scripts/segment_labels_highlighting.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,18 +287,17 @@ export function customizedTextLabel(ruler, segment, origLabel = "") {
function constructSecondaryLabel(segment, text, name) {
const labelStyles = CONFIG[MODULE_ID].labeling.styles;
const secondaryTextScale = CONFIG[MODULE_ID].labeling.secondaryTextScale;

const defaultStyle = labelStyles[name] ?? labelStyles.waypoint;
let textLabel = segment.label.getChildByName(name);
if ( !textLabel ) {
const style = labelStyles[name] ?? labelStyles.waypoint;
textLabel = new PreciseText("", style);
textLabel = new PreciseText("", defaultStyle.clone());
textLabel.name = name;
segment.label.addChild(textLabel);
if ( !textLabel.style.fontFamily.includes("fontAwesome") ) textLabel.style.fontFamily += ",fontAwesome";
}
textLabel.visible = true;
textLabel.text = text;
textLabel.style.fontSize = Math.round(segment.label.style.fontSize * secondaryTextScale);
textLabel.style.fontSize = Math.round(defaultStyle.fontSize * secondaryTextScale);
textLabel.anchor = { x: 0.5, y: 0.5 };
return textLabel;
}
Expand Down
10 changes: 8 additions & 2 deletions scripts/segments.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,14 @@ export function calculatePathPointsForSegment(segment, token) {
const t0 = performance.now();
token[MODULE_ID] ??= {};
const pf = token[MODULE_ID].pathfinder ??= new Pathfinder(token);
const path = pf.runPath(A, B);
let pathPoints = Pathfinder.getPathPoints(path);
let pathPoints = [];
try {
const path = pf.runPath(A, B);
pathPoints = Pathfinder.getPathPoints(path);
} catch (error) {
log(`calculatePathPointsForSegment|Error using pathfinding.`, path, error);
return [];
}
const t1 = performance.now();
log(`Found ${pathPoints.length} path points between ${A.x},${A.y} -> ${B.x},${B.y} in ${t1 - t0} ms.`, pathPoints);

Expand Down

0 comments on commit 061ad89

Please sign in to comment.