migrates advantages to DocumentV2

feature/applicationv2
macniel 2025-10-15 16:24:51 +02:00
parent 232347aae5
commit 3869982927
5 changed files with 114 additions and 58 deletions

View File

@ -6,7 +6,7 @@ import {SpellDataModel} from "./module/data/spell.mjs";
import {VornachteileDataModel} from "./module/data/vornachteile.mjs"; import {VornachteileDataModel} from "./module/data/vornachteile.mjs";
import {Character} from "./module/documents/character.mjs"; import {Character} from "./module/documents/character.mjs";
import {CharacterSheet} from "./module/sheets/characterSheet.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 {GroupDataModel} from "./module/data/group.mjs";
import {GroupSheet} from "./module/sheets/groupSheet.mjs"; import {GroupSheet} from "./module/sheets/groupSheet.mjs";
import {EquipmentDataModel} from "./module/data/equipment.mjs"; import {EquipmentDataModel} from "./module/data/equipment.mjs";
@ -106,7 +106,7 @@ Hooks.once("init", () => {
makeDefault: true, makeDefault: true,
label: 'DSA41.SpellLabels.Item', label: 'DSA41.SpellLabels.Item',
}); });
foundry.documents.collections.Items.registerSheet('dsa41.advantage', VornachteilSheet, { foundry.documents.collections.Items.registerSheet('dsa41.advantage', AdvantageSheet, {
types: ["Advantage"], types: ["Advantage"],
makeDefault: true, makeDefault: true,
label: 'DSA41.VornachteilLabels.Item' label: 'DSA41.VornachteilLabels.Item'

View File

@ -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;
}
}

View File

@ -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) {
}
}
}

View File

@ -0,0 +1,14 @@
<div>
{{!-- Sheet Tab Navigation --}}
<nav class="sheet-tabs tabs{{#if verticalTabs}} vertical{{/if}}"
aria-roledescription="{{localize "SHEETS.FormNavLabel"}}">
{{#each tabs as |tab|}}
<a data-action="tab" data-group="{{tab.group}}" data-tab="{{tab.id}}"
{{#if tab.cssClass}}class="{{tab.cssClass}}"{{/if}}
{{#if tab.tooltip}}data-tooltip="{{tab.tooltip}}"{{/if}}>
{{#if tab.icon}}<i class="{{tab.icon}}" inert></i>{{/if}}
{{#if tab.label}}<span>{{localize tab.label}}</span>{{/if}}
</a>
{{/each}}
</nav>
</div>

View File

@ -0,0 +1,33 @@
<section class="tab {{tabs.advantage.id}} {{tabs.advantage.cssClass}}"
data-tab="{{tabs.advantage.id}}"
data-group="{{tabs.advantage.group}}">
<div>
<label>Name</label>
<input name="system.name" value="{{system.name}}"/>
</div>
{{#if hasModality}}
<div>
<label for="{{this._id}}.choice">Auswahl</label>
{{#if hasChoices}}
<select id="{{this._id}}.choice" name="system.gruppe">
{{selectOptions choices selected=system.auswahl inverted=true}}
</select>
{{else}}
<input id="{{this._id}}.choice" name="system.value" value="{{system.value}}"/>
{{/if}}
</div>
{{/if}}
<div class="body">
<label>Beschreibung</label>
<prose-mirror
name=" system.description"
button="false"
editable="{{editable}}"
toggled="true"
value="{{ system.description}}">
{{{ system.description}}}
</prose-mirror>
</div>
</section>