mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-12 03:31:07 +01:00
Bug/103 enrich htmlfield content before its used in applications (#369)
* FIX: Add enritch to HTMLField FIX: Remove no-HTMLField from Manifest FIX: Convert Scar's HTMLField to StringField FIX: Remove unused HTMLField * REMOVE unused hanldebars helpers * FEAT: add inventory-fieldset-items-V2 and inventory-item-V2 partials for Actors * FIX showLabels to hideTags * FEAT: add template to items sheet * FEAT: add effects tabs on ItemSheet * FEAT: add context menus for all inventory-items * FEAT: add resources to inventory-item template * FEAT: add enritch on inventory-item description FEAT: add extensible behavior on inventory-item-content FEAT: add fade effect on item-img to roll-itmg * FEAT: add eritch to NPC description FIX: missing htmlFieldss on manfiest FIX: add misisng localizations * FIX_ minor fixes * Little resource fix. Noone will notice ._. * FIX: remove default list styles FIX: .extended css reduce max-height, shorten animation duration to 0.5s, and set overflow to auto. FIX: set enriched=notes.enriche on notes.hbs FIX: set experience.value on sidebar.hbs FIX: move tooltip from item-img to img-portrait on inventory-item-V2.hbs REMOVE: unused files --------- Co-authored-by: Joaquin Pereyra <joaquinpereyra98@users.noreply.github.com> Co-authored-by: WBHarry <williambjrklund@gmail.com>
This commit is contained in:
parent
615df65415
commit
b8930b18a4
61 changed files with 1768 additions and 1434 deletions
|
|
@ -1,5 +1,10 @@
|
|||
const { HandlebarsApplicationMixin } = foundry.applications.api;
|
||||
import { tagifyElement } from '../../../helpers/utils.mjs';
|
||||
import { getDocFromElement, tagifyElement } from '../../../helpers/utils.mjs';
|
||||
import DHActionConfig from '../../sheets-configs/action-config.mjs';
|
||||
|
||||
/**
|
||||
* @typedef {import('@client/applications/_types.mjs').ApplicationClickAction} ApplicationClickAction
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {object} DragDropConfig
|
||||
|
|
@ -71,11 +76,32 @@ export default function DHApplicationMixin(Base) {
|
|||
static DEFAULT_OPTIONS = {
|
||||
classes: ['daggerheart', 'sheet', 'dh-style'],
|
||||
actions: {
|
||||
triggerContextMenu: DHSheetV2.#triggerContextMenu,
|
||||
createDoc: DHSheetV2.#createDoc,
|
||||
editDoc: DHSheetV2.#editDoc,
|
||||
deleteDoc: DHSheetV2.#deleteDoc
|
||||
deleteDoc: DHSheetV2.#deleteDoc,
|
||||
toChat: DHSheetV2.#toChat,
|
||||
useItem: DHSheetV2.#useItem,
|
||||
useAction: DHSheetV2.#useAction,
|
||||
toggleEffect: DHSheetV2.#toggleEffect,
|
||||
toggleExtended: DHSheetV2.#toggleExtended,
|
||||
},
|
||||
contextMenus: [],
|
||||
contextMenus: [{
|
||||
handler: DHSheetV2.#getEffectContextOptions,
|
||||
selector: '[data-item-uuid][data-type="effect"]',
|
||||
options: {
|
||||
parentClassHooks: false,
|
||||
fixed: true
|
||||
},
|
||||
},
|
||||
{
|
||||
handler: DHSheetV2.#getActionContextOptions,
|
||||
selector: '[data-item-uuid][data-type="action"]',
|
||||
options: {
|
||||
parentClassHooks: false,
|
||||
fixed: true
|
||||
}
|
||||
}],
|
||||
dragDrop: [],
|
||||
tagifyConfigs: []
|
||||
};
|
||||
|
|
@ -99,6 +125,27 @@ export default function DHApplicationMixin(Base) {
|
|||
this._createTagifyElements(this.options.tagifyConfigs);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/* Sync Parts */
|
||||
/* -------------------------------------------- */
|
||||
|
||||
/**@inheritdoc */
|
||||
_syncPartState(partId, newElement, priorElement, state) {
|
||||
super._syncPartState(partId, newElement, priorElement, state);
|
||||
for (const el of priorElement.querySelectorAll(".extensible.extended")) {
|
||||
const { actionId, itemUuid } = el.parentElement.dataset;
|
||||
const selector = `${actionId ? `[data-action-id="${actionId}"]` : `[data-item-uuid="${itemUuid}"]`} .extensible`;
|
||||
const newExtensible = newElement.querySelector(selector);
|
||||
|
||||
if (!newExtensible) continue;
|
||||
newExtensible.classList.add("extended");
|
||||
const descriptionElement = newExtensible.querySelector('.invetory-description');
|
||||
if (descriptionElement) {
|
||||
this.#prepareInventoryDescription(newExtensible, descriptionElement);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/* Tags */
|
||||
/* -------------------------------------------- */
|
||||
|
|
@ -162,14 +209,14 @@ export default function DHApplicationMixin(Base) {
|
|||
* @param {DragEvent} event
|
||||
* @protected
|
||||
*/
|
||||
_onDragStart(event) {}
|
||||
_onDragStart(event) { }
|
||||
|
||||
/**
|
||||
* Handle drop event.
|
||||
* @param {DragEvent} event
|
||||
* @protected
|
||||
*/
|
||||
_onDrop(event) {}
|
||||
_onDrop(event) { }
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/* Context Menu */
|
||||
|
|
@ -185,12 +232,140 @@ export default function DHApplicationMixin(Base) {
|
|||
/* -------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Get the set of ContextMenu options which should be used for journal entry pages in the sidebar.
|
||||
* @returns {import('@client/applications/ux/context-menu.mjs').ContextMenuEntry[]}
|
||||
* Get the set of ContextMenu options for DomainCards.
|
||||
* @returns {import('@client/applications/ux/context-menu.mjs').ContextMenuEntry[]} - The Array of context options passed to the ContextMenu instance
|
||||
* @this {CharacterSheet}
|
||||
* @protected
|
||||
*/
|
||||
_getEntryContextOptions() {
|
||||
return [];
|
||||
static #getEffectContextOptions() {
|
||||
/**@type {import('@client/applications/ux/context-menu.mjs').ContextMenuEntry[]} */
|
||||
const options = [
|
||||
{
|
||||
name: 'disableEffect',
|
||||
icon: 'fa-solid fa-lightbulb',
|
||||
condition: target => !getDocFromElement(target).disabled,
|
||||
callback: target => getDocFromElement(target).update({ disabled: true })
|
||||
},
|
||||
{
|
||||
name: 'enableEffect',
|
||||
icon: 'fa-regular fa-lightbulb',
|
||||
condition: target => getDocFromElement(target).disabled,
|
||||
callback: target => getDocFromElement(target).update({ disabled: false })
|
||||
},
|
||||
].map(option => ({
|
||||
...option,
|
||||
name: `DAGGERHEART.APPLICATIONS.ContextMenu.${option.name}`,
|
||||
icon: `<i class="${option.icon}"></i>`
|
||||
}));
|
||||
|
||||
return [...options, ...this._getContextMenuCommonOptions.call(this, { toChat: true })];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the set of ContextMenu options for Actions.
|
||||
* @returns {import('@client/applications/ux/context-menu.mjs').ContextMenuEntry[]} - The Array of context options passed to the ContextMenu instance
|
||||
* @this {DHSheetV2}
|
||||
* @protected
|
||||
*/
|
||||
static #getActionContextOptions() {
|
||||
/**@type {import('@client/applications/ux/context-menu.mjs').ContextMenuEntry[]} */
|
||||
const getAction = (target) => {
|
||||
const { actionId } = target.closest('[data-action-id]').dataset;
|
||||
const { actions, attack } = this.document.system;
|
||||
return attack?.id === actionId ? attack : actions?.find(a => a.id === actionId);
|
||||
};
|
||||
|
||||
const options = [
|
||||
{
|
||||
name: 'DAGGERHEART.APPLICATIONS.ContextMenu.useItem',
|
||||
icon: 'fa-solid fa-burst',
|
||||
condition: this.document instanceof foundry.documents.Actor ||
|
||||
(this.document instanceof foundry.documents.Item && this.document.parent),
|
||||
callback: (target, event) => getAction(target).use(event),
|
||||
},
|
||||
{
|
||||
name: 'DAGGERHEART.APPLICATIONS.ContextMenu.sendToChat',
|
||||
icon: 'fa-solid fa-message',
|
||||
callback: (target) => getAction(target).toChat(this.document.id),
|
||||
},
|
||||
{
|
||||
name: 'CONTROLS.CommonEdit',
|
||||
icon: 'fa-solid fa-pen-to-square',
|
||||
callback: (target) => new DHActionConfig(getAction(target)).render({ force: true })
|
||||
},
|
||||
{
|
||||
name: 'CONTROLS.CommonDelete',
|
||||
icon: 'fa-solid fa-trash',
|
||||
condition: (target) => {
|
||||
const { actionId } = target.closest('[data-action-id]').dataset;
|
||||
const { attack } = this.document.system;
|
||||
return attack?.id !== actionId
|
||||
},
|
||||
callback: async (target) => {
|
||||
const action = getAction(target)
|
||||
const confirmed = await foundry.applications.api.DialogV2.confirm({
|
||||
window: {
|
||||
title: game.i18n.format('DAGGERHEART.APPLICATIONS.DeleteConfirmation.title', {
|
||||
type: game.i18n.localize(`DAGGERHEART.GENERAL.Action.single`),
|
||||
name: action.name
|
||||
})
|
||||
},
|
||||
content: game.i18n.format('DAGGERHEART.APPLICATIONS.DeleteConfirmation.text', { name: action.name })
|
||||
});
|
||||
if (!confirmed) return;
|
||||
|
||||
return this.document.update({
|
||||
'system.actions': this.document.system.actions.filter((a) => a.id !== action.id)
|
||||
});
|
||||
}
|
||||
}
|
||||
].map(option => ({
|
||||
...option,
|
||||
icon: `<i class="${option.icon}"></i>`
|
||||
}));
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the set of ContextMenu options.
|
||||
* @returns {import('@client/applications/ux/context-menu.mjs').ContextMenuEntry[]} - The Array of context options passed to the ContextMenu instance
|
||||
*/
|
||||
_getContextMenuCommonOptions({ usable = false, toChat = false, deletable = true }) {
|
||||
const options = [
|
||||
{
|
||||
name: 'CONTROLS.CommonEdit',
|
||||
icon: 'fa-solid fa-pen-to-square',
|
||||
callback: target => getDocFromElement(target).sheet.render({ force: true })
|
||||
},
|
||||
];
|
||||
|
||||
if (usable) options.unshift({
|
||||
name: 'DAGGERHEART.APPLICATIONS.ContextMenu.useItem',
|
||||
icon: 'fa-solid fa-burst',
|
||||
callback: (target, event) => getDocFromElement(target).use(event),
|
||||
});
|
||||
|
||||
if (toChat) options.unshift({
|
||||
name: 'DAGGERHEART.APPLICATIONS.ContextMenu.sendToChat',
|
||||
icon: 'fa-solid fa-message',
|
||||
callback: (target) => getDocFromElement(target).toChat(this.document.id),
|
||||
});
|
||||
|
||||
if (deletable) options.push({
|
||||
name: 'CONTROLS.CommonDelete',
|
||||
icon: 'fa-solid fa-trash',
|
||||
callback: (target, event) => {
|
||||
const doc = getDocFromElement(target);
|
||||
if (event.shiftKey) return doc.delete();
|
||||
else return doc.deleteDialog();
|
||||
}
|
||||
})
|
||||
|
||||
return options.map(option => ({
|
||||
...option,
|
||||
icon: `<i class="${option.icon}"></i>`
|
||||
}))
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
|
@ -207,66 +382,229 @@ export default function DHApplicationMixin(Base) {
|
|||
return context;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/* Prepare Descriptions */
|
||||
/* -------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Prepares and enriches an inventory item or action description for display.
|
||||
* @param {HTMLElement} extensibleElement - The parent element containing the description.
|
||||
* @param {HTMLElement} descriptionElement - The element where the enriched description will be rendered.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async #prepareInventoryDescription(extensibleElement, descriptionElement) {
|
||||
const parent = extensibleElement.closest('[data-item-uuid], [data-action-id]');
|
||||
const { actionId, itemUuid } = parent?.dataset || {};
|
||||
if (!actionId && !itemUuid) return;
|
||||
|
||||
const doc = itemUuid
|
||||
? getDocFromElement(extensibleElement)
|
||||
: this.document.system.attack?.id === actionId
|
||||
? this.document.system.attack
|
||||
: this.document.system.actions?.find(a => a.id === actionId);
|
||||
if (!doc) return;
|
||||
|
||||
const description = doc.system?.description ?? doc.description;
|
||||
const isAction = !!actionId;
|
||||
descriptionElement.innerHTML = await foundry.applications.ux.TextEditor.implementation.enrichHTML(description, {
|
||||
relativeTo: isAction ? doc.parent : doc,
|
||||
rollData: doc.getRollData?.(),
|
||||
secrets: isAction ? doc.parent.isOwner : doc.isOwner
|
||||
});
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/* Application Clicks Actions */
|
||||
/* -------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Create an embedded document.
|
||||
* @param {PointerEvent} event - The originating click event
|
||||
* @param {HTMLElement} button - The capturing HTML element which defines the [data-action="removeAction"]
|
||||
* @type {ApplicationClickAction}
|
||||
*/
|
||||
static async #createDoc(event, button) {
|
||||
const { documentClass, type } = button.dataset;
|
||||
const parent = this.document;
|
||||
static async #createDoc(event, target) {
|
||||
const { documentClass, type, inVault, disabled } = target.dataset;
|
||||
const parentIsItem = this.document.documentName === 'Item';
|
||||
const parent = parentIsItem && documentClass === 'Item' ? null : this.document;
|
||||
|
||||
const cls = getDocumentClass(documentClass);
|
||||
return await cls.createDocuments(
|
||||
[
|
||||
{
|
||||
name: cls.defaultName({ type, parent }),
|
||||
type
|
||||
if (type === 'action') {
|
||||
const { type: actionType } = await foundry.applications.api.DialogV2.input({
|
||||
window: { title: 'Select Action Type' },
|
||||
content: await foundry.applications.handlebars.renderTemplate(
|
||||
'systems/daggerheart/templates/actionTypes/actionType.hbs',
|
||||
{ types: CONFIG.DH.ACTIONS.actionTypes }
|
||||
),
|
||||
ok: {
|
||||
label: game.i18n.format('DOCUMENT.Create', {
|
||||
type: game.i18n.localize('DAGGERHEART.GENERAL.Action.single')
|
||||
}),
|
||||
}
|
||||
],
|
||||
{ parent, renderSheet: !event.shiftKey }
|
||||
);
|
||||
}) ?? {};
|
||||
if (!actionType) return;
|
||||
const cls = game.system.api.models.actions.actionsTypes[actionType]
|
||||
const action = new cls({
|
||||
_id: foundry.utils.randomID(),
|
||||
type: actionType,
|
||||
name: game.i18n.localize(CONFIG.DH.ACTIONS.actionTypes[actionType].name),
|
||||
...cls.getSourceConfig(this.document)
|
||||
},
|
||||
{
|
||||
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({
|
||||
force: true
|
||||
});
|
||||
return action;
|
||||
|
||||
} else {
|
||||
const cls = getDocumentClass(documentClass);
|
||||
const data = {
|
||||
name: cls.defaultName({ type, parent }),
|
||||
type,
|
||||
}
|
||||
if (inVault) data["system.inVault"] = true;
|
||||
if (disabled) data.disabled = true;
|
||||
|
||||
const doc = await cls.create(data, { parent, renderSheet: !event.shiftKey });
|
||||
if (parentIsItem && type === 'feature') {
|
||||
await this.document.update({
|
||||
'system.features': this.document.system.toObject().features.concat(doc.uuid)
|
||||
});
|
||||
}
|
||||
return doc;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders an embedded document.
|
||||
* @param {PointerEvent} event - The originating click event
|
||||
* @param {HTMLElement} button - The capturing HTML element which defines the [data-action="removeAction"]
|
||||
* @type {ApplicationClickAction}
|
||||
*/
|
||||
static #editDoc(_event, button) {
|
||||
const { type, docId } = button.dataset;
|
||||
this.document.getEmbeddedDocument(type, docId, { strict: true }).sheet.render({ force: true });
|
||||
static #editDoc(_event, target) {
|
||||
const doc = getDocFromElement(target);
|
||||
if (doc) return doc.sheet.render({ force: true });
|
||||
|
||||
// TODO: REDO this
|
||||
const { actionId } = target.closest('[data-action-id]').dataset;
|
||||
const { actions, attack } = this.document.system;
|
||||
const action = attack?.id === actionId ? attack : actions?.find(a => a.id === actionId);
|
||||
new DHActionConfig(action).render({ force: true })
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an embedded document.
|
||||
* @param {PointerEvent} _event - The originating click event
|
||||
* @param {HTMLElement} button - The capturing HTML element which defines the [data-action="removeAction"]
|
||||
* @type {ApplicationClickAction}
|
||||
*/
|
||||
static async #deleteDoc(_event, button) {
|
||||
const { type, docId } = button.dataset;
|
||||
const document = this.document.getEmbeddedDocument(type, docId, { strict: true });
|
||||
const typeName = game.i18n.localize(
|
||||
document.type === 'base' ? `DOCUMENT.${type}` : `TYPES.${type}.${document.type}`
|
||||
);
|
||||
static async #deleteDoc(event, target) {
|
||||
const doc = getDocFromElement(target);
|
||||
|
||||
const confirmed = await foundry.applications.api.DialogV2.confirm({
|
||||
window: {
|
||||
title: game.i18n.format('DAGGERHEART.APPLICATIONS.DeleteConfirmation.title', {
|
||||
type: typeName,
|
||||
name: document.name
|
||||
})
|
||||
},
|
||||
content: game.i18n.format('DAGGERHEART.APPLICATIONS.DeleteConfirmation.text', { name: document.name })
|
||||
if (doc) {
|
||||
if (event.shiftKey) return doc.delete()
|
||||
else return await doc.deleteDialog()
|
||||
}
|
||||
|
||||
// TODO: REDO this
|
||||
const { actionId } = target.closest('[data-action-id]').dataset;
|
||||
const { actions, attack } = this.document.system;
|
||||
if (attack?.id === actionId) return;
|
||||
const action = actions.find(a => a.id === actionId);
|
||||
|
||||
if (!event.shiftKey) {
|
||||
const confirmed = await foundry.applications.api.DialogV2.confirm({
|
||||
window: {
|
||||
title: game.i18n.format('DAGGERHEART.APPLICATIONS.DeleteConfirmation.title', {
|
||||
type: game.i18n.localize(`DAGGERHEART.GENERAL.Action.single`),
|
||||
name: action.name
|
||||
})
|
||||
},
|
||||
content: game.i18n.format('DAGGERHEART.APPLICATIONS.DeleteConfirmation.text', { name: action.name })
|
||||
});
|
||||
if (!confirmed) return;
|
||||
}
|
||||
|
||||
return await this.document.update({
|
||||
'system.actions': actions.filter((a) => a.id !== action.id)
|
||||
});
|
||||
if (!confirmed) return;
|
||||
|
||||
await document.delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Send item to Chat
|
||||
* @type {ApplicationClickAction}
|
||||
*/
|
||||
static async #toChat(_event, target) {
|
||||
let doc = getDocFromElement(target);
|
||||
|
||||
// TODO: REDO this
|
||||
if (!doc) {
|
||||
const { actionId } = target.closest('[data-action-id]').dataset;
|
||||
const { actions, attack } = this.document.system;
|
||||
doc = attack?.id === actionId ? attack : actions?.find(a => a.id === actionId);
|
||||
}
|
||||
return doc.toChat(this.document.id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Use a item
|
||||
* @type {ApplicationClickAction}
|
||||
*/
|
||||
static async #useItem(event, target) {
|
||||
let doc = getDocFromElement(target);
|
||||
// TODO: REDO this
|
||||
if (!doc) {
|
||||
const { actionId } = target.closest('[data-action-id]').dataset;
|
||||
const { actions, attack } = this.document.system;
|
||||
doc = attack?.id === actionId ? attack : actions?.find(a => a.id === actionId);
|
||||
if(this.document instanceof foundry.documents.Item && !this.document.parent) return;
|
||||
}
|
||||
|
||||
await doc.use(event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Use a item
|
||||
* @type {ApplicationClickAction}
|
||||
*/
|
||||
static async #useAction(event, target) {
|
||||
const doc = getDocFromElement(target);
|
||||
const { actionId } = target.closest('[data-action-id]').dataset;
|
||||
const { actions, attack } = doc.system;
|
||||
const action = attack?.id === actionId ? attack : actions?.find(a => a.id === actionId);
|
||||
await action.use(event);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Toggle a ActiveEffect
|
||||
* @type {ApplicationClickAction}
|
||||
*/
|
||||
static async #toggleEffect(_, target) {
|
||||
const doc = getDocFromElement(target);
|
||||
await doc.update({ disabled: !doc.disabled });
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger the context menu.
|
||||
* @type {ApplicationClickAction}
|
||||
*/
|
||||
static #triggerContextMenu(event, _) {
|
||||
return CONFIG.ux.ContextMenu.triggerContextMenu(event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle the 'extended' class on the .extensible element inside inventory-item-content
|
||||
* @type {ApplicationClickAction}
|
||||
* @this {DHSheetV2}
|
||||
*/
|
||||
static async #toggleExtended(_, target) {
|
||||
const container = target.closest('.inventory-item');
|
||||
const extensible = container?.querySelector('.extensible');
|
||||
const t = extensible?.classList.toggle('extended');
|
||||
|
||||
const descriptionElement = extensible?.querySelector('.invetory-description');
|
||||
if (t && !!descriptionElement) this.#prepareInventoryDescription(extensible, descriptionElement);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return DHSheetV2;
|
||||
|
|
|
|||
|
|
@ -21,11 +21,24 @@ export default class DHBaseActorSheet extends DHApplicationMixin(ActorSheetV2) {
|
|||
submitOnChange: true
|
||||
},
|
||||
actions: {
|
||||
openSettings: DHBaseActorSheet.#openSettings
|
||||
openSettings: DHBaseActorSheet.#openSettings,
|
||||
sendExpToChat: DHBaseActorSheet.#sendExpToChat,
|
||||
},
|
||||
contextMenus: [
|
||||
{
|
||||
handler: DHBaseActorSheet.#getFeatureContextOptions,
|
||||
selector: '[data-item-uuid][data-type="feature"]',
|
||||
options: {
|
||||
parentClassHooks: false,
|
||||
fixed: true
|
||||
}
|
||||
}
|
||||
],
|
||||
dragDrop: [{ dragSelector: '.inventory-item[data-type="attack"]', dropSelector: null }]
|
||||
};
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
||||
/**@type {typeof DHBaseActorSettings}*/
|
||||
#settingSheet;
|
||||
|
||||
|
|
@ -35,6 +48,10 @@ export default class DHBaseActorSheet extends DHApplicationMixin(ActorSheetV2) {
|
|||
return (this.#settingSheet ??= SheetClass ? new SheetClass({ document: this.document }) : null);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/* Prepare Context */
|
||||
/* -------------------------------------------- */
|
||||
|
||||
/**@inheritdoc */
|
||||
async _prepareContext(_options) {
|
||||
const context = await super._prepareContext(_options);
|
||||
|
|
@ -42,6 +59,56 @@ export default class DHBaseActorSheet extends DHApplicationMixin(ActorSheetV2) {
|
|||
return context;
|
||||
}
|
||||
|
||||
|
||||
/**@inheritdoc */
|
||||
async _preparePartContext(partId, context, options) {
|
||||
context = await super._preparePartContext(partId, context, options);
|
||||
switch (partId) {
|
||||
case 'effects':
|
||||
await this._prepareEffectsContext(context, options);
|
||||
break;
|
||||
}
|
||||
return context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare render context for the Effect part.
|
||||
* @param {ApplicationRenderContext} context
|
||||
* @param {ApplicationRenderOptions} options
|
||||
* @returns {Promise<void>}
|
||||
* @protected
|
||||
*/
|
||||
async _prepareEffectsContext(context, _options) {
|
||||
context.effects = {
|
||||
actives: [],
|
||||
inactives: [],
|
||||
};
|
||||
|
||||
for (const effect of this.actor.allApplicableEffects()) {
|
||||
const list = effect.active ? context.effects.actives : context.effects.inactives;
|
||||
list.push(effect);
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/* Context Menu */
|
||||
/* -------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Get the set of ContextMenu options for Features.
|
||||
* @returns {import('@client/applications/ux/context-menu.mjs').ContextMenuEntry[]} - The Array of context options passed to the ContextMenu instance
|
||||
* @this {DHSheetV2}
|
||||
* @protected
|
||||
*/
|
||||
static #getFeatureContextOptions() {
|
||||
return this._getContextMenuCommonOptions.call(this, { usable: true, toChat: true });
|
||||
}
|
||||
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/* Application Clicks Actions */
|
||||
/* -------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Open the Actor Setting Sheet
|
||||
* @type {ApplicationClickAction}
|
||||
|
|
@ -50,6 +117,29 @@ export default class DHBaseActorSheet extends DHApplicationMixin(ActorSheetV2) {
|
|||
await this.settingSheet.render({ force: true });
|
||||
}
|
||||
|
||||
/**
|
||||
* Send Experience to Chat
|
||||
* @type {ApplicationClickAction}
|
||||
*/
|
||||
static async #sendExpToChat(_, button) {
|
||||
const experience = this.document.system.experiences[button.dataset.id];
|
||||
|
||||
const systemData = {
|
||||
name: game.i18n.localize('DAGGERHEART.GENERAL.Experience.single'),
|
||||
description: `${experience.name} ${experience.value.signedString()}`
|
||||
};
|
||||
|
||||
foundry.documents.ChatMessage.implementation.create({
|
||||
type: 'abilityUse',
|
||||
user: game.user.id,
|
||||
system: systemData,
|
||||
content: await foundry.applications.handlebars.renderTemplate(
|
||||
'systems/daggerheart/templates/ui/chat/ability-use.hbs',
|
||||
systemData
|
||||
)
|
||||
});
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/* Application Drag/Drop */
|
||||
/* -------------------------------------------- */
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import DHActionConfig from '../../sheets-configs/action-config.mjs';
|
||||
import { getDocFromElement } from '../../../helpers/utils.mjs';
|
||||
import DHApplicationMixin from './application-mixin.mjs';
|
||||
|
||||
const { ItemSheetV2 } = foundry.applications.sheets;
|
||||
|
|
@ -15,16 +15,14 @@ export default class DHBaseItemSheet extends DHApplicationMixin(ItemSheetV2) {
|
|||
static DEFAULT_OPTIONS = {
|
||||
classes: ['item'],
|
||||
position: { width: 600 },
|
||||
window: { resizable: true },
|
||||
form: {
|
||||
submitOnChange: true
|
||||
},
|
||||
actions: {
|
||||
addAction: DHBaseItemSheet.#addAction,
|
||||
editAction: DHBaseItemSheet.#editAction,
|
||||
removeAction: DHBaseItemSheet.#removeAction,
|
||||
addFeature: DHBaseItemSheet.#addFeature,
|
||||
editFeature: DHBaseItemSheet.#editFeature,
|
||||
removeFeature: DHBaseItemSheet.#removeFeature,
|
||||
deleteFeature: DHBaseItemSheet.#deleteFeature,
|
||||
addResource: DHBaseItemSheet.#addResource,
|
||||
removeResource: DHBaseItemSheet.#removeResource
|
||||
},
|
||||
|
|
@ -32,6 +30,16 @@ export default class DHBaseItemSheet extends DHApplicationMixin(ItemSheetV2) {
|
|||
{ dragSelector: null, dropSelector: '.tab.features .drop-section' },
|
||||
{ dragSelector: '.feature-item', dropSelector: null },
|
||||
{ dragSelector: '.action-item', dropSelector: null }
|
||||
],
|
||||
contextMenus: [
|
||||
{
|
||||
handler: DHBaseItemSheet.#getFeatureContextOptions,
|
||||
selector: '[data-item-uuid][data-type="feature"]',
|
||||
options: {
|
||||
parentClassHooks: false,
|
||||
fixed: true
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
|
|
@ -40,7 +48,7 @@ export default class DHBaseItemSheet extends DHApplicationMixin(ItemSheetV2) {
|
|||
/** @inheritdoc */
|
||||
static TABS = {
|
||||
primary: {
|
||||
tabs: [{ id: 'description' }, { id: 'settings' }, { id: 'actions' }],
|
||||
tabs: [{ id: 'description' }, { id: 'settings' }, { id: 'actions' }, { id: 'effects' }],
|
||||
initial: 'description',
|
||||
labelPrefix: 'DAGGERHEART.GENERAL.Tabs'
|
||||
}
|
||||
|
|
@ -51,8 +59,8 @@ export default class DHBaseItemSheet extends DHApplicationMixin(ItemSheetV2) {
|
|||
/* -------------------------------------------- */
|
||||
|
||||
/**@inheritdoc */
|
||||
async _preparePartContext(partId, context) {
|
||||
await super._preparePartContext(partId, context);
|
||||
async _preparePartContext(partId, context, options) {
|
||||
await super._preparePartContext(partId, context, options);
|
||||
const { TextEditor } = foundry.applications.ux;
|
||||
|
||||
switch (partId) {
|
||||
|
|
@ -64,77 +72,78 @@ export default class DHBaseItemSheet extends DHApplicationMixin(ItemSheetV2) {
|
|||
secrets: this.item.isOwner
|
||||
});
|
||||
break;
|
||||
case "effects":
|
||||
await this._prepareEffectsContext(context, options)
|
||||
break;
|
||||
case "features":
|
||||
context.isGM = game.user.isGM;
|
||||
break;
|
||||
}
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/* Application Clicks Actions */
|
||||
/* -------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Render a dialog prompting the user to select an action type.
|
||||
*
|
||||
* @returns {Promise<object>} An object containing the selected action type.
|
||||
* Prepare render context for the Effect part.
|
||||
* @param {ApplicationRenderContext} context
|
||||
* @param {ApplicationRenderOptions} options
|
||||
* @returns {Promise<void>}
|
||||
* @protected
|
||||
*/
|
||||
static async selectActionType() {
|
||||
const content = await foundry.applications.handlebars.renderTemplate(
|
||||
'systems/daggerheart/templates/actionTypes/actionType.hbs',
|
||||
{ types: CONFIG.DH.ACTIONS.actionTypes }
|
||||
),
|
||||
title = 'Select Action Type';
|
||||
async _prepareEffectsContext(context, _options) {
|
||||
context.effects = {
|
||||
actives: [],
|
||||
inactives: [],
|
||||
};
|
||||
|
||||
return foundry.applications.api.DialogV2.prompt({
|
||||
window: { title },
|
||||
content,
|
||||
ok: {
|
||||
label: title,
|
||||
callback: (event, button, dialog) => button.form.elements.type.value
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new action to the item, prompting the user for its type.
|
||||
* @type {ApplicationClickAction}
|
||||
*/
|
||||
static async #addAction(_event, _button) {
|
||||
const actionType = await DHBaseItemSheet.selectActionType();
|
||||
if (!actionType) return;
|
||||
try {
|
||||
const cls =
|
||||
game.system.api.models.actions.actionsTypes[actionType] ??
|
||||
game.system.api.models.actions.actionsTypes.attack,
|
||||
action = new cls(
|
||||
{
|
||||
_id: foundry.utils.randomID(),
|
||||
type: actionType,
|
||||
name: game.i18n.localize(CONFIG.DH.ACTIONS.actionTypes[actionType].name),
|
||||
...cls.getSourceConfig(this.document)
|
||||
},
|
||||
{
|
||||
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({
|
||||
force: true
|
||||
});
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
for (const effect of this.item.effects) {
|
||||
const list = effect.active ? context.effects.actives : context.effects.inactives;
|
||||
list.push(effect);
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/* Context Menu */
|
||||
/* -------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Edit an existing action on the item
|
||||
* @type {ApplicationClickAction}
|
||||
* Get the set of ContextMenu options for Features.
|
||||
* @returns {import('@client/applications/ux/context-menu.mjs').ContextMenuEntry[]} - The Array of context options passed to the ContextMenu instance
|
||||
* @this {DHSheetV2}
|
||||
* @protected
|
||||
*/
|
||||
static async #editAction(_event, button) {
|
||||
const action = this.document.system.actions[button.dataset.index];
|
||||
await new DHActionConfig(action).render({ force: true });
|
||||
static #getFeatureContextOptions() {
|
||||
const options = this._getContextMenuCommonOptions({ usable: true, toChat: true, deletable: false })
|
||||
options.push(
|
||||
{
|
||||
name: 'CONTROLS.CommonDelete',
|
||||
icon: '<i class="fa-solid fa-trash"></i>',
|
||||
callback: async (target) => {
|
||||
const feature = getDocFromElement(target);
|
||||
if (!feature) return;
|
||||
const confirmed = await foundry.applications.api.DialogV2.confirm({
|
||||
window: {
|
||||
title: game.i18n.format('DAGGERHEART.APPLICATIONS.DeleteConfirmation.title', {
|
||||
type: game.i18n.localize(`TYPES.Item.feature`),
|
||||
name: feature.name
|
||||
})
|
||||
},
|
||||
content: game.i18n.format('DAGGERHEART.APPLICATIONS.DeleteConfirmation.text', { name: feature.name })
|
||||
});
|
||||
if (!confirmed) return;
|
||||
await this.document.update({
|
||||
'system.features': this.document.system.toObject().features.filter(uuid => uuid !== feature.uuid)
|
||||
});
|
||||
},
|
||||
}
|
||||
)
|
||||
return options;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/* Application Clicks Actions */
|
||||
/* -------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Remove an action from the item.
|
||||
* @type {ApplicationClickAction}
|
||||
|
|
@ -144,16 +153,19 @@ export default class DHBaseItemSheet extends DHApplicationMixin(ItemSheetV2) {
|
|||
const actionIndex = button.closest('[data-index]').dataset.index;
|
||||
const action = this.document.system.actions[actionIndex];
|
||||
|
||||
const confirmed = await foundry.applications.api.DialogV2.confirm({
|
||||
window: {
|
||||
title: game.i18n.format('DAGGERHEART.APPLICATIONS.DeleteConfirmation.title', {
|
||||
type: game.i18n.localize(`DAGGERHEART.GENERAL.Action.single`),
|
||||
name: action.name
|
||||
})
|
||||
},
|
||||
content: game.i18n.format('DAGGERHEART.APPLICATIONS.DeleteConfirmation.text', { name: action.name })
|
||||
});
|
||||
if (!confirmed) return;
|
||||
if(!event.shiftKey) {
|
||||
const confirmed = await foundry.applications.api.DialogV2.confirm({
|
||||
window: {
|
||||
title: game.i18n.format('DAGGERHEART.APPLICATIONS.DeleteConfirmation.title', {
|
||||
type: game.i18n.localize(`DAGGERHEART.GENERAL.Action.single`),
|
||||
name: action.name
|
||||
})
|
||||
},
|
||||
content: game.i18n.format('DAGGERHEART.APPLICATIONS.DeleteConfirmation.text', { name: action.name })
|
||||
});
|
||||
if (!confirmed) return;
|
||||
}
|
||||
|
||||
|
||||
await this.document.update({
|
||||
'system.actions': this.document.system.actions.filter((_, index) => index !== Number.parseInt(actionIndex))
|
||||
|
|
@ -164,57 +176,31 @@ export default class DHBaseItemSheet extends DHApplicationMixin(ItemSheetV2) {
|
|||
* Add a new feature to the item, prompting the user for its type.
|
||||
* @type {ApplicationClickAction}
|
||||
*/
|
||||
static async #addFeature(_event, _button) {
|
||||
const feature = await game.items.documentClass.create({
|
||||
static async #addFeature(_, target) {
|
||||
const { type } = target.dataset;
|
||||
const cls = foundry.documents.Item.implementation;
|
||||
const feature = await cls.create({
|
||||
type: 'feature',
|
||||
name: game.i18n.format('DOCUMENT.New', { type: game.i18n.localize('TYPES.Item.feature') })
|
||||
name: cls.defaultName({ type: 'feature' }),
|
||||
"system.subType": CONFIG.DH.ITEM.featureSubTypes[type]
|
||||
});
|
||||
await this.document.update({
|
||||
'system.features': [...this.document.system.features.filter(x => x).map(x => x.uuid), feature.uuid]
|
||||
'system.features': [...this.document.system.features, feature].map(f => f.uuid)
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit an existing feature on the item
|
||||
* @type {ApplicationClickAction}
|
||||
*/
|
||||
static async #editFeature(_event, button) {
|
||||
const target = button.closest('.feature-item');
|
||||
const feature = this.document.system.features.find(x => x?.id === target.id);
|
||||
if (!feature) {
|
||||
ui.notifications.warn(game.i18n.localize('DAGGERHEART.UI.Notifications.featureIsMissing'));
|
||||
return;
|
||||
}
|
||||
|
||||
feature.sheet.render(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a feature from the item.
|
||||
* @type {ApplicationClickAction}
|
||||
*/
|
||||
static async #removeFeature(event, button) {
|
||||
event.stopPropagation();
|
||||
const target = button.closest('.feature-item');
|
||||
const feature = this.document.system.features.find(x => x && x.id === target.id);
|
||||
|
||||
if (feature) {
|
||||
const confirmed = await foundry.applications.api.DialogV2.confirm({
|
||||
window: {
|
||||
title: game.i18n.format('DAGGERHEART.APPLICATIONS.DeleteConfirmation.title', {
|
||||
type: game.i18n.localize(`TYPES.Item.feature`),
|
||||
name: feature.name
|
||||
})
|
||||
},
|
||||
content: game.i18n.format('DAGGERHEART.APPLICATIONS.DeleteConfirmation.text', { name: feature.name })
|
||||
});
|
||||
if (!confirmed) return;
|
||||
}
|
||||
|
||||
static async #deleteFeature(_, target) {
|
||||
const feature = getDocFromElement(target);
|
||||
if (!feature) return ui.notifications.warn(game.i18n.localize('DAGGERHEART.UI.Notifications.featureIsMissing'));
|
||||
await feature.update({ 'system.subType': null });
|
||||
await this.document.update({
|
||||
'system.features': this.document.system.features
|
||||
.filter(feature => feature && feature.id !== target.id)
|
||||
.map(x => x.uuid)
|
||||
.filter(uuid => uuid !== feature.uuid)
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue