Merge branch 'main' into bug/103-enrich-htmlfield-content-before-its-used-in-applications

This commit is contained in:
Joaquin Pereyra 2025-07-18 15:24:25 -03:00
commit f56c2482cb
551 changed files with 2831 additions and 14203 deletions

View file

@ -272,13 +272,15 @@ export default function DHApplicationMixin(Base) {
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);
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),
},
{
@ -297,7 +299,7 @@ export default function DHApplicationMixin(Base) {
condition: (target) => {
const { actionId } = target.closest('[data-action-id]').dataset;
const { attack } = this.document.system;
return attack.id !== actionId
return attack?.id !== actionId
},
callback: async (target) => {
const action = getAction(target)
@ -313,7 +315,7 @@ export default function DHApplicationMixin(Base) {
if (!confirmed) return;
return this.document.update({
'system.actions': this.document.system.actions.do.filter((a) => a.id !== action.id)
'system.actions': this.document.system.actions.filter((a) => a.id !== action.id)
});
}
}
@ -353,7 +355,11 @@ export default function DHApplicationMixin(Base) {
if (deletable) options.push({
name: 'CONTROLS.CommonDelete',
icon: 'fa-solid fa-trash',
callback: target => getDocFromElement(target).deleteDialog(),
callback: (target, event) => {
const doc = getDocFromElement(target);
if (event.shiftKey) return doc.delete();
else return doc.deleteDialog();
}
})
return options.map(option => ({
@ -402,7 +408,7 @@ export default function DHApplicationMixin(Base) {
const isAction = !!actionId;
descriptionElement.innerHTML = await foundry.applications.ux.TextEditor.implementation.enrichHTML(description, {
relativeTo: isAction ? doc.parent : doc,
rollData: doc.getRollData(),
rollData: doc.getRollData?.(),
secrets: isAction ? doc.parent.isOwner : doc.isOwner
});
}
@ -432,7 +438,7 @@ export default function DHApplicationMixin(Base) {
type: game.i18n.localize('DAGGERHEART.GENERAL.Action.single')
}),
}
});
}) ?? {};
if (!actionType) return;
const cls = game.system.api.models.actions.actionsTypes[actionType]
const action = new cls({
@ -482,7 +488,7 @@ export default function DHApplicationMixin(Base) {
// 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);
const action = attack?.id === actionId ? attack : actions?.find(a => a.id === actionId);
new DHActionConfig(action).render({ force: true })
}
@ -490,27 +496,32 @@ export default function DHApplicationMixin(Base) {
* Delete an embedded document.
* @type {ApplicationClickAction}
*/
static async #deleteDoc(_event, target) {
static async #deleteDoc(event, target) {
const doc = getDocFromElement(target);
// TODO: REDO this
if (doc) return await doc.deleteDialog()
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;
if (attack?.id === actionId) return;
const action = actions.find(a => a.id === actionId);
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;
}
return await this.document.update({
'system.actions': actions.filter((a) => a.id !== action.id)
@ -528,7 +539,7 @@ export default function DHApplicationMixin(Base) {
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);
doc = attack?.id === actionId ? attack : actions?.find(a => a.id === actionId);
}
return doc.toChat(this.document.id);
}
@ -544,6 +555,7 @@ export default function DHApplicationMixin(Base) {
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);

View file

@ -34,7 +34,7 @@ export default class DHBaseActorSheet extends DHApplicationMixin(ActorSheetV2) {
}
}
],
dragDrop: []
dragDrop: [{ dragSelector: '.inventory-item[data-type="attack"]', dropSelector: null }]
};
/* -------------------------------------------- */
@ -139,4 +139,27 @@ export default class DHBaseActorSheet extends DHApplicationMixin(ActorSheetV2) {
)
});
}
/* -------------------------------------------- */
/* Application Drag/Drop */
/* -------------------------------------------- */
/**
* On dragStart on the item.
* @param {DragEvent} event - The drag event
*/
async _onDragStart(event) {
const attackItem = event.currentTarget.closest('.inventory-item[data-type="attack"]');
if (attackItem) {
const attackData = {
type: 'Attack',
actorUuid: this.document.uuid,
img: this.document.system.attack.img,
fromInternal: true
};
event.dataTransfer.setData('text/plain', JSON.stringify(attackData));
event.dataTransfer.setDragImage(attackItem.querySelector('img'), 60, 0);
}
}
}

View file

@ -22,14 +22,14 @@ export default class DHBaseItemSheet extends DHApplicationMixin(ItemSheetV2) {
actions: {
removeAction: DHBaseItemSheet.#removeAction,
addFeature: DHBaseItemSheet.#addFeature,
editFeature: DHBaseItemSheet.#editFeature,
removeFeature: DHBaseItemSheet.#removeFeature,
deleteFeature: DHBaseItemSheet.#deleteFeature,
addResource: DHBaseItemSheet.#addResource,
removeResource: DHBaseItemSheet.#removeResource
},
dragDrop: [
{ dragSelector: null, dropSelector: '.tab.features .drop-section' },
{ dragSelector: '.feature-item', dropSelector: null }
{ dragSelector: '.feature-item', dropSelector: null },
{ dragSelector: '.action-item', dropSelector: null }
],
contextMenus: [
{
@ -153,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))
@ -173,58 +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) {
static async #addFeature(_, target) {
const { type } = target.dataset;
const cls = foundry.documents.Item.implementation;
const feature = await cls.create({
type: 'feature',
name: cls.defaultName({ type: 'feature' }),
"system.subType": CONFIG.DH.ITEM.featureSubTypes[type]
});
await this.document.update({
'system.features': [...this.document.system.features, feature]
'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)
});
}
@ -269,6 +245,23 @@ export default class DHBaseItemSheet extends DHApplicationMixin(ItemSheetV2) {
const featureData = { type: 'Item', data: { ...feature.toObject(), _id: null }, fromInternal: true };
event.dataTransfer.setData('text/plain', JSON.stringify(featureData));
event.dataTransfer.setDragImage(featureItem.querySelector('img'), 60, 0);
} else {
const actionItem = event.currentTarget.closest('.action-item');
if (actionItem) {
const action = this.document.system.actions[actionItem.dataset.index];
if (!action) {
ui.notifications.warn(game.i18n.localize('DAGGERHEART.UI.Notifications.actionIsMissing'));
return;
}
const actionData = {
type: 'Action',
data: { ...action.toObject(), id: action.id, itemUuid: this.document.uuid },
fromInternal: true
};
event.dataTransfer.setData('text/plain', JSON.stringify(actionData));
event.dataTransfer.setDragImage(actionItem.querySelector('img'), 60, 0);
}
}
}