Add Document class changes to make the Token bars work with my attributes object

This commit is contained in:
Oliver-Akins 2025-06-29 00:46:30 -06:00
parent ae525ce1b8
commit 959f75d55c
2 changed files with 139 additions and 0 deletions

View file

@ -0,0 +1,28 @@
import { Logger } from "../utils/Logger.mjs";
const { Actor } = foundry.documents;
export class TAFActor extends Actor {
async modifyTokenAttribute(attribute, value, isDelta = false, isBar = true) {
Logger.table({ attribute, value, isDelta, isBar });
const attr = foundry.utils.getProperty(this.system, attribute);
const current = isBar ? attr.value : attr;
const update = isDelta ? current + value : value;
if ( update === current ) {
return this;
};
// Determine the updates to make to the actor data
let updates;
if (isBar) {
updates = {[`system.${attribute}.value`]: Math.clamp(update, 0, attr.max)};
} else {
updates = {[`system.${attribute}`]: update};
};
// Allow a hook to override these changes
const allowed = Hooks.call(`modifyTokenAttribute`, {attribute, value, isDelta, isBar}, updates, this);
return allowed !== false ? this.update(updates) : this;
}
};