Remove getCostForStep SpedProvider function in favor or the Enhanced Terrain Layer API
This commit is contained in:
+6
-14
@@ -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) {
|
export function getColorForDistanceAndToken(distance, token, ranges = null) {
|
||||||
if (!ranges) {
|
if (!ranges) {
|
||||||
ranges = getRangesFromSpeedProvider(token);
|
ranges = getRangesFromSpeedProvider(token);
|
||||||
@@ -159,8 +147,12 @@ export function getMovedDistanceFromToken(token) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function buildCostFunction(token, shape) {
|
export function buildCostFunction(token, shape) {
|
||||||
return (x, y, costOptions = {}) =>
|
return (x, y, costOptions = {}) => {
|
||||||
getCostFromSpeedProvider(token, getAreaFromPositionAndShape({x, y}, shape), 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) {
|
export function registerModule(moduleId, speedProvider) {
|
||||||
|
|||||||
@@ -56,27 +56,6 @@ export class SpeedProvider {
|
|||||||
return 0xff0000;
|
return 0xff0000;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the cost for a token to step into the specificed area.
|
|
||||||
* The area indicates the whole area that the token will occupy (for tokens larger than 1x1) the array will more than one entry.
|
|
||||||
* The return value should be an integer indicating a multiplicator by that the cost of that step should be increased.
|
|
||||||
* (1 is regular cost, 2 costs double, 3 costs triple, ...)
|
|
||||||
*
|
|
||||||
* Parameters:
|
|
||||||
* - options: An object used to configure Enhanced Terrain Layer's cost calculation. Ex: If options.ignoreGrid is set to true, then Euclidean measurement can be forced on a gridded map.
|
|
||||||
*
|
|
||||||
* This function is only called if the Enhanced Terrain Layer and Terrain Ruler modules are enabled.
|
|
||||||
*
|
|
||||||
* Implementing this method is optional and only needs to be done if you want to provide a custom cost function (for example to allow tokens to ignore difficult terrain)
|
|
||||||
*/
|
|
||||||
getCostForStep(token, area, options = {}) {
|
|
||||||
// Lookup the cost for each square occupied by the token
|
|
||||||
options.token = token;
|
|
||||||
const costs = area.map(space => terrainRuler.getCost(space.x, space.y, options));
|
|
||||||
// Return the maximum of the costs
|
|
||||||
return costs.reduce((max, current) => Math.max(max, current));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a boolean indicating whether this token will use a Ruler or not.
|
* Returns a boolean indicating whether this token will use a Ruler or not.
|
||||||
* If this is returns `false` for a token Drag Ruler will be disabled for that token. Dragging a token for which this function
|
* If this is returns `false` for a token Drag Ruler will be disabled for that token. Dragging a token for which this function
|
||||||
|
|||||||
Reference in New Issue
Block a user