mirror of
https://github.com/RoY7x/worldbuilding.git
synced 2025-07-06 06:30:39 -04:00
[#25] Ensure resource attribute values are clamped between their min and max. Ensure token attribute update deltas are applied correctly to resource attributes. Draw attribute bars appropriately when attribute min is non-zero.
This commit is contained in:
parent
abc9e949a7
commit
d799fb1c56
5 changed files with 72 additions and 3 deletions
|
@ -587,4 +587,21 @@ export class EntitySheetHelper {
|
|||
options: options
|
||||
});
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Ensure the resource values are within the specified min and max.
|
||||
* @param {object} attrs The Document's attributes.
|
||||
*/
|
||||
static clampResourceValues(attrs) {
|
||||
const flat = foundry.utils.flattenObject(attrs);
|
||||
for ( const [attr, value] of Object.entries(flat) ) {
|
||||
const parts = attr.split(".");
|
||||
if ( parts.pop() !== "value" ) continue;
|
||||
const current = foundry.utils.getProperty(attrs, parts.join("."));
|
||||
if ( current?.dtype !== "Resource" ) continue;
|
||||
foundry.utils.setProperty(attrs, attr, Math.clamped(value, current.min || 0, current.max || 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue