mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-12 03:31:07 +01:00
modify ruler and token ruler to show distance ranges
This commit is contained in:
parent
7ef17168be
commit
0e345b70b1
4 changed files with 47 additions and 6 deletions
|
|
@ -9,6 +9,7 @@ import { registerDHPSettings } from './module/applications/settings.mjs';
|
||||||
import DhpChatLog from './module/ui/chatLog.mjs';
|
import DhpChatLog from './module/ui/chatLog.mjs';
|
||||||
import DhpPlayers from './module/ui/players.mjs';
|
import DhpPlayers from './module/ui/players.mjs';
|
||||||
import DhpRuler from './module/ui/ruler.mjs';
|
import DhpRuler from './module/ui/ruler.mjs';
|
||||||
|
import DhpTokenRuler from './module/ui/tokenRuler.mjs';
|
||||||
|
|
||||||
globalThis.SYSTEM = SYSTEM;
|
globalThis.SYSTEM = SYSTEM;
|
||||||
|
|
||||||
|
|
@ -83,6 +84,7 @@ Hooks.once('init', () => {
|
||||||
CONFIG.ui.combat = DhpCombatTracker;
|
CONFIG.ui.combat = DhpCombatTracker;
|
||||||
CONFIG.ui.chat = DhpChatLog;
|
CONFIG.ui.chat = DhpChatLog;
|
||||||
CONFIG.ui.players = DhpPlayers;
|
CONFIG.ui.players = DhpPlayers;
|
||||||
|
CONFIG.Token.rulerClass = DhpTokenRuler;
|
||||||
|
|
||||||
game.socket.on(`system.${SYSTEM.id}`, handleSocketEvent);
|
game.socket.on(`system.${SYSTEM.id}`, handleSocketEvent);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -204,7 +204,7 @@ export const registerDHPSettings = () => {
|
||||||
config: false,
|
config: false,
|
||||||
type: Object,
|
type: Object,
|
||||||
default: {
|
default: {
|
||||||
enabled: false,
|
enabled: true,
|
||||||
melee: 5,
|
melee: 5,
|
||||||
veryClose: 15,
|
veryClose: 15,
|
||||||
close: 30,
|
close: 30,
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,17 @@
|
||||||
export default class DhpRuler extends foundry.canvas.interaction.Ruler {
|
export default class DhpRuler extends foundry.canvas.interaction.Ruler {
|
||||||
_getSegmentLabel(segment, totalDistance) {
|
_getWaypointLabelContext(waypoint, state) {
|
||||||
|
const context = super._getWaypointLabelContext(waypoint, state);
|
||||||
|
if (!context) return;
|
||||||
|
|
||||||
const range = game.settings.get(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.General.RangeMeasurement);
|
const range = game.settings.get(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.General.RangeMeasurement);
|
||||||
if (!range.enabled) return super._getSegmentLabel(segment, totalDistance);
|
|
||||||
|
|
||||||
const segmentDistance = Math.round(segment.distance * 100) / 100;
|
if (range.enabled) {
|
||||||
const totalDistanceValue = Math.round(totalDistance * 100) / 100;
|
const distance = this.#getRangeLabel(waypoint.measurement.distance.toNearest(0.01), range);
|
||||||
|
context.cost = { total: distance, units: null };
|
||||||
|
context.distance = { total: distance, units: null };
|
||||||
|
}
|
||||||
|
|
||||||
return `${this.#getRangeLabel(segmentDistance, range)} [${this.#getRangeLabel(totalDistanceValue, range)}]`;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
#getRangeLabel(distance, settings) {
|
#getRangeLabel(distance, settings) {
|
||||||
|
|
|
||||||
34
module/ui/tokenRuler.mjs
Normal file
34
module/ui/tokenRuler.mjs
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
export default class DhpTokenRuler extends foundry.canvas.placeables.tokens.TokenRuler {
|
||||||
|
_getWaypointLabelContext(waypoint, state) {
|
||||||
|
const context = super._getWaypointLabelContext(waypoint, state);
|
||||||
|
if (!context) return;
|
||||||
|
|
||||||
|
const range = game.settings.get(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.General.RangeMeasurement);
|
||||||
|
|
||||||
|
if (range.enabled) {
|
||||||
|
const distance = this.#getRangeLabel(waypoint.measurement.distance.toNearest(0.01), range);
|
||||||
|
context.cost = { total: distance, units: null };
|
||||||
|
context.distance = { total: distance, units: null };
|
||||||
|
}
|
||||||
|
|
||||||
|
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