Add api endpoint to determine the distance that a token has moved already

This commit is contained in:
Manuel Vögele
2021-04-08 10:45:14 +02:00
parent c66ec46aed
commit 35624a37aa
5 changed files with 29 additions and 12 deletions
+12
View File
@@ -1,5 +1,8 @@
import {measureDistances} from "./compatibility.js";
import {getMovementHistory} from "./movement_tracking.js";
import {GenericSpeedProvider, SpeedProvider} from "./speed_provider.js"
import {settingsKey} from "./settings.js"
import {getTokenShape} from "./util.js";
export const availableSpeedProviders = {}
export let currentSpeedProvider = undefined
@@ -104,6 +107,15 @@ export function getCostFromSpeedProvider(token, area) {
return currentSpeedProvider.getCostForStep(token, area);
}
export function getMovedDistanceFromToken(token) {
const history = getMovementHistory(token);
const segments = Ruler.dragRulerGetRaysFromWaypoints(history, {x: token.x, y: token.y}).map(ray => {return {ray}});
const shape = getTokenShape(token);
const distances = measureDistances(segments, token, shape);
// Sum up the distances
return distances.reduce((acc, val) => acc + val, 0);
}
export function registerModule(moduleId, speedProvider) {
// Check if a module with the given id exists and is currently enabled
const module = game.modules.get(moduleId)