[#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

@ -21,6 +21,16 @@ export class SimpleActor extends Actor {
return EntitySheetHelper.createDialog.call(this, data, options);
}
/* -------------------------------------------- */
/**
* Is this Actor used as a template for other Actors?
* @type {boolean}
*/
get isTemplate() {
return !!this.getFlag("worldbuilding", "isTemplate");
}
/* -------------------------------------------- */
/* Roll Data Preparation */
/* -------------------------------------------- */

View file

@ -20,4 +20,14 @@ export class SimpleItem extends Item {
static async createDialog(data={}, options={}) {
return EntitySheetHelper.createDialog.call(this, data, options);
}
/* -------------------------------------------- */
/**
* Is this Item used as a template for other Items?
* @type {boolean}
*/
get isTemplate() {
return !!this.getFlag("worldbuilding", "isTemplate");
}
}

View file

@ -115,7 +115,7 @@ Hooks.on("getActorDirectoryEntryContext", (html, options) => {
icon: '<i class="fas fa-stamp"></i>',
condition: li => {
const actor = game.actors.get(li.data(idAttr));
return !actor.getFlag("worldbuilding", "isTemplate");
return !actor.isTemplate;
},
callback: li => {
const actor = game.actors.get(li.data(idAttr));
@ -129,7 +129,7 @@ Hooks.on("getActorDirectoryEntryContext", (html, options) => {
icon: '<i class="fas fa-times"></i>',
condition: li => {
const actor = game.actors.get(li.data(idAttr));
return actor.getFlag("worldbuilding", "isTemplate");
return actor.isTemplate;
},
callback: li => {
const actor = game.actors.get(li.data(idAttr));
@ -149,7 +149,7 @@ Hooks.on("getItemDirectoryEntryContext", (html, options) => {
icon: '<i class="fas fa-stamp"></i>',
condition: li => {
const item = game.items.get(li.data(idAttr));
return !item.getFlag("worldbuilding", "isTemplate");
return !item.isTemplate;
},
callback: li => {
const item = game.items.get(li.data(idAttr));
@ -163,7 +163,7 @@ Hooks.on("getItemDirectoryEntryContext", (html, options) => {
icon: '<i class="fas fa-times"></i>',
condition: li => {
const item = game.items.get(li.data(idAttr));
return item.getFlag("worldbuilding", "isTemplate");
return item.isTemplate;
},
callback: li => {
const item = game.items.get(li.data(idAttr));

View file

@ -1,11 +0,0 @@
export class SimpleTokenDocument extends TokenDocument {
/** @inheritdoc */
getBarAttribute(barName, {alternative}={}) {
const attr = super.getBarAttribute(barName, {alternative});
if ( attr === null ) return null;
attr.editable = true; // Attribute always editable, super requires attr to exist in actor template
return attr;
}
}

View file

@ -1,5 +1,5 @@
/**
* 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 {
@ -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);
}
}