Skip to content

Commit

Permalink
1.0.17 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
IronMonk88 committed Mar 30, 2021
1 parent f6ee885 commit 8fadb4b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ options {elevation: 0, reduce:[], tokenId: token.id, token:token} lets the terra
- reduce: [{id:'arctic',value:1}] will result in any calculation essentially ignoring arctic terrain. [{id:'arctic',value:'-1',stop:1}] will result in any calculation reducing the difficulty by 1 and stopping at 1. You can also use '+1' to add to the difficulty. stop is an optional parameter. And you can use the id 'token' to have these settings applied when calculating cost through another token's space.
- tokenId - pass in the token id to avoid having the result use the token's own space as difficult terrain.
- token - pass in the token, will use both the id and elevation of that token. passing in elevation:false will result in the the function ignoring the token's elevation.
- calculate - this is how you'd like the cost to be calculated. default is 'maximum', which returns the highest value found while looking through all terrains. you can also passin 'additive' if you want all costs to be added together.
- calculate - this is how you'd like the cost to be calculated. default is 'maximum', which returns the highest value found while looking through all terrains. you can also pass in 'additive' if you want all costs to be added together. And if neither of those work, you can pass your own function in to make the final calculation `calculate(cost, total, object)` with cost being the current cost and total being the running total so far and object being either the terrain, measure, or token that's caused the difficult terrain.

if you'd like all the details of how the cost was acheived, call costDetails(pts, options). It will return the cost, and an array of details that combined to make the cost.

Expand Down
20 changes: 12 additions & 8 deletions classes/terrainlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,15 @@ export class TerrainLayer extends PlaceablesLayer {

let calculate = options.calculate || 'maximum';
let calculateFn = function (cost, total) { return cost; };
switch (calculate) {
case 'maximum':
calculateFn = function (cost, total) { return Math.max(cost, total); }; break;
case 'additive':
calculateFn = function (cost, total) { return cost + total; }; break;
if (typeof calculate == 'function')
calculateFn = calculate;
else {
switch (calculate) {
case 'maximum':
calculateFn = function (cost, total) { return Math.max(cost, total); }; break;
case 'additive':
calculateFn = function (cost, total) { return cost + total; }; break;
}
}

for (let pt of pts) {
Expand All @@ -138,7 +142,7 @@ export class TerrainLayer extends PlaceablesLayer {
detail.reduce = reduce;
terraincost = reduceFn(terraincost, reduce);
}
cost = calculateFn(terraincost, cost);
cost = calculateFn(terraincost, cost, terrain);
detail.total = cost;

details.push(detail);
Expand All @@ -165,7 +169,7 @@ export class TerrainLayer extends PlaceablesLayer {
terraincost = reduceFn(terraincost, reduce);
}

cost = calculateFn(terraincost, cost);
cost = calculateFn(terraincost, cost, measure);
detail.total = cost;

details.push(detail);
Expand All @@ -189,7 +193,7 @@ export class TerrainLayer extends PlaceablesLayer {
terraincost = reduceFn(terraincost, reduce);
}

cost = calculateFn(terraincost, cost);
cost = calculateFn(terraincost, cost, token);
detail.total = cost;

details.push(detail);
Expand Down

0 comments on commit 8fadb4b

Please sign in to comment.