import { DS4Item } from "./item"; import { DS4ItemDataType, isDS4ItemDataTypePhysical } from "./item-data"; /** * Extend the basic ItemSheet with some very simple modifications * @extends {ItemSheet} */ export class DS4ItemSheet extends ItemSheet { /** @override */ static get defaultOptions(): FormApplicationOptions { return mergeObject(super.defaultOptions, { width: 530, height: 400, classes: ["ds4", "sheet", "item"], tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "description" }], }); } /** @override */ get template(): string { const path = "systems/ds4/templates/item"; return `${path}/${this.item.data.type}-sheet.hbs`; } /* -------------------------------------------- */ /** @override */ getData(): ItemSheetData { const data = { ...super.getData(), config: CONFIG.DS4, isOwned: this.item.isOwned, actor: this.item.actor, isPhysical: isDS4ItemDataTypePhysical(this.item.data.data), }; console.log(data); return data; } /* -------------------------------------------- */ /** @override */ setPosition(options: ApplicationPosition = {}): ApplicationPosition { const position = super.setPosition(options); if ("find" in this.element) { const sheetBody = this.element.find(".sheet-body"); const bodyHeight = position.height - 192; sheetBody.css("height", bodyHeight); } else { console.log("Failure setting position."); } return position; } private readonly ownedItemActiveEffectWarning = "Managing Active Effects within an Owned Item is not currently supported and will be added in a subsequent update."; /* -------------------------------------------- */ /** @override */ activateListeners(html: JQuery): void { super.activateListeners(html); if (!this.options.editable) return; html.find(".effect-control").on("click", this._onManageActiveEffect.bind(this)); } /** * Handle management of ActiveEffects. * @param {Event} event The originating click event */ private async _onManageActiveEffect(event: JQuery.ClickEvent): Promise { event.preventDefault(); if (this.item.isOwned) { return ui.notifications.warn(this.ownedItemActiveEffectWarning); } const a = event.currentTarget; const li = $(a).parents(".effect"); switch (a.dataset["action"]) { case "create": return this._createActiveEffect(); case "edit": const effect = this.item.effects.get(li.data("effectId")); return effect.sheet.render(true); case "delete": { return this.item.deleteEmbeddedEntity("ActiveEffect", li.data("effectId")); } } } /** * Create a new ActiveEffect for the item using default data. */ private async _createActiveEffect(): Promise { const label = `New Effect`; const createData = { label: label, changes: [], duration: {}, transfer: true, }; const effect = await ActiveEffect.create(createData, this.item); return effect.create({}); } }