mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-13 12:11:07 +01:00
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:
parent
3a0a4673ad
commit
f840dc2553
41 changed files with 844 additions and 190 deletions
|
|
@ -13,3 +13,5 @@ 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 { default as DhActiveEffectConfig } from './sheets/activeEffectConfig.mjs';
|
||||
|
||||
export * as pseudoDocumentSheet from './sheets/pseudo-documents/_module.mjs';
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ const { ApplicationV2 } = foundry.applications.api;
|
|||
export default class DHActionConfig extends DaggerheartSheet(ApplicationV2) {
|
||||
constructor(action) {
|
||||
super({});
|
||||
|
||||
|
||||
this.action = action;
|
||||
this.openSection = null;
|
||||
}
|
||||
|
|
@ -59,8 +59,8 @@ export default class DHActionConfig extends DaggerheartSheet(ApplicationV2) {
|
|||
context.openSection = this.openSection;
|
||||
context.tabs = this._getTabs();
|
||||
context.config = SYSTEM;
|
||||
if(!!this.action.effects) context.effects = this.action.effects.map(e => this.action.item.effects.get(e._id));
|
||||
if(this.action.damage?.hasOwnProperty('includeBase')) context.hasBaseDamage = !!this.action.parent.damage;
|
||||
if (!!this.action.effects) context.effects = this.action.effects.map(e => this.action.item.effects.get(e._id));
|
||||
if (this.action.damage?.hasOwnProperty('includeBase')) context.hasBaseDamage = !!this.action.parent.damage;
|
||||
context.getRealIndex = this.getRealIndex.bind(this);
|
||||
return context;
|
||||
}
|
||||
|
|
@ -86,10 +86,10 @@ export default class DHActionConfig extends DaggerheartSheet(ApplicationV2) {
|
|||
static async updateForm(event, _, formData) {
|
||||
const submitData = this._prepareSubmitData(event, formData),
|
||||
data = foundry.utils.expandObject(foundry.utils.mergeObject(this.action.toObject(), submitData)),
|
||||
newActions = this.action.parent.actions.map(x => x.toObject()); // Find better way
|
||||
newActions = this.action.parent.actions.map(x => x.toObject()); // Find better way
|
||||
if (!newActions.findSplice(x => x._id === data._id, data)) newActions.push(data);
|
||||
const updates = await this.action.parent.parent.update({ 'system.actions': newActions });
|
||||
if(!updates) return;
|
||||
if (!updates) return;
|
||||
this.action = updates.system.actions[this.action.index];
|
||||
this.render();
|
||||
}
|
||||
|
|
@ -97,7 +97,7 @@ export default class DHActionConfig extends DaggerheartSheet(ApplicationV2) {
|
|||
static addElement(event) {
|
||||
const data = this.action.toObject(),
|
||||
key = event.target.closest('.action-category-data').dataset.key;
|
||||
if ( !this.action[key] ) return;
|
||||
if (!this.action[key]) return;
|
||||
data[key].push({});
|
||||
this.constructor.updateForm.bind(this)(null, null, { object: foundry.utils.flattenObject(data) });
|
||||
}
|
||||
|
|
@ -109,16 +109,16 @@ export default class DHActionConfig extends DaggerheartSheet(ApplicationV2) {
|
|||
data[key].splice(index, 1);
|
||||
this.constructor.updateForm.bind(this)(null, null, { object: foundry.utils.flattenObject(data) });
|
||||
}
|
||||
|
||||
|
||||
static addDamage(event) {
|
||||
if ( !this.action.damage.parts ) return;
|
||||
if (!this.action.damage.parts) return;
|
||||
const data = this.action.toObject();
|
||||
data.damage.parts.push({});
|
||||
this.constructor.updateForm.bind(this)(null, null, { object: foundry.utils.flattenObject(data) });
|
||||
}
|
||||
|
||||
static removeDamage(event) {
|
||||
if ( !this.action.damage.parts ) return;
|
||||
if (!this.action.damage.parts) return;
|
||||
const data = this.action.toObject(),
|
||||
index = event.target.dataset.index;
|
||||
data.damage.parts.splice(index, 1);
|
||||
|
|
@ -126,15 +126,15 @@ export default class DHActionConfig extends DaggerheartSheet(ApplicationV2) {
|
|||
}
|
||||
|
||||
static async addEffect(event) {
|
||||
if ( !this.action.effects ) return;
|
||||
if (!this.action.effects) return;
|
||||
const effectData = this._addEffectData.bind(this)(),
|
||||
[created] = await this.action.item.createEmbeddedDocuments("ActiveEffect", [effectData], { render: false }),
|
||||
[created] = await this.action.item.createEmbeddedDocuments('ActiveEffect', [effectData], { render: false }),
|
||||
data = this.action.toObject();
|
||||
data.effects.push( { '_id': created._id } )
|
||||
data.effects.push({ _id: created._id });
|
||||
this.constructor.updateForm.bind(this)(null, null, { object: foundry.utils.flattenObject(data) });
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* The data for a newly created applied effect.
|
||||
* @returns {object}
|
||||
* @protected
|
||||
|
|
@ -149,14 +149,12 @@ export default class DHActionConfig extends DaggerheartSheet(ApplicationV2) {
|
|||
}
|
||||
|
||||
static removeEffect(event) {
|
||||
if ( !this.action.effects ) return;
|
||||
if (!this.action.effects) return;
|
||||
const index = event.target.dataset.index,
|
||||
effectId = this.action.effects[index]._id;
|
||||
this.constructor.removeElement.bind(this)(event);
|
||||
this.action.item.deleteEmbeddedDocuments("ActiveEffect", [effectId]);
|
||||
this.action.item.deleteEmbeddedDocuments('ActiveEffect', [effectId]);
|
||||
}
|
||||
|
||||
static editEffect(event) {
|
||||
|
||||
}
|
||||
static editEffect(event) {}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ export default function DHItemMixin(Base) {
|
|||
editAction: this.editAction,
|
||||
removeAction: this.removeAction
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static TABS = {
|
||||
description: {
|
||||
|
|
@ -49,7 +49,7 @@ export default function DHItemMixin(Base) {
|
|||
icon: null,
|
||||
label: 'DAGGERHEART.Sheets.Feature.Tabs.Settings'
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
async _prepareContext(_options) {
|
||||
const context = await super._prepareContext(_options);
|
||||
|
|
@ -67,8 +67,8 @@ export default function DHItemMixin(Base) {
|
|||
|
||||
static async selectActionType() {
|
||||
const content = await foundry.applications.handlebars.renderTemplate(
|
||||
"systems/daggerheart/templates/views/actionType.hbs",
|
||||
{types: SYSTEM.ACTIONS.actionTypes}
|
||||
'systems/daggerheart/templates/views/actionType.hbs',
|
||||
{ types: SYSTEM.ACTIONS.actionTypes }
|
||||
),
|
||||
title = 'Select Action Type',
|
||||
type = 'form',
|
||||
|
|
@ -76,21 +76,22 @@ export default function DHItemMixin(Base) {
|
|||
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);
|
||||
foundry.utils.mergeObject(data, fd.object, { inplace: true });
|
||||
// if (!data.name?.trim()) data.name = game.i18n.localize(SYSTEM.ACTIONS.actionTypes[data.type].name);
|
||||
return data;
|
||||
},
|
||||
rejectClose: false
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
static async addAction() {
|
||||
const actionType = await DHItemSheetV2.selectActionType(),
|
||||
actionIndexes = this.document.system.actions.map(x => x._id.split('-')[2]).sort((a, b) => a - b)
|
||||
actionIndexes = this.document.system.actions.map(x => x._id.split('-')[2]).sort((a, b) => a - b);
|
||||
try {
|
||||
const cls = actionsTypes[actionType?.type] ?? actionsTypes.attack,
|
||||
action = new cls(
|
||||
|
|
@ -105,10 +106,12 @@ export default function DHItemMixin(Base) {
|
|||
parent: this.document
|
||||
}
|
||||
);
|
||||
await this.document.update({ 'system.actions': [...this.document.system.actions, action] });
|
||||
await new DHActionConfig(this.document.system.actions[this.document.system.actions.length - 1]).render(true);
|
||||
await this.document.update({ 'system.actions': [...this.document.system.actions, action] });
|
||||
await new DHActionConfig(this.document.system.actions[this.document.system.actions.length - 1]).render(
|
||||
true
|
||||
);
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
console.log(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -125,5 +128,5 @@ export default function DHItemMixin(Base) {
|
|||
)
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import DHItemSheetV2 from '../item.mjs'
|
||||
import DHItemSheetV2 from '../item.mjs';
|
||||
|
||||
const { ItemSheetV2 } = foundry.applications.sheets;
|
||||
export default class ConsumableSheet extends DHItemSheetV2(ItemSheetV2) {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import DHItemSheetV2 from '../item.mjs'
|
||||
import DHItemSheetV2 from '../item.mjs';
|
||||
|
||||
const { ItemSheetV2 } = foundry.applications.sheets;
|
||||
export default class DomainCardSheet extends DHItemSheetV2(ItemSheetV2) {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import DHItemSheetV2 from '../item.mjs'
|
||||
import DHItemSheetV2 from '../item.mjs';
|
||||
|
||||
const { ItemSheetV2 } = foundry.applications.sheets;
|
||||
export default class FeatureSheet extends DHItemSheetV2(ItemSheetV2) {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import DHItemSheetV2 from '../item.mjs'
|
||||
import DHItemSheetV2 from '../item.mjs';
|
||||
|
||||
const { ItemSheetV2 } = foundry.applications.sheets;
|
||||
export default class MiscellaneousSheet extends DHItemSheetV2(ItemSheetV2) {
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
import DHItemSheetV2 from '../item.mjs'
|
||||
import DHItemSheetV2 from '../item.mjs';
|
||||
|
||||
const { ItemSheetV2 } = foundry.applications.sheets;
|
||||
export default class WeaponSheet extends DHItemSheetV2(ItemSheetV2) {
|
||||
static DEFAULT_OPTIONS = {
|
||||
classes: ['weapon']
|
||||
}
|
||||
};
|
||||
|
||||
static PARTS = {
|
||||
header: { template: 'systems/daggerheart/templates/sheets/items/weapon/header.hbs' },
|
||||
|
|
@ -18,5 +18,5 @@ export default class WeaponSheet extends DHItemSheetV2(ItemSheetV2) {
|
|||
template: 'systems/daggerheart/templates/sheets/items/weapon/settings.hbs',
|
||||
scrollable: ['.settings']
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
1
module/applications/sheets/pseudo-documents/_module.mjs
Normal file
1
module/applications/sheets/pseudo-documents/_module.mjs
Normal file
|
|
@ -0,0 +1 @@
|
|||
export {default as PseudoDocumentSheet }from "./pseudo-documents-sheet.mjs";
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
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,
|
||||
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);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue