Skip to content

Commit

Permalink
Merge branch 'feature/issue-62-combat-movement' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
caewok committed Apr 5, 2024
2 parents 3375b49 + 20eb265 commit 0219c02
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
7 changes: 6 additions & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
25 changes: 19 additions & 6 deletions scripts/Ruler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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);

Expand All @@ -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.
Expand Down

0 comments on commit 0219c02

Please sign in to comment.