Migration vers datamodels

This commit is contained in:
2026-02-25 15:49:55 +01:00
parent 64eb40abfb
commit f1ab04bf32
95 changed files with 7418 additions and 593 deletions

View File

@@ -0,0 +1,6 @@
export { default as EcrymeBaseItemSheet } from "./base-item-sheet.js"
export { default as EcrymeEquipmentSheet } from "./equipment-sheet.js"
export { default as EcrymeWeaponSheet } from "./weapon-sheet.js"
export { default as EcrymeTraitSheet } from "./trait-sheet.js"
export { default as EcrymeSpecializationSheet } from "./specialization-sheet.js"
export { default as EcrymeManeuverSheet } from "./maneuver-sheet.js"

View File

@@ -0,0 +1,131 @@
const { HandlebarsApplicationMixin } = foundry.applications.api
/**
* Base item sheet for Ecryme using Application V2.
* Subclasses must define static PARTS including header, tabs, description, and optionally details.
*/
export default class EcrymeBaseItemSheet extends HandlebarsApplicationMixin(foundry.applications.sheets.ItemSheetV2) {
constructor(options = {}) {
super(options)
this.#dragDrop = this.#createDragDropHandlers()
}
#dragDrop
/** @override */
static DEFAULT_OPTIONS = {
classes: ["fvtt-ecryme", "item"],
position: {
width: 520,
height: "auto",
},
form: {
submitOnChange: true,
},
window: {
resizable: true,
},
dragDrop: [{ dragSelector: "[data-drag]", dropSelector: null }],
actions: {
editImage: EcrymeBaseItemSheet.#onEditImage,
},
}
/** Active tab group tracking */
tabGroups = {
primary: "description",
}
/**
* Build the tabs definition, adding a "details" tab only if the subclass has a "details" PART.
* @returns {Record<string, object>}
*/
_getTabs() {
const tabs = {
description: { id: "description", group: "primary", label: "ECRY.ui.description" },
}
if (this.constructor.PARTS?.details) {
tabs.details = { id: "details", group: "primary", label: "ECRY.ui.details" }
}
for (const tab of Object.values(tabs)) {
tab.active = this.tabGroups[tab.group] === tab.id
tab.cssClass = tab.active ? "active" : ""
}
return tabs
}
/** @override */
async _prepareContext() {
const context = {
fields: this.document.schema.fields,
systemFields: this.document.system.schema.fields,
item: this.document,
system: this.document.system,
source: this.document.toObject(),
config: game.system.ecryme.config,
isEditable: this.isEditable,
tabs: this._getTabs(),
}
return context
}
/** @override */
async _preparePartContext(partId, context) {
context = await super._preparePartContext(partId, context)
if (partId === "description") {
context.tab = context.tabs.description
context.enrichedDescription = await foundry.applications.ux.TextEditor.implementation.enrichHTML(
this.document.system.description, { async: true }
)
}
return context
}
/** @override */
_onRender(context, options) {
this.#dragDrop.forEach((d) => d.bind(this.element))
}
// #region Drag-and-Drop
#createDragDropHandlers() {
return this.options.dragDrop.map((d) => {
d.permissions = {
dragstart: this._canDragStart.bind(this),
drop: this._canDragDrop.bind(this),
}
d.callbacks = {
dragstart: this._onDragStart.bind(this),
dragover: this._onDragOver.bind(this),
drop: this._onDrop.bind(this),
}
return new foundry.applications.ux.DragDrop.implementation(d)
})
}
_canDragStart(selector) { return this.isEditable }
_canDragDrop(selector) { return this.isEditable && this.document.isOwner }
_onDragStart(event) {}
_onDragOver(event) {}
async _onDrop(event) {}
// #endregion
// #region Actions
static async #onEditImage(event, target) {
const attr = target.dataset.edit
const current = foundry.utils.getProperty(this.document, attr)
const { img } = this.document.constructor.getDefaultArtwork?.(this.document.toObject()) ?? {}
const fp = new FilePicker({
current,
type: "image",
redirectToRoot: img ? [img] : [],
callback: (path) => {
this.document.update({ [attr]: path })
},
top: this.position.top + 40,
left: this.position.left + 10,
})
return fp.browse()
}
// #endregion
}

View File

@@ -0,0 +1,24 @@
import EcrymeBaseItemSheet from "./base-item-sheet.js"
export default class EcrymeEquipmentSheet extends EcrymeBaseItemSheet {
/** @override */
static DEFAULT_OPTIONS = {
classes: ["equipment"],
position: { width: 520 },
}
/** @override */
static PARTS = {
header: { template: "systems/fvtt-ecryme/templates/items/partials/item-header.hbs" },
tabs: { template: "templates/generic/tab-navigation.hbs" },
description: { template: "systems/fvtt-ecryme/templates/items/partials/item-description.hbs" },
details: { template: "systems/fvtt-ecryme/templates/items/item-equipment-details.hbs" },
}
/** @override */
async _preparePartContext(partId, context) {
context = await super._preparePartContext(partId, context)
if (partId === "details") context.tab = context.tabs.details
return context
}
}

View File

@@ -0,0 +1,24 @@
import EcrymeBaseItemSheet from "./base-item-sheet.js"
export default class EcrymeManeuverSheet extends EcrymeBaseItemSheet {
/** @override */
static DEFAULT_OPTIONS = {
classes: ["maneuver"],
position: { width: 520 },
}
/** @override */
static PARTS = {
header: { template: "systems/fvtt-ecryme/templates/items/partials/item-header.hbs" },
tabs: { template: "templates/generic/tab-navigation.hbs" },
description: { template: "systems/fvtt-ecryme/templates/items/partials/item-description.hbs" },
details: { template: "systems/fvtt-ecryme/templates/items/item-maneuver-details.hbs" },
}
/** @override */
async _preparePartContext(partId, context) {
context = await super._preparePartContext(partId, context)
if (partId === "details") context.tab = context.tabs.details
return context
}
}

View File

@@ -0,0 +1,24 @@
import EcrymeBaseItemSheet from "./base-item-sheet.js"
export default class EcrymeSpecializationSheet extends EcrymeBaseItemSheet {
/** @override */
static DEFAULT_OPTIONS = {
classes: ["specialization"],
position: { width: 520 },
}
/** @override */
static PARTS = {
header: { template: "systems/fvtt-ecryme/templates/items/partials/item-header.hbs" },
tabs: { template: "templates/generic/tab-navigation.hbs" },
description: { template: "systems/fvtt-ecryme/templates/items/partials/item-description.hbs" },
details: { template: "systems/fvtt-ecryme/templates/items/item-specialization-details.hbs" },
}
/** @override */
async _preparePartContext(partId, context) {
context = await super._preparePartContext(partId, context)
if (partId === "details") context.tab = context.tabs.details
return context
}
}

View File

@@ -0,0 +1,24 @@
import EcrymeBaseItemSheet from "./base-item-sheet.js"
export default class EcrymeTraitSheet extends EcrymeBaseItemSheet {
/** @override */
static DEFAULT_OPTIONS = {
classes: ["trait"],
position: { width: 520 },
}
/** @override */
static PARTS = {
header: { template: "systems/fvtt-ecryme/templates/items/partials/item-header.hbs" },
tabs: { template: "templates/generic/tab-navigation.hbs" },
description: { template: "systems/fvtt-ecryme/templates/items/partials/item-description.hbs" },
details: { template: "systems/fvtt-ecryme/templates/items/item-trait-details.hbs" },
}
/** @override */
async _preparePartContext(partId, context) {
context = await super._preparePartContext(partId, context)
if (partId === "details") context.tab = context.tabs.details
return context
}
}

View File

@@ -0,0 +1,24 @@
import EcrymeBaseItemSheet from "./base-item-sheet.js"
export default class EcrymeWeaponSheet extends EcrymeBaseItemSheet {
/** @override */
static DEFAULT_OPTIONS = {
classes: ["weapon"],
position: { width: 540 },
}
/** @override */
static PARTS = {
header: { template: "systems/fvtt-ecryme/templates/items/partials/item-header.hbs" },
tabs: { template: "templates/generic/tab-navigation.hbs" },
description: { template: "systems/fvtt-ecryme/templates/items/partials/item-description.hbs" },
details: { template: "systems/fvtt-ecryme/templates/items/item-weapon-details.hbs" },
}
/** @override */
async _preparePartContext(partId, context) {
context = await super._preparePartContext(partId, context)
if (partId === "details") context.tab = context.tabs.details
return context
}
}