mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-16 05:31:07 +01:00
Added DhMeasuredTemplate
This commit is contained in:
parent
7802d18a4d
commit
33655ae702
5 changed files with 47 additions and 38 deletions
|
|
@ -15,6 +15,7 @@ import { abilities } from './module/config/actorConfig.mjs';
|
||||||
import Resources from './module/applications/resources.mjs';
|
import Resources from './module/applications/resources.mjs';
|
||||||
import DHDualityRoll from './module/data/chat-message/dualityRoll.mjs';
|
import DHDualityRoll from './module/data/chat-message/dualityRoll.mjs';
|
||||||
import { DualityRollColor } from './module/data/settings/Appearance.mjs';
|
import { DualityRollColor } from './module/data/settings/Appearance.mjs';
|
||||||
|
import { DhMeasuredTemplate } from './module/placeables/_module.mjs';
|
||||||
|
|
||||||
globalThis.SYSTEM = SYSTEM;
|
globalThis.SYSTEM = SYSTEM;
|
||||||
|
|
||||||
|
|
@ -37,6 +38,8 @@ Hooks.once('init', () => {
|
||||||
name: game.i18n.localize(x.name)
|
name: game.i18n.localize(x.name)
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
CONFIG.MeasuredTemplate.objectClass = DhMeasuredTemplate;
|
||||||
|
|
||||||
CONFIG.Item.documentClass = documents.DhpItem;
|
CONFIG.Item.documentClass = documents.DhpItem;
|
||||||
|
|
||||||
//Registering the Item DataModel
|
//Registering the Item DataModel
|
||||||
|
|
|
||||||
3
module/placeables/_module.mjs
Normal file
3
module/placeables/_module.mjs
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
import DhMeasuredTemplate from './measuredTemplate.mjs';
|
||||||
|
|
||||||
|
export { DhMeasuredTemplate };
|
||||||
35
module/placeables/measuredTemplate.mjs
Normal file
35
module/placeables/measuredTemplate.mjs
Normal 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 '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
import DhMeasuredTemplate from '../placeables/measuredTemplate.mjs';
|
||||||
|
|
||||||
export default class DhpRuler extends foundry.canvas.interaction.Ruler {
|
export default class DhpRuler extends foundry.canvas.interaction.Ruler {
|
||||||
_getWaypointLabelContext(waypoint, state) {
|
_getWaypointLabelContext(waypoint, state) {
|
||||||
const context = super._getWaypointLabelContext(waypoint, state);
|
const context = super._getWaypointLabelContext(waypoint, state);
|
||||||
|
|
@ -6,29 +8,11 @@ export default class DhpRuler extends foundry.canvas.interaction.Ruler {
|
||||||
const range = game.settings.get(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.RangeMeasurement);
|
const range = game.settings.get(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.RangeMeasurement);
|
||||||
|
|
||||||
if (range.enabled) {
|
if (range.enabled) {
|
||||||
const distance = this.#getRangeLabel(waypoint.measurement.distance.toNearest(0.01), range);
|
const distance = DhMeasuredTemplate.getDistanceLabel(waypoint.measurement.distance.toNearest(0.01), range);
|
||||||
context.cost = { total: distance, units: null };
|
context.cost = { total: distance, units: null };
|
||||||
context.distance = { total: distance, units: null };
|
context.distance = { total: distance, units: null };
|
||||||
}
|
}
|
||||||
|
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
#getRangeLabel(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');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
import DhMeasuredTemplate from '../placeables/measuredTemplate.mjs';
|
||||||
|
|
||||||
export default class DhpTokenRuler extends foundry.canvas.placeables.tokens.TokenRuler {
|
export default class DhpTokenRuler extends foundry.canvas.placeables.tokens.TokenRuler {
|
||||||
_getWaypointLabelContext(waypoint, state) {
|
_getWaypointLabelContext(waypoint, state) {
|
||||||
const context = super._getWaypointLabelContext(waypoint, state);
|
const context = super._getWaypointLabelContext(waypoint, state);
|
||||||
|
|
@ -6,29 +8,11 @@ export default class DhpTokenRuler extends foundry.canvas.placeables.tokens.Toke
|
||||||
const range = game.settings.get(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.RangeMeasurement);
|
const range = game.settings.get(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.RangeMeasurement);
|
||||||
|
|
||||||
if (range.enabled) {
|
if (range.enabled) {
|
||||||
const distance = this.#getRangeLabel(waypoint.measurement.distance.toNearest(0.01), range);
|
const distance = DhMeasuredTemplate.getDistanceLabel(waypoint.measurement.distance.toNearest(0.01), range);
|
||||||
context.cost = { total: distance, units: null };
|
context.cost = { total: distance, units: null };
|
||||||
context.distance = { total: distance, units: null };
|
context.distance = { total: distance, units: null };
|
||||||
}
|
}
|
||||||
|
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
#getRangeLabel(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');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue