Skip to content

Commit

Permalink
Merge branch 'release/0.10.13' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
caewok committed Oct 6, 2024
2 parents 51f9310 + 8543121 commit e4dd1e4
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 235 deletions.
4 changes: 4 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.10.13
Use a cached map to track move penalties for different region combinations. Improves compatibility with DAE while not severely impacting performance. Addresses #209.
Use a mixed wrap instead of override for `Ruler#_computeDistance`, which improves compatibility with some systems, like dnd4e. Closes #213.

# 0.10.12
Fixes for calculating movement penalty in drawings.
Avoid displaying the default ruler label in some situations when using the custom label. Closes issue #212.
Expand Down
46 changes: 12 additions & 34 deletions scripts/Ruler.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,46 +397,22 @@ function _getMeasurementSegments(wrapped) {
}

/**
* Override Ruler.prototype._computeDistance
* Mixed wrap Ruler.prototype._computeDistance
* Pass 3d coordinates to measure.
* Determine the distance with and without the cost function so movement due to terrain can be calculated.
* If token not present or Terrain Mapper not active, this will be the same as segment distance.
*/
function _computeDistance() {
// If not this ruler's user, use the segments already calculated and passed via socket.
if ( this.user !== game.user ) return;

function _computeDistance(wrapped) {
log("_computeDistance");

// Debugging
const debug = CONFIG[MODULE_ID].debug;
if ( debug && this.segments.some(s => !s) ) console.error("Segment is undefined.");

// Determine the distance of each segment.
// _computeSegmentDistances.call(this);

if ( debug ) {
switch ( this.segments.length ) {
case 1: break;
case 2: break;
case 3: break;
case 4: break;
case 5: break;
case 6: break;
case 7: break;
case 8: break;
case 9: break;
}
}
// If not this ruler's user, use the segments already calculated and passed via socket.
if ( this.user !== game.user ) return;

// Debugging
if ( debug && this.segments.some(s => !s) ) console.error("Segment is undefined.");
wrapped();

// From Ruler#_computeDistance
// Changes:
// - 3d path.
// - Add the offsetDistance property for determining changes due to terrain.
// - Calculate distance properties from nearest waypoint, for labeling.
// Unfortunately, need to redo the measurement.
// Primarily b/c the cost and labeling needs the offsetDistance from the measurement.
// Add in the 3d points.
const Point3d = CONFIG.GeometryLib.threeD.Point3d;
let path = [];
if ( this.segments.length ) path.push(Point3d.fromObject(this.segments[0].ray.A));
Expand All @@ -446,6 +422,8 @@ function _computeDistance() {
path.push(B);
}
const measurements = canvas.grid.measurePath(path, {cost: this._getCostFunction()}).segments;

// Redo the properties for the segments.
this.totalDistance = 0;
this.totalCost = 0;
this.totalOffsetDistance = 0;
Expand Down Expand Up @@ -819,9 +797,9 @@ PATCHES.BASIC.WRAPS = {
_onMoveKeyDown
};

PATCHES.BASIC.MIXES = { _getMeasurementSegments, _broadcastMeasurement };
PATCHES.BASIC.MIXES = { _getMeasurementSegments, _broadcastMeasurement, _computeDistance };

PATCHES.BASIC.OVERRIDES = { _addWaypoint, _computeDistance };
PATCHES.BASIC.OVERRIDES = { _addWaypoint };

PATCHES.SPEED_HIGHLIGHTING.WRAPS = { _highlightMeasurementSegment };

Expand Down
13 changes: 0 additions & 13 deletions scripts/const.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,16 +139,3 @@ SPEED.tokenSpeed = function(token, movementType) {
if ( speed === null ) return null;
return Number(speed);
};

/**
* Temporarily set the speed attribute for a token. Only sets locally; does not hit the database.
* @param {number} value Speed to set
* @param {Token} token Token on which to set the speed property
* @param {MOVEMENT_TYPES} [movementType] Type of movement; if omitted automatically determined
*/
SPEED.setTokenSpeed = function(value, token, movementType) {
movementType ??= token.movementType;
const key = SPEED.ATTRIBUTES[keyForValue(MOVEMENT_TYPES, movementType)];
if ( !key ) return
foundry.utils.setProperty(token, key, value);
}
2 changes: 1 addition & 1 deletion scripts/geometry
Loading

0 comments on commit e4dd1e4

Please sign in to comment.