mirror of
https://github.com/RoY7x/worldbuilding.git
synced 2025-07-05 14:10:42 -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
38
module/token.js
Normal file
38
module/token.js
Normal file
|
@ -0,0 +1,38 @@
|
|||
/**
|
||||
* Extend the base TokenDocument to allow resource to support resource type attributes.
|
||||
* @extends {TokenDocument}
|
||||
*/
|
||||
export class SimpleTokenDocument extends TokenDocument {
|
||||
/** @inheritdoc */
|
||||
getBarAttribute(barName, {alternative}={}) {
|
||||
const data = super.getBarAttribute(barName, {alternative});
|
||||
const attr = alternative || this.data[barName]?.attribute;
|
||||
if ( !data || !attr || !this.actor ) return data;
|
||||
const current = foundry.utils.getProperty(this.actor.data.data, attr);
|
||||
if ( "min" in current ) data.min = parseInt(current.min || 0);
|
||||
data.editable = true;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
||||
|
||||
/**
|
||||
* Extend the base Token class to implement additional system-specific logic.
|
||||
* @extends {Token}
|
||||
*/
|
||||
export class SimpleToken extends Token {
|
||||
_drawBar(number, bar, data) {
|
||||
if ( "min" in data ) {
|
||||
// Copy the data to avoid mutating what the caller gave us.
|
||||
data = {...data};
|
||||
// Shift the value and max by the min to ensure that the bar's percentage is drawn accurately if this resource has
|
||||
// a non-zero min.
|
||||
data.value -= data.min;
|
||||
data.max -= data.min;
|
||||
}
|
||||
return super._drawBar(number, bar, data);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue