Feature/116-implementation-of-pseudo-documents (#125)

* FEAT: add baseDataModel logic

* FEAT: new PseudoDocumentsField
FIX: BasePseudoDocument 's getEmbeddedDocument

* FEAT: PseudoDocument class

* FEAT: add TypedPseudoDocument
REFACTOR: PreudoDocument
FIX: Typos Bug

* FIX: CONFIG types

* FEAT: basic PseudoDocumentSheet

* FIX: remove schema
ADD: input of example

---------

Co-authored-by: Joaquin Pereyra <joaquinpereyra98@users.noreply.github.com>
Co-authored-by: WBHarry <williambjrklund@gmail.com>
This commit is contained in:
joaquinpereyra98 2025-06-13 08:51:33 -03:00 committed by GitHub
parent 3a0a4673ad
commit f840dc2553
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
41 changed files with 844 additions and 190 deletions

View file

@ -1,12 +1,18 @@
export default class DhpItem extends Item {
prepareData() {
super.prepareData();
/** @inheritdoc */
getEmbeddedDocument(embeddedName, id, { invalid = false, strict = false } = {}) {
const systemEmbeds = this.system.constructor.metadata.embedded ?? {};
if (embeddedName in systemEmbeds) {
const path = `system.${systemEmbeds[embeddedName]}`;
return foundry.utils.getProperty(this, path).get(id) ?? null;
}
return super.getEmbeddedDocument(embeddedName, id, { invalid, strict });
}
/** @inheritDoc */
prepareEmbeddedDocuments() {
super.prepareEmbeddedDocuments();
for ( const action of this.system.actions ?? [] ) action.prepareData();
for (const action of this.system.actions ?? []) action.prepareData();
}
/**
@ -33,10 +39,6 @@ export default class DhpItem extends Item {
return ['weapon', 'armor', 'miscellaneous', 'consumable'].includes(this.type);
}
_onUpdate(data, options, userId) {
super._onUpdate(data, options, userId);
}
static async createDialog(data = {}, { parent = null, pack = null, ...options } = {}) {
const documentName = this.metadata.name;
const types = game.documentTypes[documentName].filter(t => t !== CONST.BASE_DOCUMENT_TYPE);
@ -99,8 +101,8 @@ export default class DhpItem extends Item {
async selectActionDialog() {
const content = await foundry.applications.handlebars.renderTemplate(
"systems/daggerheart/templates/views/actionSelect.hbs",
{actions: this.system.actions}
'systems/daggerheart/templates/views/actionSelect.hbs',
{ actions: this.system.actions }
),
title = 'Select Action',
type = 'div',
@ -108,26 +110,27 @@ export default class DhpItem extends Item {
return Dialog.prompt({
title,
// label: title,
content, type,
content,
type,
callback: html => {
const form = html[0].querySelector("form"),
const form = html[0].querySelector('form'),
fd = new foundry.applications.ux.FormDataExtended(form);
return this.system.actions.find(a => a._id === fd.object.actionId);
},
rejectClose: false
})
});
}
async use(event) {
const actions = this.system.actions
const actions = this.system.actions;
let response;
if(actions?.length) {
if (actions?.length) {
let action = actions[0];
if(actions.length > 1 && !event?.shiftKey) {
if (actions.length > 1 && !event?.shiftKey) {
// Actions Choice Dialog
action = await this.selectActionDialog();
}
if(action) response = action.use(event);
if (action) response = action.use(event);
// Check Target
// If action.roll => Roll Dialog
// Else If action.cost => Cost Dialog