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
+10 -1
View File
@@ -1,5 +1,6 @@
import {getCostFromSpeedProvider} from "./api.js";
import {getColorForDistance} from "./main.js"
import {highlightTokenShape} from "./util.js"
import {getAreaFromPositionAndShape, highlightTokenShape} from "./util.js";
export function getHexSizeSupportTokenGridCenter(token) {
const tokenCenterOffset = CONFIG.hexSizeSupport.getCenterOffset(token)
@@ -12,3 +13,11 @@ export function highlightMeasurementTerrainRuler(ray, startDistance, tokenShape=
highlightTokenShape.call(this, space, tokenShape, color, alpha)
}
}
export function measureDistances(segments, token, shape, gridSpaces=true) {
const terrainRulerAvailable = game.modules.get("terrain-ruler")?.active && canvas.grid.type !== CONST.GRID_TYPES.GRIDLESS;
if (terrainRulerAvailable)
return game.terrainRuler.measureDistances(segments, {costFunction: (x, y) => getCostFromSpeedProvider(token, getAreaFromPositionAndShape({x, y}, shape), {x, y})});
else
return canvas.grid.measureDistances(segments, { gridSpaces });
}