Remove getCostForStep SpedProvider function in favor or the Enhanced Terrain Layer API

This commit is contained in:
Manuel Vögele
2022-10-13 08:18:59 +02:00
parent ff9b187d90
commit 46c504341c
2 changed files with 6 additions and 35 deletions
+6 -14
View File
@@ -114,18 +114,6 @@ export function getUnreachableColorFromSpeedProvider() {
}
}
export function getCostFromSpeedProvider(token, area, options) {
try {
if (currentSpeedProvider instanceof Function) {
return SpeedProvider.prototype.getCostForStep.call(undefined, token, area, options);
}
return currentSpeedProvider.getCostForStep(token, area, options);
} catch (e) {
console.error(e);
return 1;
}
}
export function getColorForDistanceAndToken(distance, token, ranges = null) {
if (!ranges) {
ranges = getRangesFromSpeedProvider(token);
@@ -159,8 +147,12 @@ export function getMovedDistanceFromToken(token) {
}
export function buildCostFunction(token, shape) {
return (x, y, costOptions = {}) =>
getCostFromSpeedProvider(token, getAreaFromPositionAndShape({x, y}, shape), costOptions);
return (x, y, costOptions = {}) => {
costOptions.token = token;
const area = getAreaFromPositionAndShape({x, y}, shape);
const costs = area.map(space => canvas.terrain.cost({x: space.x, y: space.y, costOptions}));
return costs.reduce((max, current) => Math.max(max, current));
};
}
export function registerModule(moduleId, speedProvider) {