From ec49c8d0b02175f76ce4807b43fd317d3c8a9d8a Mon Sep 17 00:00:00 2001 From: Kim Mantas Date: Wed, 7 Aug 2024 13:40:52 +0100 Subject: [PATCH] Item Sheet V2: Effects tab --- module/applications/item/item-sheet-2.mjs | 44 +++++++++++++++++++++ module/applications/item/sheet-v2-mixin.mjs | 14 +++++++ templates/items/item-sheet-2.hbs | 10 +++++ 3 files changed, 68 insertions(+) diff --git a/module/applications/item/item-sheet-2.mjs b/module/applications/item/item-sheet-2.mjs index eacf81dc72..502d66145d 100644 --- a/module/applications/item/item-sheet-2.mjs +++ b/module/applications/item/item-sheet-2.mjs @@ -26,6 +26,34 @@ export default class ItemSheet5e2 extends ItemSheetV2Mixin(ItemSheet5e) { return "systems/dnd5e/templates/items/item-sheet-2.hbs"; } + /* -------------------------------------------- */ + /* Rendering */ + /* -------------------------------------------- */ + + /** @inheritDoc */ + async getData(options) { + const context = await super.getData(options); + + // Effects + for ( const category of Object.values(context.effects) ) { + category.effects = await category.effects.reduce(async (arr, effect) => { + effect.updateDuration(); + const { id, name, img, disabled, duration } = effect; + const source = await effect.getSource(); + arr = await arr; + arr.push({ + id, name, img, disabled, duration, source, + parent, + durationParts: duration.remaining ? duration.label.split(", ") : [], + hasTooltip: true + }); + return arr; + }, []); + } + + return context; + } + /* -------------------------------------------- */ /* Event Listeners & Handlers */ /* -------------------------------------------- */ @@ -45,4 +73,20 @@ export default class ItemSheet5e2 extends ItemSheetV2Mixin(ItemSheet5e) { }); } } + + /* -------------------------------------------- */ + /* Filtering */ + /* -------------------------------------------- */ + + /** + * Filter child embedded ActiveEffects based on the current set of filters. + * @param {string} collection The embedded collection name. + * @param {Set} filters Filters to apply to the children. + * @returns {Document[]} + * @protected + */ + _filterChildren(collection, filters) { + if ( collection === "effects" ) return Array.from(this.item.effects); + return []; + } } diff --git a/module/applications/item/sheet-v2-mixin.mjs b/module/applications/item/sheet-v2-mixin.mjs index 0d169e2ad8..41f747bfd4 100644 --- a/module/applications/item/sheet-v2-mixin.mjs +++ b/module/applications/item/sheet-v2-mixin.mjs @@ -168,6 +168,20 @@ export default function ItemSheetV2Mixin(Base) { new ImagePopout(this.item.img, { title, uuid: this.item.uuid }).render(true); } + /* -------------------------------------------- */ + + /** @override */ + _onCreateChild() { + const activeTab = this._tabs?.[0]?.active ?? this.options.tabs[0].initial; + + if ( activeTab === "effects" ) { + return ActiveEffect.implementation.create({ + name: game.i18n.localize("DND5E.EffectNew"), + img: "icons/svg/aura.svg" + }, { parent: this.item, renderSheet: true }); + } + } + /* -------------------------------------------- */ /* Helpers */ /* -------------------------------------------- */ diff --git a/templates/items/item-sheet-2.hbs b/templates/items/item-sheet-2.hbs index 973f784c63..e32cb007d8 100644 --- a/templates/items/item-sheet-2.hbs +++ b/templates/items/item-sheet-2.hbs @@ -130,7 +130,17 @@ {{!-- Description Tab --}} {{> "dnd5e.item-description2" }} + {{!-- Effects Tab --}} +
+ {{> "dnd5e.active-effects2" }} +
+ {{!-- Effect Creation --}} + +