From f505a233dfd2c30ccdd3f51ae8cc6b6c2b429128 Mon Sep 17 00:00:00 2001 From: macniel Date: Wed, 15 Oct 2025 20:10:52 +0200 Subject: [PATCH] Migrates Specialabilities and Liturgies to DocumentV2 --- src/main.mjs | 12 +-- src/module/sheets/liturgySheet.mjs | 84 ++++++++------- src/module/sheets/specialAbilitySheet.mjs | 101 ++++++++++-------- src/templates/item/item-liturgy-sheet.hbs | 14 --- src/templates/item/liturgy/main-sheet.hbs | 4 + src/templates/item/liturgy/tab-json.hbs | 8 ++ .../item/specialability/main-sheet.hbs | 4 + .../item/specialability/tab-json.hbs | 8 ++ 8 files changed, 134 insertions(+), 101 deletions(-) delete mode 100644 src/templates/item/item-liturgy-sheet.hbs create mode 100644 src/templates/item/liturgy/main-sheet.hbs create mode 100644 src/templates/item/liturgy/tab-json.hbs create mode 100644 src/templates/item/specialability/main-sheet.hbs create mode 100644 src/templates/item/specialability/tab-json.hbs diff --git a/src/main.mjs b/src/main.mjs index 942b340e..21a59bc2 100644 --- a/src/main.mjs +++ b/src/main.mjs @@ -117,20 +117,20 @@ Hooks.once("init", () => { label: 'DSA41.AusruestungLabels.Item' }) foundry.documents.collections.Items.registerSheet('dsa41.liturgy', LiturgySheet, { - types: ["SpecialAbility"], - makeDefault: true, - label: 'DSA41.SpecialAbilityLabels.Item' - }) - foundry.documents.collections.Items.registerSheet('dsa41.specialAbility', SpecialAbilitySheet, { types: ["Liturgy"], makeDefault: true, label: 'DSA41.LiturgyLabels.Item' }) + foundry.documents.collections.Items.registerSheet('dsa41.specialAbility', SpecialAbilitySheet, { + types: ["SpecialAbility"], + makeDefault: true, + label: 'DSA41.SpecialAbilityLabels.Item' + }) foundry.documents.collections.Items.registerSheet('dsa41.activeEffect', ActiveEffectSheet, { types: ['ActiveEffect'], makeDefault: true, - label: 'DSA41.ActiveEffectLabels.ActiveFfect' + label: 'DSA41.ActiveEffectLabels.ActiveEffect' }) game.settings.register('DSA_4-1', 'optional_trefferzonen', { diff --git a/src/module/sheets/liturgySheet.mjs b/src/module/sheets/liturgySheet.mjs index 3bb34124..d2e0f14e 100644 --- a/src/module/sheets/liturgySheet.mjs +++ b/src/module/sheets/liturgySheet.mjs @@ -1,50 +1,62 @@ -export class LiturgySheet extends foundry.appv1.sheets.ItemSheet { - /**@override */ - static get defaultOptions() { - return foundry.utils.mergeObject(super.defaultOptions, { - classes: ['dsa41', 'sheet', 'item', 'liturgy'], - width: 520, - height: 480, +const {DocumentSheetV2, HandlebarsApplicationMixin} = foundry.applications.api + +export class LiturgySheet extends HandlebarsApplicationMixin(DocumentSheetV2) { + + /** @inheritDoc */ + static DEFAULT_OPTIONS = { + position: {width: 520, height: 480}, + classes: ['dsa41', 'sheet', 'item', 'liturgy'], + tag: 'form', + form: { + submitOnChange: true, + closeOnSubmit: false, + handler: LiturgySheet.#onSubmitForm + }, + } + + + static TABS = { + sheet: { tabs: [ - { - navSelector: '.sheet-tabs', - contentSelector: '.sheet-body', - initial: 'description', - }, + {id: 'json', group: 'sheet', label: 'JSON'}, ], - }); + initial: 'json' + } + } + + /** @inheritDoc */ + static PARTS = { + form: { + template: `systems/DSA_4-1/templates/item/liturgy/main-sheet.hbs` + }, + json: { + template: `systems/DSA_4-1/templates/item/liturgy/tab-json.hbs` + }, + } + + /** + * Handle form submission + * @this {EquipmentSheet} + * @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 */ - get template() { - return `systems/DSA_4-1/templates/item/item-liturgy-sheet.hbs`; - } + async _prepareContext(options) { + const context = await super._prepareContext(options); - /** @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(); + const liturgyData = context.document; - // Use a safe clone of the actor data for further operations. - const liturgyData = context.data; - - // Add the actor's data to context.data for easier access, as well as flags. context.system = liturgyData.system; context.flags = liturgyData.flags; context.json = JSON.stringify(liturgyData); 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/module/sheets/specialAbilitySheet.mjs b/src/module/sheets/specialAbilitySheet.mjs index 533f1a8a..4828dbf2 100644 --- a/src/module/sheets/specialAbilitySheet.mjs +++ b/src/module/sheets/specialAbilitySheet.mjs @@ -1,51 +1,62 @@ -export class SpecialAbilitySheet extends foundry.appv1.sheets.ItemSheet { - /**@override */ - static get defaultOptions() { - return foundry.utils.mergeObject(super.defaultOptions, { - classes: ['dsa41', 'sheet', 'item', 'specialability'], - width: 520, - height: 480, +const {DocumentSheetV2, HandlebarsApplicationMixin} = foundry.applications.api + +export class SpecialAbilitySheet extends HandlebarsApplicationMixin(DocumentSheetV2) { + + /** @inheritDoc */ + static DEFAULT_OPTIONS = { + position: {width: 520, height: 480}, + classes: ['dsa41', 'sheet', 'item', 'specialability'], + tag: 'form', + form: { + submitOnChange: true, + closeOnSubmit: false, + handler: SpecialAbilitySheet.#onSubmitForm + }, + } + + + static TABS = { + sheet: { tabs: [ - { - navSelector: '.sheet-tabs', - contentSelector: '.sheet-body', - initial: 'description', - }, + {id: 'json', group: 'sheet', label: 'JSON'}, ], - }); - } - - /** @override */ - get template() { - return `systems/DSA_4-1/templates/item/item-special-ability-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.json = JSON.stringify(advantageData.system, null, 4); - - return context; - } - - activateListeners(html) { - super.activateListeners(html); - - // Everything below here is only needed if the sheet is editable - if (!this.isEditable) { - + initial: 'json' } } + /** @inheritDoc */ + static PARTS = { + form: { + template: `systems/DSA_4-1/templates/item/specialability/main-sheet.hbs` + }, + json: { + template: `systems/DSA_4-1/templates/item/specialability/tab-json.hbs` + }, + } + + /** + * Handle form submission + * @this {EquipmentSheet} + * @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 specialabilityData = context.document; + + context.system = specialabilityData.system; + context.flags = specialabilityData.flags; + context.json = JSON.stringify(specialabilityData); + return context; + } + } diff --git a/src/templates/item/item-liturgy-sheet.hbs b/src/templates/item/item-liturgy-sheet.hbs deleted file mode 100644 index d50d00ce..00000000 --- a/src/templates/item/item-liturgy-sheet.hbs +++ /dev/null @@ -1,14 +0,0 @@ -
- - {{!-- Sheet Tab Navigation --}} - - - {{!-- Sheet Body --}} -
-
-
{{json}}
-
-
-
diff --git a/src/templates/item/liturgy/main-sheet.hbs b/src/templates/item/liturgy/main-sheet.hbs new file mode 100644 index 00000000..38015a2f --- /dev/null +++ b/src/templates/item/liturgy/main-sheet.hbs @@ -0,0 +1,4 @@ +
+ + Alveranische Baustelle, bitte gehen Sie weiter, hier gibt es nichts zu sehen. +
\ No newline at end of file diff --git a/src/templates/item/liturgy/tab-json.hbs b/src/templates/item/liturgy/tab-json.hbs new file mode 100644 index 00000000..a4db94c6 --- /dev/null +++ b/src/templates/item/liturgy/tab-json.hbs @@ -0,0 +1,8 @@ +
+ +
{{json}}
+ +
+ diff --git a/src/templates/item/specialability/main-sheet.hbs b/src/templates/item/specialability/main-sheet.hbs new file mode 100644 index 00000000..fb0530ff --- /dev/null +++ b/src/templates/item/specialability/main-sheet.hbs @@ -0,0 +1,4 @@ +
+ + Sonderfertigkeiten bitte sei Besonders und Fertig +
\ No newline at end of file diff --git a/src/templates/item/specialability/tab-json.hbs b/src/templates/item/specialability/tab-json.hbs new file mode 100644 index 00000000..d9c5d89c --- /dev/null +++ b/src/templates/item/specialability/tab-json.hbs @@ -0,0 +1,8 @@ +
+ +
{{json}}
+ +
+