From f4fce226c17085a00be07b1c08248a9a2cccac9b Mon Sep 17 00:00:00 2001 From: Michael Enion Date: Fri, 5 Apr 2024 12:53:48 -0700 Subject: [PATCH 1/3] Fix for combat movement speed Cycle through speed categories that are less than the current movement. This also works when a later category has less total distance than a previous category for this token. --- scripts/Ruler.js | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/scripts/Ruler.js b/scripts/Ruler.js index 5828aee..3708100 100644 --- a/scripts/Ruler.js +++ b/scripts/Ruler.js @@ -396,14 +396,11 @@ function _computeTokenSpeed() { let totalDistance = 0; let totalMoveDistance = 0; let totalCombatMoveDistance = 0; + let minDistance = 0; let numPrevDiagonal = 0; let s = 0; let segment; - // Add in already moved combat distance. - if ( game.combat?.started - && Settings.get(Settings.KEYS.TOKEN_RULER.COMBAT_HISTORY) ) totalCombatMoveDistance = token.lastMoveDistance; - // Progress through each speed attribute in turn. const categoryIter = [...SPEED.CATEGORIES, MaximumSpeedCategory].values(); const maxDistFn = (token, speedCategory, tokenSpeed) => { @@ -414,7 +411,30 @@ function _computeTokenSpeed() { let speedCategory = categoryIter.next().value; let maxDistance = maxDistFn(token, speedCategory, tokenSpeed); + // Determine which speed category we are starting with + // Add in already moved combat distance and determine the starting category + if ( game.combat?.started + && Settings.get(Settings.KEYS.TOKEN_RULER.COMBAT_HISTORY) ) { + + totalCombatMoveDistance = token.lastMoveDistance; + minDistance = totalCombatMoveDistance; +// while ( speedCategory +// && speedCategory.name !== "Maximum" +// && totalCombatMoveDistance > maxDistance ) { +// +// speedCategory = categoryIter.next().value; +// maxDistance = maxDistFn(token, speedCategory, tokenSpeed); +// } + } + + while ( (segment = this.segments[s]) ) { + // Skip speed categories that do not provide a distance larger than the last. + while ( speedCategory.name !== "Maximum" && maxDistance <= minDistance ) { + speedCategory = categoryIter.next().value; + maxDistance = maxDistFn(token, speedCategory, tokenSpeed); + } + segment.speed = speedCategory; let newPrevDiagonal = _measureSegment(segment, token, numPrevDiagonal); @@ -436,8 +456,9 @@ function _computeTokenSpeed() { } // Increment to the next speed category. - speedCategory = categoryIter.next().value; - maxDistance = maxDistFn(token, speedCategory, tokenSpeed); + minDistance = maxDistance; +// speedCategory = categoryIter.next().value; +// maxDistance = maxDistFn(token, speedCategory, tokenSpeed); } // Increment totals. From 84d76d789f3754f98218c90de2b206ab06d0f0ba Mon Sep 17 00:00:00 2001 From: Michael Enion Date: Fri, 5 Apr 2024 12:54:55 -0700 Subject: [PATCH 2/3] Cleanup --- Changelog.md | 6 ++++++ scripts/Ruler.js | 10 +--------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/Changelog.md b/Changelog.md index a02fd65..59506e0 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,7 +1,13 @@ # 0.8.11 + +## New features +Add a keybinding ("g") to force the ruler to measure from ground terrain. Replaces "Prefer Token Elevation," which was removed. Closes #63, #64. + +## Bug fixes 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/Ruler.js b/scripts/Ruler.js index 3708100..185d7de 100644 --- a/scripts/Ruler.js +++ b/scripts/Ruler.js @@ -418,13 +418,6 @@ function _computeTokenSpeed() { totalCombatMoveDistance = token.lastMoveDistance; minDistance = totalCombatMoveDistance; -// while ( speedCategory -// && speedCategory.name !== "Maximum" -// && totalCombatMoveDistance > maxDistance ) { -// -// speedCategory = categoryIter.next().value; -// maxDistance = maxDistFn(token, speedCategory, tokenSpeed); -// } } @@ -456,9 +449,8 @@ function _computeTokenSpeed() { } // Increment to the next speed category. + // Next category will be selected in the while loop above: first category to exceed minDistance. minDistance = maxDistance; -// speedCategory = categoryIter.next().value; -// maxDistance = maxDistFn(token, speedCategory, tokenSpeed); } // Increment totals. From 20eb26579f722b28771f9dedd95998cdb53c1e60 Mon Sep 17 00:00:00 2001 From: Michael Enion Date: Fri, 5 Apr 2024 12:57:35 -0700 Subject: [PATCH 3/3] Update changelog --- Changelog.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Changelog.md b/Changelog.md index 59506e0..65160bf 100644 --- a/Changelog.md +++ b/Changelog.md @@ -5,8 +5,7 @@ Add a keybinding ("g") to force the ruler to measure from ground terrain. Replac ## Bug fixes Catch when a segment color is not defined, to avoid throwing an error. - - +Fix for incorrect combat speed movement highlighting after the first move. Closes #62. # 0.8.10 ## New features