FEAT: basic PseudoDocumentSheet

This commit is contained in:
Joaquin Pereyra 2025-06-11 15:02:58 -03:00
parent 27777dddba
commit ff4f6a22d3
8 changed files with 81 additions and 4 deletions

View file

@ -12,3 +12,5 @@ export { default as DhpWeapon } from './sheets/items/weapon.mjs';
export { default as DhpArmor } from './sheets/items/armor.mjs';
export { default as DhpChatMessage } from './chatMessage.mjs';
export { default as DhpEnvironment } from './sheets/environment.mjs';
export * as pseudoDocumentSheet from "./sheets/pseudo-documents/_module.mjs";

View file

@ -0,0 +1 @@
export {default as PseudoDocumentSheet }from "./pseudo-documents-sheet.mjs";

View file

@ -0,0 +1,67 @@
const { ApplicationV2, HandlebarsApplicationMixin } = foundry.applications.api;
export default class PseudoDocumentSheet extends HandlebarsApplicationMixin(ApplicationV2) {
constructor(options) {
super(options);
this.#pseudoDocument = options.document;
}
/**
* The UUID of the associated pseudo-document
* @type {string}
*/
get pseudoUuid() {
return this.pseudoDocument.uuid;
}
#pseudoDocument;
/**
* The pseudo-document instance this sheet represents
* @type {object}
*/
get pseudoDocument() {
return this.#pseudoDocument;
}
static DEFAULT_OPTIONS = {
tag: 'form',
classes: ['daggerheart', 'sheet'],
position: { width: 600 },
form: {
handler: PseudoDocumentSheet.#onSubmitForm,
submitOnChange: true,
closeOnSubmit: false
},
dragDrop: [{ dragSelector: null, dropSelector: null }],
};
static PARTS = {
header: { template: 'systems/daggerheart/templates/sheets/pseudo-documents/header.hbs' },
};
/** @inheritDoc */
async _prepareContext(options) {
const context = await super._prepareContext(options);
const document = this.pseudoDocument;
return Object.assign(context, {
document,
source: document._source,
fields: document.schema.fields,
editable: this.isEditable,
user: game.user,
rootId: this.id,
});
}
/**
* Form submission handler
* @param {SubmitEvent | Event} event - The originating form submission or input change event
* @param {HTMLFormElement} form - The form element that was submitted
* @param {foundry.applications.ux.FormDataExtended} formData - Processed data for the submitted form
*/
static async #onSubmitForm(event, form, formData) {
const submitData = foundry.utils.expandObject(formData.object);
await this.pseudoDocument.update(submitData, options);
}
}

View file

@ -1,12 +1,14 @@
import { pseudoDocuments } from "../data/_module.mjs";
import { pseudoDocumentSheet } from "../applications/_module.mjs";
//CONFIG.daggerheart.pseudoDocuments
export default {
sheetClass: pseudoDocumentSheet.PseudoDocumentSheet,
feature: {
label: "DAGGERHEART.Feature.Label",
documentClass: pseudoDocuments.feature.BaseFeatureData,
types: {
weapon:{
weapon: {
label: "DAGGERHEART.Feature.Weapon.Label",
documentClass: pseudoDocuments.feature.WeaponFeature,
}

View file

@ -20,7 +20,7 @@ export default class BasePseudoDocument extends foundry.abstract.DataModel {
name: '',
embedded: {},
defaultArtwork: foundry.documents.Item.DEFAULT_ICON,
sheetClass: null
sheetClass: CONFIG.daggerheart.pseudoDocuments.sheetClass,
};
}

View file

@ -16,7 +16,8 @@ export default function SheetManagementMixin(Base) {
get sheet() {
if (this._sheet) return this._sheet;
const cls = this.constructor.metadata.sheetClass ?? ApplicationV2;
if (!ApplicationV2.isPrototypeOf(cls)) {
if (!foundry.utils.isSubclass(cls, ApplicationV2)) {
return void ui.notifications.error(
'Daggerheart | Error on PseudoDocument | sheetClass must be ApplicationV2'
);
@ -24,6 +25,7 @@ export default function SheetManagementMixin(Base) {
const sheet = new cls({ document: this });
this._sheet = sheet;
return sheet;
}
/* -------------------------------------------- */

View file

@ -8,7 +8,7 @@ export default class BaseFeatureData extends PseudoDocument {
{
name: 'feature',
embedded: {},
sheetClass: null //TODO: define feature-sheet
//sheetClass: null //TODO: define feature-sheet
},
{ inplace: false }
);

View file

@ -0,0 +1,3 @@
<header>
{{log this}}
</header>