From 3869982927c99deeafb8a76f0740bcc063991fc5 Mon Sep 17 00:00:00 2001 From: macniel Date: Wed, 15 Oct 2025 16:24:51 +0200 Subject: [PATCH] migrates advantages to DocumentV2 --- src/main.mjs | 4 +- src/module/sheets/advantageSheet.mjs | 65 +++++++++++++++++++ src/module/sheets/vornachteilSheet.mjs | 56 ---------------- src/templates/item/advantage/main-sheet.hbs | 14 ++++ .../item/advantage/tab-advantage.hbs | 33 ++++++++++ 5 files changed, 114 insertions(+), 58 deletions(-) create mode 100644 src/module/sheets/advantageSheet.mjs delete mode 100644 src/module/sheets/vornachteilSheet.mjs create mode 100644 src/templates/item/advantage/main-sheet.hbs create mode 100644 src/templates/item/advantage/tab-advantage.hbs diff --git a/src/main.mjs b/src/main.mjs index fa69514f..a2c0ed6a 100644 --- a/src/main.mjs +++ b/src/main.mjs @@ -6,7 +6,7 @@ import {SpellDataModel} from "./module/data/spell.mjs"; import {VornachteileDataModel} from "./module/data/vornachteile.mjs"; import {Character} from "./module/documents/character.mjs"; import {CharacterSheet} from "./module/sheets/characterSheet.mjs"; -import {VornachteilSheet} from "./module/sheets/vornachteilSheet.mjs"; +import {AdvantageSheet} from "./module/sheets/advantageSheet.mjs"; import {GroupDataModel} from "./module/data/group.mjs"; import {GroupSheet} from "./module/sheets/groupSheet.mjs"; import {EquipmentDataModel} from "./module/data/equipment.mjs"; @@ -106,7 +106,7 @@ Hooks.once("init", () => { makeDefault: true, label: 'DSA41.SpellLabels.Item', }); - foundry.documents.collections.Items.registerSheet('dsa41.advantage', VornachteilSheet, { + foundry.documents.collections.Items.registerSheet('dsa41.advantage', AdvantageSheet, { types: ["Advantage"], makeDefault: true, label: 'DSA41.VornachteilLabels.Item' diff --git a/src/module/sheets/advantageSheet.mjs b/src/module/sheets/advantageSheet.mjs new file mode 100644 index 00000000..eff15fb4 --- /dev/null +++ b/src/module/sheets/advantageSheet.mjs @@ -0,0 +1,65 @@ +const {DocumentSheetV2, HandlebarsApplicationMixin} = foundry.applications.api + +export class AdvantageSheet extends HandlebarsApplicationMixin(DocumentSheetV2) { + + /** @inheritDoc */ + static DEFAULT_OPTIONS = { + position: {width: 520, height: 480}, + classes: ['dsa41', 'sheet', 'item', 'advantage'], + tag: 'form', + form: { + submitOnChange: true, + closeOnSubmit: false, + handler: AdvantageSheet.#onSubmitForm + } + } + + static TABS = { + sheet: { + tabs: [ + {id: 'advantage', group: 'sheet', label: 'Vorteil'}, + ], + initial: 'advantage' + } + } + + /** @inheritDoc */ + static PARTS = { + form: { + template: `systems/DSA_4-1/templates/item/advantage/main-sheet.hbs` + }, + advantage: { + template: `systems/DSA_4-1/templates/item/advantage/tab-advantage.hbs` + } + } + + /** + * Handle form submission + * @this {MyClass} + * @param {SubmitEvent} event + * @param {HTMLFormElement} form + * @param {FormDataExtended} formData + */ + static async #onSubmitForm(event, form, formData) { + event.preventDefault() + + await this.document.update(formData.object) // Note: formData.object + } + + /** @override */ + async _prepareContext(options) { + const context = await super._prepareContext(options); + const advantageData = context.document; + + context.system = advantageData.system; + context.flags = context.system.flags; + context.hasChoices = context.system.auswahl.length > 0; + context.choices = {} + context.system.auswahl.forEach(a => { + context.choices[a] = a + }) + context.hasModality = context.system.value != null + + return context; + } +} diff --git a/src/module/sheets/vornachteilSheet.mjs b/src/module/sheets/vornachteilSheet.mjs deleted file mode 100644 index 6a9278c6..00000000 --- a/src/module/sheets/vornachteilSheet.mjs +++ /dev/null @@ -1,56 +0,0 @@ -export class VornachteilSheet extends foundry.appv1.sheets.ItemSheet { - /**@override */ - static get defaultOptions() { - return foundry.utils.mergeObject(super.defaultOptions, { - classes: ['dsa41', 'sheet', 'item', 'advantage'], - width: 520, - height: 480, - tabs: [ - { - navSelector: '.sheet-tabs', - contentSelector: '.sheet-body', - initial: 'description', - }, - ], - }); - } - - /** @override */ - get template() { - return `systems/DSA_4-1/templates/item/item-advantage-sheet.hbs`; - } - - /** @override */ - getData() { - // Retrieve the data structure from the base sheet. You can inspect or log - // the context variable to see the structure, but some key properties for - // sheets are the actor object, the data object, whether or not it's - // editable, the items array, and the effects array. - const context = super.getData(); - - // Use a safe clone of the actor data for further operations. - const advantageData = context.data; - - // Add the actor's data to context.data for easier access, as well as flags. - context.system = advantageData.system; - context.flags = advantageData.flags; - context.hasChoices = context.system.auswahl.length > 0; - context.choices = {} - context.system.auswahl.forEach(a => { - context.choices[a] = a - }) - context.hasModality = context.system.value != null - - return context; - } - - activateListeners(html) { - super.activateListeners(html); - - // Everything below here is only needed if the sheet is editable - if (!this.isEditable) { - - } - } - -} diff --git a/src/templates/item/advantage/main-sheet.hbs b/src/templates/item/advantage/main-sheet.hbs new file mode 100644 index 00000000..21d661ee --- /dev/null +++ b/src/templates/item/advantage/main-sheet.hbs @@ -0,0 +1,14 @@ +
+ {{!-- Sheet Tab Navigation --}} + +
\ No newline at end of file diff --git a/src/templates/item/advantage/tab-advantage.hbs b/src/templates/item/advantage/tab-advantage.hbs new file mode 100644 index 00000000..2b11c313 --- /dev/null +++ b/src/templates/item/advantage/tab-advantage.hbs @@ -0,0 +1,33 @@ +
+
+ + + +
+ {{#if hasModality}} +
+ + {{#if hasChoices}} + + {{else}} + + {{/if}} +
+ {{/if}} +
+ + + {{{ system.description}}} + +
+ +
\ No newline at end of file