Skip to content

Commit

Permalink
Merge branch 'release/0.10.6' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
caewok committed Aug 31, 2024
2 parents e5370a4 + 43acc4d commit 903c33e
Show file tree
Hide file tree
Showing 24 changed files with 453 additions and 237 deletions.
11 changes: 11 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# 0.10.6
## New Features
Setting to apply movement penalties per-grid-space. Defaults to enabled. For gridded scenes, this will (1) count regions/tokens/drawings as imposing movement penalty only if the region/token/drawing overlaps the center point of the grid space and (2) impose the penalty at a grid-space level. If disabled, this will proportionally apply the penalty based on the precise movement path. Closes #181.

Setting to add (or subtract) a flat amount when moving into a grid space with a token penalty. E.g. +5 per grid square. Add parallel setting to drawing configuration. (May add a similar toggle to regions in Terrain Mapper if this cannot be easily handled using active effects.) Closes #125.

## Bug fixes and other updates
Correct NaN distance when using hex grids. Closes #188.
Don't treat walls as blocking if the top elevation equals the token elevation. Closes #189.
Update Italian localization. Thanks @GregoryWarn!

# 0.10.5
Fix for `_fromPoint3d` not a function. Closes #186.

Expand Down
18 changes: 14 additions & 4 deletions languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,11 @@
"elevationruler.settings.round-to-multiple.name": "Round Distance to Multiple",
"elevationruler.settings.round-to-multiple.hint": "Round the distance displayed to the nearest multiple of the number entered. Set to 0 to disable rounding.",

"elevationruler.settings.token-terrain-multiplier.name": "Token as Terrain Multiplier",
"elevationruler.settings.token-terrain-multiplier.hint": "Multiplier to use to calculate movement speed when moving through other tokens. Set to 1 to ignore. Values less than 1 treat token spaces as faster than normal; values greater than 1 penalize movement through token spaces.",
"elevationruler.settings.token-terrain-multiplier.name": "Token Penalty Percent",
"elevationruler.settings.token-terrain-multiplier.hint": "Penalize movement through other tokens. Set to 1 for no penalty, less than one to grant a bonus, greater than 1 to impose a penalty multiplier. For example, set to 2 to double movement cost through a token.",

"elevationruler.settings.token-terrain-multiplier-flat.name": "Flat Token Penalty",
"elevationruler.settings.token-terrain-multiplier-flat.hint": "If enabled, treats the token move penalty as a fixed amount of additional distance. For example, set to 5 to add +5 to each square of movement. Negative values provide a flat bonus.",

"elevationruler.settings.pathfinding_enable.name": "Use Pathfinding",
"elevationruler.settings.pathfinding_enable.hint": "When enabled, adds a pathfinding togglee to the Token controls that will cause the ruler to map a path around walls and tokens, depending on settings. Disable this if pathfinding is causing compatibility issues. Disabling may also result in a small performance increase.",
Expand All @@ -96,6 +99,7 @@

"elevationruler.settings.grid-terrain-algorithm.name": "Terrain Grid Measurement",
"elevationruler.settings.grid-terrain-algorithm.hint": "When on a grid, how to account for movement penalties or bonuses from terrain and tokens? Center: apply if the terrain/token overlaps the grid center; Percent Area: apply if the terrain/token covers at least this much of the grid square/hex; Euclidean: prorate based on percent of line segment within the terrain/token between this grid square/hex and the previous.",

"elevationruler.settings.grid-terrain-choice-center-point": "Center Point",
"elevationruler.settings.grid-terrain-choice-percent-area": "Percent Area",
"elevationruler.settings.grid-terrain-choice-euclidean": "Euclidean",
Expand All @@ -112,14 +116,20 @@
"elevationruler.settings.scale-text.name": "Scale Ruler Text",
"elevationruler.settings.scale-text.hint": "When enabled, ruler text will be scaled depending on `canvas.dimensions.size`. Further adjust scaling by using `CONFIG.elevationruler.textScale`.",

"elevationruler.settings.force-grid-penalties.name": "Use Grid for Movement Penalties",
"elevationruler.settings.force-grid-penalties.hint": "When enabled, move penalties only apply if the token/drawing/region covers the center of the hex/square and penalties are applied per-square or per-hex on gridded maps. When disabled, movement penalties are applied proportionally to the move. For example, if a drawing with a x2 move penalty covers 3/4 of a grid square, it will apply to 3/4 of the move through that square (i.e., 1.5x penalty).",

"elevationruler.settings.customized-labels.name": "Customized Ruler Text",
"elevationruler.settings.customized-labels.hint": "Customize the ruler text. Change styles using `CONFIG.elevationruler.labelStyles` and `CONFIG.elevationruler.labelIcons`.",

"elevationruler.controls.prefer-token-elevation.name": "Prefer Token Elevation",
"elevationruler.controls.pathfinding-control.name": "Use Pathfinding",

"elevationruler.drawingconfig.movementPenalty.name": "Movement Bonus/Penalty",
"elevationruler.drawingconfig.movementPenalty.hint": "Set to 1 for no penalty. Values greater than one penalize movement by that percent; values less than one effectively grant a bonus to movement. For example, set to 2 to double movement through this area. Movement under the drawing elevation will be ignored.",
"elevationruler.drawingconfig.movementPenalty.name": "Movement Penalty Percent",
"elevationruler.drawingconfig.movementPenalty.hint": "Set to 1 for no penalty, less than one to grant a bonus, greater than 1 to impose a penalty multiplier. For example, set to 2 to double movement cost through this area. Movement under the drawing elevation will be ignored.",

"elevationruler.drawingconfig.flatMovementPenalty.name": "Use Flat Penalty",
"elevationruler.drawingconfig.flatMovementPenalty.hint": "If enabled, treats the penalty as a fixed amount of additional distance. For example, set to 5 to add +5 to each square of movement. Negative values provide a flat bonus.",

"elevationruler.clearMovement": "Clear Combatant Movement",
"elevationruler.waypoint": "waypoint",
Expand Down
22 changes: 21 additions & 1 deletion languages/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@
"elevationruler.settings.token-ruler-combat-history.name": "Traccia movimenti di combattimento",
"elevationruler.settings.token-ruler-combat-history.hint": "Per l'evidenziare la velocità dei token, somma tutte le mosse dei token durante il round quando abilitato.",

"elevationruler.settings.combine-prior-with-total.name": "Combina il movimento precedente con il movimento totale",
"elevationruler.settings.combine-prior-with-total.hint": "Quando è abilitato il tracciamento dei movimenti di combattimento, combina il movimento precedente del token nel round con il movimento totale. Altrimenti, posiziona il movimento precedente su una riga separata.",

"elevationruler.settings.token-speed-property.name": "Proprietà Camminare Token",
"elevationruler.settings.token-speed-property.hint": "Per l'evidenziazione della velocità del token, questa è la proprietà che rappresenta la velocità di camminata del token.",

Expand Down Expand Up @@ -88,6 +91,9 @@
"elevationruler.settings.pathfinding_limit_token_los.name": "Limita Trova Percorso alle Aree Esplorate",
"elevationruler.settings.pathfinding_limit_token_los.hint": "Usando Trova Percorso, limita il raggio d'azione del percorso alle aree esplorate a meno che l'utente non sia il DM",

"elevationruler.settings.pathfinding_snap_to_grid.name": "Trova Percorso agganciato alla griglia",
"elevationruler.settings.pathfinding_snap_to_grid.hint": "Durante la ricerca del percorso su una mappa a griglia, aggancia il percorso ai centri della griglia a meno che ciò non provochi il blocco del percorso.",

"elevationruler.settings.grid-terrain-algorithm.name": "Misurazione Griglia Terreno",
"elevationruler.settings.grid-terrain-algorithm.hint": "Quando sei su una griglia, come tenere conto delle penalità di movimento o dei bonus derivanti dal terreno e dai token? Centro: si applica se il terreno/token si sovrappone al centro della griglia; Area percentuale: si applica se il terreno/token copre almeno questa parte del quadrato/esagono della griglia; Euclideo: ripartizione proporzionale in base alla percentuale del segmento di linea all'interno del terreno/token tra questo quadrato/esagono della griglia e il precedente.",
"elevationruler.settings.grid-terrain-choice-center-point": "Centro",
Expand All @@ -100,11 +106,25 @@
"elevationruler.settings.automatic-movement-type.name": "Rilevamento automatico del tipo di movimento",
"elevationruler.settings.automatic-movement-type.hint": "Rileva automaticamente il tipo di movimento in base alla posizione del token. Imposta l'effetto dello stato del token su 'volare' o 'scavare' per sovrascrivere.",

"elevationruler.settings.euclidean-grid-distance.name": "Preferisci la distanza euclidea",
"elevationruler.settings.euclidean-grid-distance.hint": "Per le scene a griglia, se viene scelto 'Esatto (√2)' per l'impostazione principale 'Diagonali griglia quadrata', ciò costringerà a misurare la distanza euclidea invece della distanza in unità esadecimali/quadrate. Per le griglie esagonali, viene influenzato solo il movimento di elevazione diagonale.",

"elevationruler.settings.scale-text.name": "Testo Scala Righello",
"elevationruler.settings.scale-text.hint": "Se abilitato, il testo del righello verrà ridimensionato in base a 'canvas.dimensions.size'. Regola ulteriormente il ridimensionamento utilizzando `CONFIG.elevationruler.textScale`.",

"elevationruler.settings.customized-labels.name": "Testo Righello Personalizzato",
"elevationruler.settings.customized-labels.hint": "Personalizza il testo del righello. Modifica gli stili utilizzando `CONFIG.elevationruler.labelStyles` e `CONFIG.elevationruler.labelIcons`.",

"elevationruler.controls.prefer-token-elevation.name": "Preferisci elevazione token",
"elevationruler.controls.pathfinding-control.name": "Trova Percorso",

"elevationruler.drawingconfig.movementPenalty.name": "Bonus/Penalità Movimento",
"elevationruler.drawingconfig.movementPenalty.hint": "Impostato a 1 senza penalità. Valori maggiori di uno penalizzano il movimento di quella percentuale; valori inferiori a uno garantiscono effettivamente un bonus al movimento. Ad esempio, impostalo su 2 per raddoppiare il movimento in quest'area. Il movimento sotto l'elevazione del disegno verrà ignorato.",

"elevationruler.clearMovement": "Cancella Movimento Combattente"
"elevationruler.clearMovement": "Cancella Movimento Combattente",
"elevationruler.waypoint": "Punto di passaggio",
"elevationruler.up": "Su",
"elevationruler.down": "Giù",
"elevationruler.added": "Aggiunto",
"elevationruler.prior": "Precedente"
}
14 changes: 4 additions & 10 deletions scripts/CombatTracker.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* globals
game
game,
ui
*/
/* eslint no-unused-vars: ["error", { "argsIgnorePattern": "^_" }] */

Expand All @@ -10,7 +11,7 @@ import { TEMPLATES, MODULE_ID, FLAGS } from "./const.js";
export const PATCHES = {};
PATCHES.BASIC = {};

import { injectConfiguration, renderTemplateSync } from "./util.js";
import { renderTemplateSync } from "./util.js";

// ----- NOTE: Hooks ----- //

Expand All @@ -31,15 +32,8 @@ function renderCombatTracker(app, html, data) {
if ( !dividers.length ) return;

const myHtml = renderTemplateSync(TEMPLATES.COMBAT_TRACKER, data);
// const aElem = document.createElement("a");
// aElem.innerHTML = myHtml;
dividers[0].insertAdjacentHTML("beforebegin", myHtml);

// const npcButton = Object.values(combatButtons).findIndex(b => b.dataset.control === "rollNPC");
// const findString = ".combat-button[data-control='rollNPC']";
// await injectConfiguration(app, html, data, template, findString);

html.find(`.${MODULE_ID}`).click(ev => clearMovement.call(app, ev));
html.find(`.${MODULE_ID}`).click(ev => clearMovement.call(app, ev));
}

PATCHES.BASIC.HOOKS = { renderCombatTracker };
Expand Down
10 changes: 5 additions & 5 deletions scripts/ModuleSettingsAbstract.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ export class ModuleSettingsAbstract {
const cached = this.cache.get(key);
if ( typeof cached !== "undefined" ) {
// For debugging, can confirm against what the value should be.
// const origValue = game.settings.get(MODULE_ID, key);
// if ( origValue !== cached ) {
// console.debug(`Settings cache fail: ${origValue} !== ${cached} for key ${key}`);
// return origValue;
// }
// const origValue = game.settings.get(MODULE_ID, key);
// if ( origValue !== cached ) {
// console.debug(`Settings cache fail: ${origValue} !== ${cached} for key ${key}`);
// return origValue;
// }

return cached;

Expand Down
10 changes: 7 additions & 3 deletions scripts/Patcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ export class Patcher {
Object.defineProperty(cl, name, descriptor);

const prototypeName = cl.constructor?.name;
const id = `${prototypeName ?? cl.name }.${prototypeName ? "prototype." : ""}${name}`;
const id = `${prototypeName ?? cl.name}.${prototypeName ? "prototype." : ""}${name}`;
return { id, args: { cl, name } };
}

Expand Down Expand Up @@ -401,7 +401,9 @@ export class MethodPatch extends AbstractPatch {
else if ( this.config.isSetter ) this.prevMethod = this.prevMethod?.set;
else this.prevMethod = this.prevMethod?.value;

this.regId = Patcher.addClassMethod(this.#cl, this.target, this.patchFn, { getter: this.config.isGetter, setter: this.config.isSetter });
this.regId = Patcher.addClassMethod(this.#cl, this.target, this.patchFn, {
getter: this.config.isGetter, setter: this.config.isSetter
});
}

/**
Expand All @@ -413,7 +415,9 @@ export class MethodPatch extends AbstractPatch {

// Add back the original, if any.
if ( this.prevMethod ) {
Patcher.addClassMethod(this.#cl, this.target, this.prevMethod, { getter: this.config.isGetter, setter: this.config.isSetter });
Patcher.addClassMethod(this.#cl, this.target, this.prevMethod, {
getter: this.config.isGetter, setter: this.config.isSetter
});
this.prevMethod = undefined;
}
this.regId = undefined;
Expand Down
10 changes: 6 additions & 4 deletions scripts/Ruler.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
canvas,
CONFIG,
CONST,
foundry,
game,
PIXI,
Ruler,
Expand Down Expand Up @@ -276,7 +277,7 @@ function _getMeasurementDestination(wrapped, point, {snap=true}={}) {
const origin = token.getCenterPoint();
const delta = origPoint.subtract(origin, PIXI.Point._tmp);
let position = PIXI.Point._tmp2.copyFrom(token.document).add(delta, PIXI.Point._tmp2);
const tlSnapped = token._preview.getSnappedPosition(position);
const tlSnapped = token._preview.getSnappedPosition(position);
return token.getCenterPoint(tlSnapped);
}

Expand Down Expand Up @@ -499,8 +500,7 @@ function _getCostFunction() {
return (prevOffset, currOffset, offsetDistance) => {
if ( !(prevOffset instanceof GridCoordinates3d) ) prevOffset = GridCoordinates3d.fromOffset(prevOffset);
if ( !(currOffset instanceof GridCoordinates3d) ) currOffset = GridCoordinates3d.fromOffset(currOffset);
const penalty = movePenaltyInstance.movementPenaltyForSegment(prevOffset, currOffset);
return offsetDistance * penalty;
return movePenaltyInstance.movementCostForSegment(prevOffset, currOffset, offsetDistance);
};
}

Expand All @@ -519,9 +519,11 @@ function _getSegmentLabel(wrapped, segment) {
}

// Force distance to be between waypoints instead of (possibly pathfinding) segments.
// Use cost instead of straight distance for the label.
const origSegmentDistance = segment.distance;
const origTotalDistance = this.totalDistance;
segment.distance = roundMultiple(segment.waypoint.distance);
segment.distance = roundMultiple(segment.waypoint.cost);
this.totalDistance = this.totalCost;
const origLabel = wrapped(segment);
segment.distance = origSegmentDistance;
this.totalDistance = origTotalDistance;
Expand Down
9 changes: 5 additions & 4 deletions scripts/Token.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* globals
canvas,
CanvasAnimation,
CONFIG,
foundry,
game,
Ruler
Expand Down Expand Up @@ -96,7 +97,7 @@ function updateToken(document, changed, _options, _userId) {
const tokenHistory = token[MODULE_ID].measurementHistory ??= [];
const gridUnitsToPixels = CONFIG.GeometryLib.utils.gridUnitsToPixels;
const origin = token.getCenterPoint(document);
const dest = token.getCenterPoint({ x: changed.x ?? document.x, y: changed.y ?? document.y})
const dest = token.getCenterPoint({ x: changed.x ?? document.x, y: changed.y ?? document.y});
origin.z = gridUnitsToPixels(document.elevation);
origin.teleport = false;
origin.cost = 0;
Expand Down Expand Up @@ -129,7 +130,7 @@ function _onDragLeftCancel(wrapped, event) {

// Add waypoint on right click
const ruler = canvas.controls.ruler;
if ( event.button === 2 && ruler._isTokenRuler && ruler.active && ruler.state === Ruler.STATES.MEASURING ) {
if ( event.button === 2 && ruler._isTokenRuler && ruler.active && ruler.state === Ruler.STATES.MEASURING ) {
log("Token#_onDragLeftMove|Token ruler active");
event.preventDefault();
if ( event.ctrlKey ) ruler._removeWaypoint(event.interactionData.origin, {snap: !event.shiftKey});
Expand Down Expand Up @@ -187,7 +188,7 @@ async function _onDragLeftDrop(wrapped, event) {
return false;
}

// ruler._state = Ruler.STATES.MOVING; // Do NOT set state to MOVING here in v12, as it will break the canvas.
// NO: ruler._state = Ruler.STATES.MOVING; // Do NOT set state to MOVING here in v12, as it will break the canvas.
ruler._onMoveKeyDown(event); // Movement is async here but not awaited in _onMoveKeyDown.
}

Expand Down Expand Up @@ -259,4 +260,4 @@ function noStartEase(easing) {
function noEndEase(easing) {
if ( typeof easing === "string" ) easing = CanvasAnimation[easing];
return pt => (pt > 0.5) ? pt : easing(pt);
}
}
5 changes: 4 additions & 1 deletion scripts/const.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const TEMPLATES = {
export const FLAGS = {
MOVEMENT_SELECTION: "selectedMovementType",
MOVEMENT_PENALTY: "movementPenalty",
MOVEMENT_PENALTY_FLAT: "flatMovementPenalty",
SCENE: {
BACKGROUND_ELEVATION: "backgroundElevation"
},
Expand Down Expand Up @@ -47,7 +48,9 @@ export const MOVEMENT_TYPES = {
* @param {number} groundElev Ground elevation in grid units
* @returns {MOVEMENT_TYPE}
*/
forCurrentElevation: function movementTypeForCurrentElevation(currElev, groundElev = 0) { return Math.sign(currElev - groundElev) + 1; }
forCurrentElevation: function(currElev, groundElev = 0) {
return Math.sign(currElev - groundElev) + 1;
}
};


Expand Down
2 changes: 1 addition & 1 deletion scripts/geometry
Loading

0 comments on commit 903c33e

Please sign in to comment.