diff --git a/Changelog.md b/Changelog.md index a02fd65..65160bf 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,6 +1,11 @@ # 0.8.11 -Catch when a segment color is not defined, to avoid throwing an error. +## 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. +Fix for incorrect combat speed movement highlighting after the first move. Closes #62. # 0.8.10 ## New features diff --git a/scripts/Ruler.js b/scripts/Ruler.js index 5828aee..185d7de 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,23 @@ 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 ( (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 +449,8 @@ function _computeTokenSpeed() { } // Increment to the next speed category. - speedCategory = categoryIter.next().value; - maxDistance = maxDistFn(token, speedCategory, tokenSpeed); + // Next category will be selected in the while loop above: first category to exceed minDistance. + minDistance = maxDistance; } // Increment totals.