From 930a81b96ef10a46e147d31e69813c674fe4c85a Mon Sep 17 00:00:00 2001 From: caewok Date: Fri, 5 Apr 2024 09:44:38 -0700 Subject: [PATCH] Catch if speed is undefined for a segment --- Changelog.md | 4 ++++ scripts/const.js | 8 +++++--- scripts/segments.js | 3 ++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Changelog.md b/Changelog.md index 5c25600..a02fd65 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,3 +1,7 @@ +# 0.8.11 +Catch when a segment color is not defined, to avoid throwing an error. + + # 0.8.10 ## New features Add indicator of past combat movement in the ruler. diff --git a/scripts/const.js b/scripts/const.js index bf9c014..1ac80a9 100644 --- a/scripts/const.js +++ b/scripts/const.js @@ -162,11 +162,13 @@ SPEED.maximumCategoryDistance = function(token, speedCategory, tokenSpeed) { /** * Given a token, retrieve its base speed. * @param {Token} token Token whose speed is required - * @returns {number} Distance, in grid units + * @returns {number|null} Distance, in grid units. Null if no speed provided for that category. + * (Null will disable speed highlighting.) */ SPEED.tokenSpeed = function(token) { - const speedAttribute = SPEED.ATTRIBUTES[token.movementType] ?? SPEED.ATTRIBUTES.WALK; - return Number(foundry.utils.getProperty(token, speedAttribute)); + const speed = foundry.utils.getProperty(token, SPEED.ATTRIBUTES[token.movementType]); + if ( speed === null ) return null; + return Number(speed); }; // Avoid testing for the system id each time. diff --git a/scripts/segments.js b/scripts/segments.js index e238135..6a186b3 100644 --- a/scripts/segments.js +++ b/scripts/segments.js @@ -289,7 +289,8 @@ export function _highlightMeasurementSegment(wrapped, segment) { const token = this._getMovementToken(); const doSpeedHighlighting = token // && this.user === game.user - && Settings.get(Settings.KEYS.TOKEN_RULER.SPEED_HIGHLIGHTING); + && Settings.get(Settings.KEYS.TOKEN_RULER.SPEED_HIGHLIGHTING) + && segment.speed?.color; // Highlight each split in turn, changing highlight color each time. if ( doSpeedHighlighting ) this.color = segment.speed.color;