[#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:
fyorl 2022-01-12 21:03:22 +00:00
parent abc9e949a7
commit d799fb1c56
No known key found for this signature in database
GPG key ID: 3A4E57DAE36AC3C4
5 changed files with 72 additions and 3 deletions

View file

@ -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));
}
}
}