Skip to content

Commit

Permalink
Item Sheet V2: Effects tab
Browse files Browse the repository at this point in the history
  • Loading branch information
Fyorl committed Aug 7, 2024
1 parent e62662f commit ec49c8d
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
44 changes: 44 additions & 0 deletions module/applications/item/item-sheet-2.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
/* -------------------------------------------- */
Expand All @@ -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<string>} filters Filters to apply to the children.
* @returns {Document[]}
* @protected
*/
_filterChildren(collection, filters) {
if ( collection === "effects" ) return Array.from(this.item.effects);
return [];
}
}
14 changes: 14 additions & 0 deletions module/applications/item/sheet-v2-mixin.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
/* -------------------------------------------- */
Expand Down
10 changes: 10 additions & 0 deletions templates/items/item-sheet-2.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,17 @@
{{!-- Description Tab --}}
{{> "dnd5e.item-description2" }}

{{!-- Effects Tab --}}
<div class="tab effects" data-group="primary" data-tab="effects">
{{> "dnd5e.active-effects2" }}
</div>

</section>

{{!-- Effect Creation --}}
<button type="button" class="create-child gold-button"
aria-label="{{ localize "SIDEBAR.Create" type=(localize "DOCUMENT.ActiveEffect") }}">
<i class="fas fa-plus"></i>
</button>

</form>

0 comments on commit ec49c8d

Please sign in to comment.