/** * 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); } }