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 8fadb4b commit 3cda8e6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ options {elevation: 0, reduce:[], tokenId: token.id, token:token} lets the terra
- 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 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.
- verbose - setting this to true will return an object with 'cost' set to the total cost and 'details' as an array of all terrain object found.

A list of Terrain Environments can be found by calling canvas.terrain.environment(); and can be overridden if the environments in your game differ.

Expand Down
12 changes: 5 additions & 7 deletions classes/terrainlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,6 @@ export class TerrainLayer extends PlaceablesLayer {
}

cost(pts, options = {}) {
let details = this.costDetails(pts, options);
return details.cost;
}

costDetails(pts, options = {}) {
let reduceFn = function (cost, reduce) {
let value = parseFloat(reduce.value);

Expand All @@ -95,7 +90,7 @@ export class TerrainLayer extends PlaceablesLayer {
}
}

return Math.max(value, 0);
return value; //Math.max(value, 0);
}

let details = [];
Expand Down Expand Up @@ -205,7 +200,10 @@ export class TerrainLayer extends PlaceablesLayer {
total += (cost != undefined ? cost : 1);
}

return { cost: total, details: details, calculate: calculate };
if (options.verbose === true)
return { cost: total, details: details, calculate: calculate };
else
return total;
}

terrainAt(x, y) {
Expand Down

0 comments on commit 3cda8e6

Please sign in to comment.