Skip to content

Commit

Permalink
Merge branch 'release/0.10.3' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
caewok committed Aug 23, 2024
2 parents 80f3248 + 6e55e4f commit 742b5bf
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 40 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.3
Fix for the ruler label blowing up the font size on gridless and hex scenes.
Fix for gridless measuring in pixel units instead of grid units.

# 0.10.2

## New Features
Expand Down
8 changes: 7 additions & 1 deletion scripts/Ruler.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,12 @@ function _getMeasurementSegments(wrapped) {

// No segments are present if dragging back to the origin point.
const segments = wrapped();

// Make sure the style is cloned for each segment b/c we are adjusting the size.
if ( Settings.get(Settings.KEYS.LABELING.SCALE_TEXT) ) {
segments.forEach(segment => segment.label.style = segment.label.style.clone())
}

const segmentMap = this._pathfindingSegmentMap ??= new Map();
if ( !segments.length ) {
segmentMap.clear();
Expand Down Expand Up @@ -498,7 +504,7 @@ function _getSegmentLabel(wrapped, segment) {
this.totalDistance = origTotalDistance;

if ( Settings.get(Settings.KEYS.LABELING.SCALE_TEXT) ) {
segment.label.style.fontSize = Math.round(CONFIG.canvasTextStyle.fontSize * canvas.dimensions.size / 100 * CONFIG[MODULE_ID].labeling.textScale);
segment.label.style.fontSize = Math.round(CONFIG.canvasTextStyle.fontSize * (canvas.dimensions.size / 100) * CONFIG[MODULE_ID].labeling.textScale);
}

if ( !segment.label.style.fontFamily.includes("fontAwesome") ) segment.label.style.fontFamily += ",fontAwesome";
Expand Down
65 changes: 30 additions & 35 deletions scripts/measurement/Grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ function getDirectPathGridless(wrapped, waypoints) {
// 1-to-1 relationship between the waypoints and the offsets2d for gridless.
return offsets2d.map((offset2d, idx) => {
const offset3d = GridCoordinates3d.fromOffset(offset2d);
offset3d.k = GridCoordinates3d.unitElevation(waypoints[idx].elevation);
const waypoint = GridCoordinates3d.fromObject(waypoints[idx]);
offset3d.k = GridCoordinates3d.unitElevation(waypoint.elevation);
return offset3d;
});
}
Expand Down Expand Up @@ -116,12 +117,6 @@ function directPath3dSquare(start, end, path2d) {
const doDiagonalElevationStep = !is2dDiagonal && diagonalElevationStepsRemaining > 0 && ((diagonalElevationStep + 1) % doDiagonalElevationStepMod) === 0;
const doAdditionalElevationSteps = additionalElevationStepsRemaining > 0 && ((i + 1) % doAdditionalElevationStepMod) === 0;

/*
console.log(`${i} ${stepsRemaining}`,
{ doDoubleDiagonalElevationStep, doDiagonalElevationStep, doAdditionalElevationSteps },
{ doubleDiagonalElevationStepsRemaining, diagonalElevationStepsRemaining, additionalElevationStepsRemaining });
*/

// Either double or normal diagonals are the same but have separate tracking.
if ( doDoubleDiagonalElevationStep ) {
currOffset.k += 1;
Expand All @@ -136,7 +131,6 @@ function directPath3dSquare(start, end, path2d) {

if ( doAdditionalElevationSteps ) {
let elevationSteps = Math.ceil(additionalElevationStepsRemaining / stepsRemaining);
// console.log("\t", { elevationSteps });
while ( elevationSteps > 0 ) {
currOffset.k += 1;
elevationSteps -= 1;
Expand Down Expand Up @@ -240,7 +234,6 @@ function directPath3dHex(start, end, path2d) {

const doElevationStep = ((i + 1) % doElevationStepMod) === 0;
let elevationSteps = doElevationStep && (elevationStepsRemaining > 0) ? Math.ceil(elevationStepsRemaining / stepsRemaining) : 0;
console.log(`${i} ${stepsRemaining} | elevationSteps: ${elevationSteps}`)
elevationStepsRemaining -= elevationSteps

// Apply the first elevation step as a diagonal upwards move in combination with the canvas 2d move.
Expand Down Expand Up @@ -309,29 +302,6 @@ function singleOffsetHexDistanceFn(numDiagonals = 0) {
return fn;
}

// ----- NOTE: Patches ----- //

PATCHES_GridlessGrid.BASIC.WRAPS = { getDirectPath: getDirectPathGridless };
PATCHES_SquareGrid.BASIC.WRAPS = { getDirectPath: getDirectPathGridded };
PATCHES_HexagonalGrid.BASIC.WRAPS = { getDirectPath: getDirectPathGridded };

PATCHES_GridlessGrid.BASIC.MIXES = { _measurePath };
PATCHES_SquareGrid.BASIC.MIXES = { _measurePath };
PATCHES_HexagonalGrid.BASIC.MIXES = { _measurePath };

// ----- NOTE: Helper functions ----- //

/**
* Define certain parameters required in the result object.
*/
function initializeResultObject(obj) {
obj.distance ??= 0;
obj.spaces ??= 0;
obj.cost ??= 0;
obj.diagonals ??= 0;
obj.offsetDistance ??= 0;
}

/**
* Measure a path for a gridded scene. Handles hex and square grids.
* @param {GridMeasurePathWaypoint[]} waypoints The waypoints the path must pass through
Expand Down Expand Up @@ -411,17 +381,17 @@ function _measurePath(wrapped, waypoints, { cost }, result) {
/**
* Wrap HexagonalGrid#getDirectPath and SquareGrid#getDirectPath
* Returns the sequence of grid offsets of a shortest, direct path passing through the given waypoints.
* @param {GridCoordinates[]} waypoints The waypoints the path must pass through
* @param {Point3d[]} waypoints The waypoints the path must pass through
* @returns {GridOffset[]} The sequence of grid offsets of a shortest, direct path
* @abstract
*/
function getDirectPathGridded(wrapped, waypoints) {
if ( !(waypoints[0] instanceof Point3d) ) return wrapped(waypoints);
let prevWaypoint = waypoints[0];
let prevWaypoint = GridCoordinates3d.fromObject(waypoints[0]);
const path3d = [];
const path3dFn = canvas.grid.isHexagonal ? directPath3dHex : directPath3dSquare;
for ( let i = 1, n = waypoints.length; i < n; i += 1 ) {
const currWaypoint = waypoints[i];
const currWaypoint = GridCoordinates3d.fromObject(waypoints[i]);
const path2d = wrapped([prevWaypoint, currWaypoint]);

// Keep the exact start and end points, used by _measure to calculate distance.
Expand All @@ -435,3 +405,28 @@ function getDirectPathGridded(wrapped, waypoints) {
}
return path3d;
}

// ----- NOTE: Patches ----- //

PATCHES_GridlessGrid.BASIC.WRAPS = { getDirectPath: getDirectPathGridless };
PATCHES_SquareGrid.BASIC.WRAPS = { getDirectPath: getDirectPathGridded };
PATCHES_HexagonalGrid.BASIC.WRAPS = { getDirectPath: getDirectPathGridded };

PATCHES_GridlessGrid.BASIC.MIXES = { _measurePath };
PATCHES_SquareGrid.BASIC.MIXES = { _measurePath };
PATCHES_HexagonalGrid.BASIC.MIXES = { _measurePath };

// ----- NOTE: Helper functions ----- //

/**
* Define certain parameters required in the result object.
*/
function initializeResultObject(obj) {
obj.distance ??= 0;
obj.spaces ??= 0;
obj.cost ??= 0;
obj.diagonals ??= 0;
obj.offsetDistance ??= 0;
}


4 changes: 2 additions & 2 deletions scripts/measurement/grid_coordinates.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export class GridCoordinates extends PIXI.Point {
* @returns {number} Distance, in grid units
*/
static gridDistanceBetween(a, b, altGridDistFn) {
if ( canvas.grid.isGridless ) return this.distanceBetween(a, b);
if ( canvas.grid.isGridless ) return CONFIG.GeometryLib.utils.pixelsToGridUnits(this.distanceBetween(a, b));
const distFn = canvas.grid.isHexagonal ? hexGridDistanceBetween : squareGridDistanceBetween;
const dist = distFn(a, b, altGridDistFn);

Expand Down Expand Up @@ -613,7 +613,7 @@ export class GridCoordinates3d extends RegionMovementWaypoint3d {
* @returns {number} Distance, in grid units
*/
static gridDistanceBetween(a, b, altGridDistFn) {
if ( canvas.grid.isGridless ) return this.distanceBetween(a, b);
if ( canvas.grid.isGridless ) return CONFIG.GeometryLib.utils.pixelsToGridUnits(this.distanceBetween(a, b));
const distFn = canvas.grid.isHexagonal ? hexGridDistanceBetween : squareGridDistanceBetween;
const dist = distFn(a, b, altGridDistFn);

Expand Down
4 changes: 2 additions & 2 deletions scripts/segment_labels_highlighting.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ export function customizedTextLabel(ruler, segment, origLabel = "") {

function constructSecondaryLabel(segment, text, name) {
const labelStyles = CONFIG[MODULE_ID].labeling.styles;
const textScale = CONFIG[MODULE_ID].labeling.secondaryTextScale;
const secondaryTextScale = CONFIG[MODULE_ID].labeling.secondaryTextScale;

let textLabel = segment.label.getChildByName(name);
if ( !textLabel ) {
Expand All @@ -292,7 +292,7 @@ function constructSecondaryLabel(segment, text, name) {
}
textLabel.visible = true;
textLabel.text = text;
textLabel.style.fontSize = Math.round(segment.label.style.fontSize * textScale);
textLabel.style.fontSize = Math.round(segment.label.style.fontSize * secondaryTextScale);
textLabel.anchor = { x: 0.5, y: 0.5 };
return textLabel;
}
Expand Down

0 comments on commit 742b5bf

Please sign in to comment.