Use range labels function for distance hover

This commit is contained in:
Carlos Fernandez 2026-01-30 07:34:40 -05:00
parent 19e375e242
commit a1b8e5c1f7
2 changed files with 7 additions and 28 deletions

View file

@ -27,31 +27,11 @@ export default class DhMeasuredTemplate extends foundry.canvas.placeables.Measur
return result;
}
const melee = sceneRangeMeasurement?.setting === custom.id ? sceneRangeMeasurement.melee : settings.melee;
const veryClose =
sceneRangeMeasurement?.setting === custom.id ? sceneRangeMeasurement.veryClose : settings.veryClose;
const close = sceneRangeMeasurement?.setting === custom.id ? sceneRangeMeasurement.close : settings.close;
const far = sceneRangeMeasurement?.setting === custom.id ? sceneRangeMeasurement.far : settings.far;
if (distanceValue <= melee) {
result.distance = game.i18n.localize('DAGGERHEART.CONFIG.Range.melee.name');
return result;
const ranges = sceneRangeMeasurement?.setting === custom.id ? sceneRangeMeasurement : settings;
const distanceKey = ['melee', 'veryClose', 'close', 'far'].find(r => ranges[r] >= distanceValue);
if (distanceKey) {
result.distance = game.i18n.localize(`DAGGERHEART.CONFIG.Range.${distanceKey}.name`);
}
if (distanceValue <= veryClose) {
result.distance = game.i18n.localize('DAGGERHEART.CONFIG.Range.veryClose.name');
return result;
}
if (distanceValue <= close) {
result.distance = game.i18n.localize('DAGGERHEART.CONFIG.Range.close.name');
return result;
}
if (distanceValue <= far) {
result.distance = game.i18n.localize('DAGGERHEART.CONFIG.Range.far.name');
return result;
}
if (distanceValue > far) {
result.distance = game.i18n.localize('DAGGERHEART.CONFIG.Range.veryFar.name');
}
return result;
}
}

View file

@ -1,3 +1,5 @@
import DhMeasuredTemplate from "./measuredTemplate.mjs";
export default class DhTokenPlaceable extends foundry.canvas.placeables.Token {
/** @inheritdoc */
async _draw(options) {
@ -101,11 +103,8 @@ export default class DhTokenPlaceable extends foundry.canvas.placeables.Token {
// Determine the actual range
const ranges = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.variantRules).rangeMeasurement;
if (!ranges.enabled) return;
const distanceNum = originToken.distanceTo(this);
const distanceKey = ['melee', 'veryClose', 'close', 'far', 'very far'].find(r => ranges[r] >= distanceNum);
const distanceLabel = distanceKey ? game.i18n.localize(`DAGGERHEART.CONFIG.Range.${distanceKey}.name`) : null;
if (!distanceLabel) return; // todo: out of bounds instead
const distanceLabel = DhMeasuredTemplate.getRangeLabels(distanceNum, ranges).distance;
// Create the element
const element = document.createElement('div');