diff --git a/src/main.mjs b/src/main.mjs index a2c0ed6a..942b340e 100644 --- a/src/main.mjs +++ b/src/main.mjs @@ -10,7 +10,7 @@ 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"; -import {AusruestungSheet} from "./module/sheets/equipmentSheet.mjs"; +import {EquipmentSheet} from "./module/sheets/equipmentSheet.mjs"; import {CreatureDataModel} from "./module/data/creature.mjs"; import {CreatureSheet} from "./module/sheets/creatureSheet.mjs"; import {LiturgySheet} from "./module/sheets/liturgySheet.mjs"; @@ -111,7 +111,7 @@ Hooks.once("init", () => { makeDefault: true, label: 'DSA41.VornachteilLabels.Item' }) - foundry.documents.collections.Items.registerSheet('dsa41.equipment', AusruestungSheet, { + foundry.documents.collections.Items.registerSheet('dsa41.equipment', EquipmentSheet, { types: ["Equipment"], makeDefault: false, label: 'DSA41.AusruestungLabels.Item' diff --git a/src/module/sheets/advantageSheet.mjs b/src/module/sheets/advantageSheet.mjs index eff15fb4..62696148 100644 --- a/src/module/sheets/advantageSheet.mjs +++ b/src/module/sheets/advantageSheet.mjs @@ -35,7 +35,7 @@ export class AdvantageSheet extends HandlebarsApplicationMixin(DocumentSheetV2) /** * Handle form submission - * @this {MyClass} + * @this {AdvantageSheet} * @param {SubmitEvent} event * @param {HTMLFormElement} form * @param {FormDataExtended} formData diff --git a/src/module/sheets/equipmentSheet.mjs b/src/module/sheets/equipmentSheet.mjs index d3d769f8..2e12f378 100644 --- a/src/module/sheets/equipmentSheet.mjs +++ b/src/module/sheets/equipmentSheet.mjs @@ -1,42 +1,121 @@ -export class AusruestungSheet extends foundry.appv1.sheets.ItemSheet { - /**@override */ - static get defaultOptions() { - return foundry.utils.mergeObject(super.defaultOptions, { - classes: ['dsa41', 'sheet', 'item', 'equipment'], - width: 520, - height: 480, +const {DocumentSheetV2, HandlebarsApplicationMixin} = foundry.applications.api + +/** + * @typedef ApplicationTab + * @property {string} id + * @property {string} group + * @property {boolean} active + * @property {string} cssClass + * @property {string} [label] + * @property {string} [icon] + * @property {string} [tooltip] + */ + +export class EquipmentSheet extends HandlebarsApplicationMixin(DocumentSheetV2) { + + /** @inheritDoc */ + static DEFAULT_OPTIONS = { + position: {width: 640, height: 480}, + classes: ['dsa41', 'sheet', 'item', 'equipment'], + tag: 'form', + form: { + submitOnChange: true, + closeOnSubmit: false, + handler: EquipmentSheet.#onSubmitForm + }, + actions: { + editImage: + DocumentSheetV2.DEFAULT_OPTIONS.actions.editImage + + } + } + + static TABS = { + sheet: { tabs: [ - { - navSelector: '.sheet-tabs', - contentSelector: '.sheet-body', - initial: 'description', - }, + {id: 'meta', group: 'sheet', label: 'Meta'}, + // Additional Tabs are added based on the nature of this item + ], - }); + initial: 'meta' + } } - /** @override */ - get template() { - return `systems/DSA_4-1/templates/item/item-equipment-sheet.hbs`; + + /** @inheritDoc */ + static PARTS = { + form: { + template: `systems/DSA_4-1/templates/item/equipment/main-sheet.hbs` + }, + meta: { + template: `systems/DSA_4-1/templates/item/equipment/tab-meta.hbs` + }, + melee: { + template: `systems/DSA_4-1/templates/item/equipment/tab-melee.hbs` + }, + ranged: { + template: `systems/DSA_4-1/templates/item/equipment/tab-ranged.hbs` + }, + container: { + template: `systems/DSA_4-1/templates/item/equipment/tab-container.hbs` + }, + armor: { + template: `systems/DSA_4-1/templates/item/equipment/tab-armor.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(); + /** + * Handle form submission + * @this {EquipmentSheet} + * @param {SubmitEvent} event + * @param {HTMLFormElement} form + * @param {FormDataExtended} formData + */ + static async #onSubmitForm(event, form, formData) { + event.preventDefault() - // Use a safe clone of the actor data for further operations. - const equipmentData = context.data; + let normalisedFormData = {} - // Add the actor's data to context.data for easier access, as well as flags. - context.system = equipmentData.system; - context.flags = equipmentData.flags; + Object.entries(formData.object).forEach(([key, value]) => { + if (Array.isArray(value)) { + normalisedFormData[key] = value[0] + } else { + normalisedFormData[key] = value + } + }) - context.quantity = context.system.quantity; - context.description = context.system.description; + await this.document.update(normalisedFormData) // Note: formData.object + } + + async _preparePartContext(partId, context) { + switch (partId) { + case 'meta': + this.#prepareMetaContext(context) + break; + case 'melee': + this.#prepareMeleeContext(context) + break; + case 'ranged': + this.#prepareRangedContext(context) + break; + case 'container': + this.#prepareContainerContext(context) + break; + case 'armor': + this.#prepareArmorContext(context) + break; + } + context.tab = context.tabs[partId] + return context + } + + #prepareMetaContext(context) { + const equipmentData = context.document.system; + context.system = equipmentData; + context.quantity = equipmentData.quantity; + context.description = equipmentData.description; + context.name = context.document.name; + context.img = context.document.img; context.categoryAndOptions = { options: { @@ -46,23 +125,22 @@ export class AusruestungSheet extends foundry.appv1.sheets.ItemSheet { Behälter: "Behälter", Rüstung: "Rüstung", }, - entries: context.system.category, + entries: equipmentData.category, targetField: "category" }; - context.isMeleeWeapon = context.system.category.includes("Nahkampfwaffe"); - context.isRangedWeapon = context.system.category.includes("Fernkampfwaffe"); - context.isContainer = context.system.category.includes("Behälter"); - context.isArmor = context.system.category.includes("Rüstung"); - context.price = context.system.price; - context.weight = context.system.weight; + } + + #prepareMeleeContext(context) { + const equipmentData = context.document.system; + context.system = equipmentData; context.meleeSkillsAndOptions = { options: { "": "", Dolche: "Dolche", Fechtwaffen: "Fechtwaffen", - Säbel: "Säbel", + "Säbel": "Säbel", Schwerter: "Schwerter", - Anderthalbhänder: "Anderthalbhänder", + "Anderthalbhänder": "Anderthalbhänder", "Zweihandschwerter/-säbel": "Zweihandschwerter/-säbel", "Infanteriewaffen": "Infanteriewaffen", "Speere": "Speere", @@ -72,9 +150,13 @@ export class AusruestungSheet extends foundry.appv1.sheets.ItemSheet { "Kettenwaffen": "Kettenwaffen", "Raufen": "Raufen" }, - entries: context.system.meleeSkills, + entries: equipmentData.meleeSkills, targetField: "meleeSkills" } + } + + #prepareRangedContext(context) { + const equipmentData = context.document.system; context.rangedSkillsAndOptions = { options: { "": "", @@ -84,24 +166,86 @@ export class AusruestungSheet extends foundry.appv1.sheets.ItemSheet { "Armbrust": "Armbrust", "Bogen": "Bogen", }, - entries: context.system.rangedSkills, + entries: equipmentData.rangedSkills, targetField: "rangedSkills" } - return context; } - activateListeners(html) { - super.activateListeners(html); + #prepareContainerContext(context) { - html.on('change', '.array-editor select', (evt) => { + } + + #prepareArmorContext(context) { + + } + + /** + * Adds Tabs based on the items nature + * + * @param {String} tabGroup + * @private + */ + _prepareTabs(tabGroup) { + + const currentTabs = super._prepareTabs(tabGroup); + + const category = this.document.system.category + /** + * + * @type {[{ApplicationTab}]} + */ + let tabs = currentTabs; + + if (category.includes("Nahkampfwaffe")) { + tabs.melee = { + id: 'melee', group: tabGroup, label: 'Nahkampfwaffe' + } + } + if (category.includes("Fernkampfwaffe")) { + tabs.ranged = { + id: 'ranged', group: tabGroup, label: 'Fernkampfwaffe' + } + } + if (category.includes("Behälter")) { + tabs.container = { + id: 'container', group: tabGroup, label: 'Behälter' + } + } + if (category.includes("Rüstung")) { + tabs.armor = { + id: 'armor', group: tabGroup, label: 'Rüstung' + } + } + + return tabs + } + + /** @override */ + async _prepareContext(options) { + + const context = await super._prepareContext(options); + context.price = context.document.system.price + context.weight = context.document.system.weight + + return context + } + + /** + * Actions performed after any render of the Application. + * Post-render steps are not awaited by the render process. + * @param {ApplicationRenderContext} context Prepared context data + * @param {RenderOptions} options Provided render options + * @protected + */ + _onRender(context, options) { + this.element.querySelector('.array-editor select').addEventListener('change', (evt) => { const addingValue = evt.currentTarget.value; const fieldToTarget = evt.currentTarget.dataset.targetField; - const newSkills = [...this.object.system[fieldToTarget], addingValue]; + const newSkills = [...this.document.system[fieldToTarget], addingValue]; - this.object.update({system: {[fieldToTarget]: newSkills}}); + this.document.update({system: {[fieldToTarget]: newSkills}}); evt.currentTarget.value = ""; }) - } } diff --git a/src/module/sheets/skillSheet.mjs b/src/module/sheets/skillSheet.mjs index cf1e2b4d..07654deb 100644 --- a/src/module/sheets/skillSheet.mjs +++ b/src/module/sheets/skillSheet.mjs @@ -39,7 +39,7 @@ export class SkillSheet extends HandlebarsApplicationMixin(DocumentSheetV2) { /** * Handle form submission - * @this {MyClass} + * @this {SkillSheet} * @param {SubmitEvent} event * @param {HTMLFormElement} form * @param {FormDataExtended} formData diff --git a/src/module/sheets/spellSheet.mjs b/src/module/sheets/spellSheet.mjs index 3713a24b..2e793d9e 100644 --- a/src/module/sheets/spellSheet.mjs +++ b/src/module/sheets/spellSheet.mjs @@ -1,49 +1,69 @@ -export class SpellSheet extends foundry.appv1.sheets.ItemSheet { - /**@override */ - static get defaultOptions() { - return foundry.utils.mergeObject(super.defaultOptions, { - classes: ['dsa41', 'sheet', 'item', 'spell'], - width: 520, - height: 480, +const {DocumentSheetV2, HandlebarsApplicationMixin} = foundry.applications.api + +export class SpellSheet extends HandlebarsApplicationMixin(DocumentSheetV2) { + + + /** @inheritDoc */ + static DEFAULT_OPTIONS = { + position: {width: 520, height: 480}, + classes: ['dsa41', 'sheet', 'item', 'spell'], + tag: 'form', + form: { + submitOnChange: true, + closeOnSubmit: false, + handler: SpellSheet.#onSubmitForm + } + } + + static TABS = { + sheet: { tabs: [ - { - navSelector: '.sheet-tabs', - contentSelector: '.sheet-body', - initial: 'meta', - }, + {id: 'meta', group: 'sheet', label: 'Meta'}, + {id: 'variants', group: 'sheet', label: 'Varianten'}, + {id: 'commonality', group: 'sheet', label: 'Verbreitung'}, ], - }); + initial: 'meta' + } + } + + /** @inheritDoc */ + static PARTS = { + form: { + template: `systems/DSA_4-1/templates/item/spell/main-sheet.hbs` + }, + meta: { + template: `systems/DSA_4-1/templates/item/spell/tab-meta.hbs` + }, + variants: { + template: `systems/DSA_4-1/templates/item/spell/tab-variants.hbs` + }, + commonality: { + template: `systems/DSA_4-1/templates/item/spell/tab-commonality.hbs` + } + } + + /** + * Handle form submission + * @this {SpellSheet} + * @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-spell-sheet.hbs`; - } + async _prepareContext(options) { + const context = await super._prepareContext(options); + const spellData = context.document; - /** @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 skillData = context.data; - - // Add the actor's data to context.data for easier access, as well as flags. - context.system = skillData.system; - context.flags = skillData.flags; + context.system = spellData.system; + context.flags = spellData.flags; return context; } - activateListeners(html) { - super.activateListeners(html); - - // Everything below here is only needed if the sheet is editable - if (!this.isEditable) return; - - } - } \ No newline at end of file diff --git a/src/style/_equipment-sheet.scss b/src/style/_equipment-sheet.scss index 80f041f0..859793e5 100644 --- a/src/style/_equipment-sheet.scss +++ b/src/style/_equipment-sheet.scss @@ -1,28 +1,15 @@ @use "./_colours"; @use "./_numbers"; -.app.window-app.dsa41.sheet.item.equipment { +.application.sheet.dsa41.item.equipment { - .sheet-body { + .tab.meta.active > div { - position: relative; - - .tab.active { - padding: 4px; - top: 0; - bottom: 0; - left: 0; - right: 0; - } - - .tab.meta.active { - - position: absolute; display: grid; grid-auto-columns: 1fr 1fr; grid-template-columns: 80px auto; - grid-template-rows: 24px 48px auto 48px; - gap: 0 0; + grid-template-rows: 32px 48px auto 48px; + gap: 8px; grid-template-areas: "category category" "quantity name" @@ -57,6 +44,7 @@ grid-area: bottomline; display: grid; grid-template-columns: repeat(2, 1fr); + gap: 8px; .named-value { position: relative; @@ -104,7 +92,7 @@ ul { list-style-type: none; - padding: 0; + padding: 0 32px 0 0; margin: 0; text-indent: 0; @@ -124,6 +112,7 @@ position: absolute; right: 0; top: 0; + width: 24px; } } @@ -153,7 +142,4 @@ } - - } - } diff --git a/src/templates/item/equipment/main-sheet.hbs b/src/templates/item/equipment/main-sheet.hbs new file mode 100644 index 00000000..21d661ee --- /dev/null +++ b/src/templates/item/equipment/main-sheet.hbs @@ -0,0 +1,14 @@ +
+ {{!-- Sheet Tab Navigation --}} + +
\ No newline at end of file diff --git a/src/templates/item/equipment/tab-armor.hbs b/src/templates/item/equipment/tab-armor.hbs new file mode 100644 index 00000000..7bfcd6de --- /dev/null +++ b/src/templates/item/equipment/tab-armor.hbs @@ -0,0 +1,37 @@ +
+
+ +
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+
\ No newline at end of file diff --git a/src/templates/item/equipment/tab-container.hbs b/src/templates/item/equipment/tab-container.hbs new file mode 100644 index 00000000..2a8282ef --- /dev/null +++ b/src/templates/item/equipment/tab-container.hbs @@ -0,0 +1,7 @@ +
+
+ Behälter Specs +
+
\ No newline at end of file diff --git a/src/templates/item/equipment/tab-melee.hbs b/src/templates/item/equipment/tab-melee.hbs new file mode 100644 index 00000000..fcd7a83d --- /dev/null +++ b/src/templates/item/equipment/tab-melee.hbs @@ -0,0 +1,43 @@ +
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+
\ No newline at end of file diff --git a/src/templates/item/equipment/tab-meta.hbs b/src/templates/item/equipment/tab-meta.hbs new file mode 100644 index 00000000..1409724a --- /dev/null +++ b/src/templates/item/equipment/tab-meta.hbs @@ -0,0 +1,40 @@ +
+
+
+ {{name}} + +
+
+ +
+
+
+ + + {{{system.description}}} + +
+
+ + +
+
+
\ No newline at end of file diff --git a/src/templates/item/equipment/tab-ranged.hbs b/src/templates/item/equipment/tab-ranged.hbs new file mode 100644 index 00000000..4eb4f520 --- /dev/null +++ b/src/templates/item/equipment/tab-ranged.hbs @@ -0,0 +1,32 @@ +
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+
\ No newline at end of file diff --git a/src/templates/item/item-equipment-sheet.hbs b/src/templates/item/item-equipment-sheet.hbs deleted file mode 100644 index c8334090..00000000 --- a/src/templates/item/item-equipment-sheet.hbs +++ /dev/null @@ -1,164 +0,0 @@ -
- - {{!-- Sheet Tab Navigation --}} - - - {{!-- Sheet Body --}} -
- -
-
- - -
-
- -
-
-
- - {{editor system.description target="system.description" button=true owner=owner editable=editable}} -
-
- - -
-
- - {{#if isMeleeWeapon}} -
-
- -
-
- -
-
- -
-
- -
-
- -
-
- -
-
- -
-
- {{/if}} - {{#if isRangedWeapon}} -
-
- -
-
- -
-
- -
-
- -
-
- -
-
- {{/if}} - {{#if isContainer}} -
- Behälter Specs -
- {{/if}} - {{#if isArmor}} -
-
- -
-
- -
-
- -
-
- -
-
- -
-
- -
-
- {{/if}} -
-
diff --git a/src/templates/item/spell/main-sheet.hbs b/src/templates/item/spell/main-sheet.hbs new file mode 100644 index 00000000..21d661ee --- /dev/null +++ b/src/templates/item/spell/main-sheet.hbs @@ -0,0 +1,14 @@ +
+ {{!-- Sheet Tab Navigation --}} + +
\ No newline at end of file diff --git a/src/templates/item/spell/tab-commonality.hbs b/src/templates/item/spell/tab-commonality.hbs new file mode 100644 index 00000000..351998d0 --- /dev/null +++ b/src/templates/item/spell/tab-commonality.hbs @@ -0,0 +1,21 @@ +
+ +
+ +
+
+ +
+
+ +
+ +
\ No newline at end of file diff --git a/src/templates/item/spell/tab-meta.hbs b/src/templates/item/spell/tab-meta.hbs new file mode 100644 index 00000000..7dc4079b --- /dev/null +++ b/src/templates/item/spell/tab-meta.hbs @@ -0,0 +1,48 @@ +
+ +
+ +
+
+ +
+
+
+ +
+
+ +
+
+ +
+
+ +
+ + +
\ No newline at end of file diff --git a/src/templates/item/spell/tab-variants.hbs b/src/templates/item/spell/tab-variants.hbs new file mode 100644 index 00000000..334d3786 --- /dev/null +++ b/src/templates/item/spell/tab-variants.hbs @@ -0,0 +1,26 @@ +
+ +
+ +
+
+ +
+
+ +
+
+ +
+ +
\ No newline at end of file