Add api endpoint to determine the distance that a token has moved already
This commit is contained in:
+12
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user