Skip to content

Commit

Permalink
Fix diagonal movement calculation
Browse files Browse the repository at this point in the history
Closes #18
  • Loading branch information
KitCat420 committed Jun 22, 2024
1 parent 610364e commit 7a84bd0
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- Prevent weapons from becoming unequipped when switching weapon sets
- Only allow weapons with attack actions and attacks for weapon sets
- Remove background skills from drawer when not active
- Fix movement calculation for diagonals

## 0.9.4
- Top-align portrait tooltips to avoid overlapping actual text
Expand Down
1 change: 0 additions & 1 deletion modules/argon/buttons/itemButton.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,6 @@ export function itemButton(ARGON) {
})
}

console.log(action)
if (action.data.duration.value) {
details.push({
label: game.i18n.localize("PF1.Duration"),
Expand Down
49 changes: 49 additions & 0 deletions modules/argon/movementHud.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export function movementHud(ARGON) {
constructor(props) {
super(props);
this.triggerCount = 0;
this.movedDiagonals = 0;
}

get isUnchained() {
Expand All @@ -20,6 +21,52 @@ export function movementHud(ARGON) {
return Math.floor((isElevated ? flySpeed : landSpeed) / 5);
}

onTokenUpdate(updates, context) {
if (updates.x === undefined && updates.y === undefined) return;
console.log(updates, context)
const dimensions = canvas.dimensions.distance;

const distanceX = Math.floor(canvas.grid.measureDistance({
x: this.token.x,
y: 0
}, {x: updates.x ?? this.token.x, y: 0}, {gridSpaces: true}) / dimensions);

const distanceY = Math.floor(canvas.grid.measureDistance({x: 0, y: this.token.y}, {
x: 0,
y: updates.y ?? this.token.y
}, {gridSpaces: true}) / dimensions);

const diagonals = Math.min(distanceX, distanceY);
const straights = Math.abs(distanceX - distanceY);
const diagonalRule = game.settings.get("pf1", "diagonalMovement");

let distance = straights;
switch(diagonalRule) {
case "555":
distance += diagonals;
break;

case "5105":
const diagonalDistance = diagonals * 1.5;
distance += !!(this.movedDiagonals % 2) === !!context?.isUndo ? Math.floor(diagonalDistance) : Math.ceil(diagonalDistance);
break;

default:
console.error("Movement rule not supported.");
distance += diagonals;
break;
}

if (context?.isUndo) {
this.movementUsed -= distance;
this.movedDiagonals -= diagonals;
} else {
this.movementUsed += distance;
this.movedDiagonals += diagonals;
}
this.updateMovement();
}

updateMovement() {
super.updateMovement();

Expand Down Expand Up @@ -66,11 +113,13 @@ export function movementHud(ARGON) {
_onNewRound(combat) {
super._onNewRound(combat);
this.triggerCount = 0;
this.movedDiagonals = 0;
}

_onCombatEnd(combat) {
super._onCombatEnd(combat);
this.triggerCount = 0;
this.movedDiagonals = 0;
}

}
Expand Down

0 comments on commit 7a84bd0

Please sign in to comment.