modify ruler and token ruler to show distance ranges (#40)

This commit is contained in:
IrkTheImp 2025-05-23 18:19:37 -05:00 committed by GitHub
parent 504e2ca0f2
commit 2d832e74d4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 47 additions and 6 deletions

View file

@ -1,12 +1,17 @@
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);
if (!range.enabled) return super._getSegmentLabel(segment, totalDistance);
const segmentDistance = Math.round(segment.distance * 100) / 100;
const totalDistanceValue = Math.round(totalDistance * 100) / 100;
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 `${this.#getRangeLabel(segmentDistance, range)} [${this.#getRangeLabel(totalDistanceValue, range)}]`;
return context;
}
#getRangeLabel(distance, settings) {