Update active rulers when the movement history changes
This commit is contained in:
@@ -1,4 +1,7 @@
|
|||||||
## In development
|
## In development
|
||||||
|
### Bugfixes
|
||||||
|
- If the movement history for a token is being updated (for example by a history reset by the gm) while a player is currently measuring a distance for that token the history change is now being reflected in the active measurement.
|
||||||
|
|
||||||
### Compatibility
|
### Compatibility
|
||||||
- Drag Ruler's Generic SpeedProvider is now aware of good default values for the Savage Worlds Adventure Edition game system
|
- Drag Ruler's Generic SpeedProvider is now aware of good default values for the Savage Worlds Adventure Edition game system
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import {highlightMeasurementTerrainRuler, measureDistances} from "./compatibilit
|
|||||||
import {getGridPositionFromPixels} from "./foundry_fixes.js";
|
import {getGridPositionFromPixels} from "./foundry_fixes.js";
|
||||||
import {getColorForDistance} from "./main.js"
|
import {getColorForDistance} from "./main.js"
|
||||||
import {trackRays} from "./movement_tracking.js"
|
import {trackRays} from "./movement_tracking.js"
|
||||||
|
import {recalculate} from "./socket.js";
|
||||||
import {applyTokenSizeOffset, getSnapPointForToken, getTokenShape, highlightTokenShape, zip} from "./util.js";
|
import {applyTokenSizeOffset, getSnapPointForToken, getTokenShape, highlightTokenShape, zip} from "./util.js";
|
||||||
|
|
||||||
// This is a modified version of Ruler.moveToken from foundry 0.7.9
|
// This is a modified version of Ruler.moveToken from foundry 0.7.9
|
||||||
@@ -87,7 +88,7 @@ async function animateTokens(tokens, draggedToken, draggedRays, wasPaused) {
|
|||||||
for (const {token} of tokenAnimationData) {
|
for (const {token} of tokenAnimationData) {
|
||||||
token._noAnimate = false;
|
token._noAnimate = false;
|
||||||
}
|
}
|
||||||
trackRays(tokenAnimationData.map(({token}) => token), tokenAnimationData.map(({rays}) => rays));
|
trackRays(tokens, tokenAnimationData.map(({rays}) => rays)).then(() => recalculate(tokens));
|
||||||
}
|
}
|
||||||
|
|
||||||
function calculateTokenOffset(tokenA, tokenB) {
|
function calculateTokenOffset(tokenA, tokenB) {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import {performMigrations} from "./migration.js"
|
|||||||
import {DragRulerRuler} from "./ruler.js";
|
import {DragRulerRuler} from "./ruler.js";
|
||||||
import {getMovementHistory, resetMovementHistory} from "./movement_tracking.js";
|
import {getMovementHistory, resetMovementHistory} from "./movement_tracking.js";
|
||||||
import {registerSettings, settingsKey} from "./settings.js"
|
import {registerSettings, settingsKey} from "./settings.js"
|
||||||
|
import {recalculate} from "./socket.js";
|
||||||
import {SpeedProvider} from "./speed_provider.js"
|
import {SpeedProvider} from "./speed_provider.js"
|
||||||
|
|
||||||
Hooks.once("init", () => {
|
Hooks.once("init", () => {
|
||||||
@@ -22,6 +23,7 @@ Hooks.once("init", () => {
|
|||||||
getMovedDistanceFromToken,
|
getMovedDistanceFromToken,
|
||||||
registerModule,
|
registerModule,
|
||||||
registerSystem,
|
registerSystem,
|
||||||
|
recalculate,
|
||||||
resetMovementHistory,
|
resetMovementHistory,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import {measureDistances} from "./compatibility.js";
|
import {measureDistances} from "./compatibility.js";
|
||||||
import {updateCombatantDragRulerFlags} from "./socket.js";
|
import {recalculate, updateCombatantDragRulerFlags} from "./socket.js";
|
||||||
import {getTokenShape, zip} from "./util.js";
|
import {getTokenShape, zip} from "./util.js";
|
||||||
|
|
||||||
function initTrackingFlag(combatant) {
|
function initTrackingFlag(combatant) {
|
||||||
@@ -90,4 +90,5 @@ export async function resetMovementHistory(combat, combatantId) {
|
|||||||
dragRulerFlags.trackedRound = null;
|
dragRulerFlags.trackedRound = null;
|
||||||
dragRulerFlags.rulerState = null;
|
dragRulerFlags.rulerState = null;
|
||||||
await updateCombatantDragRulerFlags(combat, [{_id: combatantId, dragRulerFlags}]);
|
await updateCombatantDragRulerFlags(combat, [{_id: combatantId, dragRulerFlags}]);
|
||||||
|
recalculate();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import {measure} from "./foundry_imports.js"
|
import {measure} from "./foundry_imports.js"
|
||||||
|
import {getMovementHistory} from "./movement_tracking.js";
|
||||||
import {settingsKey} from "./settings.js";
|
import {settingsKey} from "./settings.js";
|
||||||
import {getSnapPointForToken} from "./util.js";
|
import {getSnapPointForToken} from "./util.js";
|
||||||
|
|
||||||
@@ -78,6 +79,11 @@ export class DragRulerRuler extends Ruler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dragRulerClearWaypoints() {
|
||||||
|
this.waypoints = [];
|
||||||
|
this.labels.removeChildren().forEach(c => c.destroy());
|
||||||
|
}
|
||||||
|
|
||||||
dragRulerDeleteWaypoint(event={preventDefault: () => {return}}) {
|
dragRulerDeleteWaypoint(event={preventDefault: () => {return}}) {
|
||||||
if (this.waypoints.filter(w => !w.isPrevious).length > 1) {
|
if (this.waypoints.filter(w => !w.isPrevious).length > 1) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
@@ -100,6 +106,22 @@ export class DragRulerRuler extends Ruler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async dragRulerRecalculate(tokenIds) {
|
||||||
|
if (this._state !== Ruler.STATES.MEASURING)
|
||||||
|
return;
|
||||||
|
if (tokenIds && !tokenIds.includes(this.draggedToken.id))
|
||||||
|
return;
|
||||||
|
const waypoints = this.waypoints.filter(waypoint => !waypoint.isPrevious);
|
||||||
|
this.dragRulerClearWaypoints();
|
||||||
|
if (game.settings.get(settingsKey, "enableMovementHistory"))
|
||||||
|
this.dragRulerAddWaypointHistory(getMovementHistory(this.draggedToken));
|
||||||
|
for (const waypoint of waypoints) {
|
||||||
|
this.dragRulerAddWaypoint(waypoint, false);
|
||||||
|
}
|
||||||
|
this.measure(this.destination);
|
||||||
|
game.user.broadcastActivity({ruler: this});
|
||||||
|
}
|
||||||
|
|
||||||
static dragRulerGetRaysFromWaypoints(waypoints, destination) {
|
static dragRulerGetRaysFromWaypoints(waypoints, destination) {
|
||||||
if ( destination )
|
if ( destination )
|
||||||
waypoints = waypoints.concat([destination]);
|
waypoints = waypoints.concat([destination]);
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ let socket;
|
|||||||
Hooks.once("socketlib.ready", () => {
|
Hooks.once("socketlib.ready", () => {
|
||||||
socket = socketlib.registerModule("drag-ruler");
|
socket = socketlib.registerModule("drag-ruler");
|
||||||
socket.register("updateCombatantDragRulerFlags", _socketUpdateCombatantDragRulerFlags);
|
socket.register("updateCombatantDragRulerFlags", _socketUpdateCombatantDragRulerFlags);
|
||||||
|
socket.register("recalculate", _socketRecalculate);
|
||||||
});
|
});
|
||||||
|
|
||||||
export function updateCombatantDragRulerFlags(combat, updates) {
|
export function updateCombatantDragRulerFlags(combat, updates) {
|
||||||
@@ -32,3 +33,11 @@ async function _socketUpdateCombatantDragRulerFlags(combatId, updates) {
|
|||||||
});
|
});
|
||||||
await combat.updateEmbeddedEntity("Combatant", updates, {diff: false});
|
await combat.updateEmbeddedEntity("Combatant", updates, {diff: false});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function recalculate(tokens) {
|
||||||
|
socket.executeForEveryone(_socketRecalculate, tokens ? tokens.map(token => token.id) : undefined);
|
||||||
|
}
|
||||||
|
|
||||||
|
function _socketRecalculate(tokenIds) {
|
||||||
|
return canvas.controls.ruler.dragRulerRecalculate(tokenIds);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user