[#32] Draw available tracked resources from world actors rather than system model.

This commit is contained in:
fyorl 2022-01-13 13:24:44 +00:00
parent db34d156af
commit 9b19f8b590
No known key found for this signature in database
GPG key ID: 3A4E57DAE36AC3C4
5 changed files with 40 additions and 17 deletions

View file

@ -1,10 +1,10 @@
/**
* Extend the base TokenDocument to allow resource to support resource type attributes.
* Extend the base TokenDocument to support resource type attributes.
* @extends {TokenDocument}
*/
export class SimpleTokenDocument extends TokenDocument {
/** @inheritdoc */
getBarAttribute(barName, {alternative}={}) {
getBarAttribute(barName, {alternative}={}) {
const data = super.getBarAttribute(barName, {alternative});
const attr = alternative || this.data[barName]?.attribute;
if ( !data || !attr || !this.actor ) return data;
@ -13,6 +13,20 @@ export class SimpleTokenDocument extends TokenDocument {
data.editable = true;
return data;
}
/* -------------------------------------------- */
static getTrackedAttributes(data, _path=[]) {
if ( data || _path.length ) return super.getTrackedAttributes(data, _path);
data = {};
for ( const model of Object.values(game.system.model.Actor) ) {
foundry.utils.mergeObject(data, model);
}
for ( const actor of game.actors ) {
if ( actor.isTemplate ) foundry.utils.mergeObject(data, actor.toObject().data);
}
return super.getTrackedAttributes(data);
}
}