146 - Measured Templates (#147)

* Added DhMeasuredTemplate

* Added TemplateEnricher for Template buttons in text
This commit is contained in:
WBHarry 2025-06-15 20:33:34 +02:00 committed by GitHub
parent 7802d18a4d
commit 96ed90b5fc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 168 additions and 66 deletions

View file

@ -0,0 +1,3 @@
import DhMeasuredTemplate from './measuredTemplate.mjs';
export { DhMeasuredTemplate };

View file

@ -0,0 +1,35 @@
export default class DhMeasuredTemplate extends MeasuredTemplate {
_refreshRulerText() {
super._refreshRulerText();
const rangeMeasurementSettings = game.settings.get(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.RangeMeasurement);
if (rangeMeasurementSettings.enabled) {
const splitRulerText = this.ruler.text.split(' ');
if (splitRulerText.length > 0) {
const rulerValue = Number(splitRulerText[0]);
const vagueLabel = this.constructor.getDistanceLabel(rulerValue, rangeMeasurementSettings);
this.ruler.text = vagueLabel;
}
}
}
static getDistanceLabel(distance, settings) {
if (distance <= settings.melee) {
return game.i18n.localize('DAGGERHEART.Range.melee.name');
}
if (distance <= settings.veryClose) {
return game.i18n.localize('DAGGERHEART.Range.veryClose.name');
}
if (distance <= settings.close) {
return game.i18n.localize('DAGGERHEART.Range.close.name');
}
if (distance <= settings.far) {
return game.i18n.localize('DAGGERHEART.Range.far.name');
}
if (distance <= settings.veryFar) {
return game.i18n.localize('DAGGERHEART.Range.veryFar.name');
}
return '';
}
}