Fixed so that features are deleted from system.features if if the feature itself is deleted

This commit is contained in:
WBHarry 2025-07-20 18:18:58 +02:00
parent 867947c2c5
commit 28efef7951
10 changed files with 241 additions and 179 deletions

View file

@ -84,24 +84,26 @@ export default function DHApplicationMixin(Base) {
useItem: DHSheetV2.#useItem, useItem: DHSheetV2.#useItem,
useAction: DHSheetV2.#useAction, useAction: DHSheetV2.#useAction,
toggleEffect: DHSheetV2.#toggleEffect, toggleEffect: DHSheetV2.#toggleEffect,
toggleExtended: DHSheetV2.#toggleExtended, toggleExtended: DHSheetV2.#toggleExtended
}, },
contextMenus: [{ contextMenus: [
handler: DHSheetV2.#getEffectContextOptions, {
selector: '[data-item-uuid][data-type="effect"]', handler: DHSheetV2.#getEffectContextOptions,
options: { selector: '[data-item-uuid][data-type="effect"]',
parentClassHooks: false, options: {
fixed: true parentClassHooks: false,
fixed: true
}
}, },
}, {
{ handler: DHSheetV2.#getActionContextOptions,
handler: DHSheetV2.#getActionContextOptions, selector: '[data-item-uuid][data-type="action"]',
selector: '[data-item-uuid][data-type="action"]', options: {
options: { parentClassHooks: false,
parentClassHooks: false, fixed: true
fixed: true }
} }
}], ],
dragDrop: [], dragDrop: [],
tagifyConfigs: [] tagifyConfigs: []
}; };
@ -132,13 +134,13 @@ export default function DHApplicationMixin(Base) {
/**@inheritdoc */ /**@inheritdoc */
_syncPartState(partId, newElement, priorElement, state) { _syncPartState(partId, newElement, priorElement, state) {
super._syncPartState(partId, newElement, priorElement, state); super._syncPartState(partId, newElement, priorElement, state);
for (const el of priorElement.querySelectorAll(".extensible.extended")) { for (const el of priorElement.querySelectorAll('.extensible.extended')) {
const { actionId, itemUuid } = el.parentElement.dataset; const { actionId, itemUuid } = el.parentElement.dataset;
const selector = `${actionId ? `[data-action-id="${actionId}"]` : `[data-item-uuid="${itemUuid}"]`} .extensible`; const selector = `${actionId ? `[data-action-id="${actionId}"]` : `[data-item-uuid="${itemUuid}"]`} .extensible`;
const newExtensible = newElement.querySelector(selector); const newExtensible = newElement.querySelector(selector);
if (!newExtensible) continue; if (!newExtensible) continue;
newExtensible.classList.add("extended"); newExtensible.classList.add('extended');
const descriptionElement = newExtensible.querySelector('.invetory-description'); const descriptionElement = newExtensible.querySelector('.invetory-description');
if (descriptionElement) { if (descriptionElement) {
this.#prepareInventoryDescription(newExtensible, descriptionElement); this.#prepareInventoryDescription(newExtensible, descriptionElement);
@ -209,14 +211,14 @@ export default function DHApplicationMixin(Base) {
* @param {DragEvent} event * @param {DragEvent} event
* @protected * @protected
*/ */
_onDragStart(event) { } _onDragStart(event) {}
/** /**
* Handle drop event. * Handle drop event.
* @param {DragEvent} event * @param {DragEvent} event
* @protected * @protected
*/ */
_onDrop(event) { } _onDrop(event) {}
/* -------------------------------------------- */ /* -------------------------------------------- */
/* Context Menu */ /* Context Menu */
@ -251,7 +253,7 @@ export default function DHApplicationMixin(Base) {
icon: 'fa-regular fa-lightbulb', icon: 'fa-regular fa-lightbulb',
condition: target => getDocFromElement(target).disabled, condition: target => getDocFromElement(target).disabled,
callback: target => getDocFromElement(target).update({ disabled: false }) callback: target => getDocFromElement(target).update({ disabled: false })
}, }
].map(option => ({ ].map(option => ({
...option, ...option,
name: `DAGGERHEART.APPLICATIONS.ContextMenu.${option.name}`, name: `DAGGERHEART.APPLICATIONS.ContextMenu.${option.name}`,
@ -269,7 +271,7 @@ export default function DHApplicationMixin(Base) {
*/ */
static #getActionContextOptions() { static #getActionContextOptions() {
/**@type {import('@client/applications/ux/context-menu.mjs').ContextMenuEntry[]} */ /**@type {import('@client/applications/ux/context-menu.mjs').ContextMenuEntry[]} */
const getAction = (target) => { const getAction = target => {
const { actionId } = target.closest('[data-action-id]').dataset; const { actionId } = target.closest('[data-action-id]').dataset;
const { actions, attack } = this.document.system; 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);
@ -279,30 +281,31 @@ export default function DHApplicationMixin(Base) {
{ {
name: 'DAGGERHEART.APPLICATIONS.ContextMenu.useItem', name: 'DAGGERHEART.APPLICATIONS.ContextMenu.useItem',
icon: 'fa-solid fa-burst', icon: 'fa-solid fa-burst',
condition: this.document instanceof foundry.documents.Actor || condition:
this.document instanceof foundry.documents.Actor ||
(this.document instanceof foundry.documents.Item && this.document.parent), (this.document instanceof foundry.documents.Item && this.document.parent),
callback: (target, event) => getAction(target).use(event), callback: (target, event) => getAction(target).use(event)
}, },
{ {
name: 'DAGGERHEART.APPLICATIONS.ContextMenu.sendToChat', name: 'DAGGERHEART.APPLICATIONS.ContextMenu.sendToChat',
icon: 'fa-solid fa-message', icon: 'fa-solid fa-message',
callback: (target) => getAction(target).toChat(this.document.id), callback: target => getAction(target).toChat(this.document.id)
}, },
{ {
name: 'CONTROLS.CommonEdit', name: 'CONTROLS.CommonEdit',
icon: 'fa-solid fa-pen-to-square', icon: 'fa-solid fa-pen-to-square',
callback: (target) => new DHActionConfig(getAction(target)).render({ force: true }) callback: target => new DHActionConfig(getAction(target)).render({ force: true })
}, },
{ {
name: 'CONTROLS.CommonDelete', name: 'CONTROLS.CommonDelete',
icon: 'fa-solid fa-trash', icon: 'fa-solid fa-trash',
condition: (target) => { condition: target => {
const { actionId } = target.closest('[data-action-id]').dataset; const { actionId } = target.closest('[data-action-id]').dataset;
const { attack } = this.document.system; const { attack } = this.document.system;
return attack?.id !== actionId return attack?.id !== actionId;
}, },
callback: async (target) => { callback: async target => {
const action = getAction(target) const action = getAction(target);
const confirmed = await foundry.applications.api.DialogV2.confirm({ const confirmed = await foundry.applications.api.DialogV2.confirm({
window: { window: {
title: game.i18n.format('DAGGERHEART.APPLICATIONS.DeleteConfirmation.title', { title: game.i18n.format('DAGGERHEART.APPLICATIONS.DeleteConfirmation.title', {
@ -310,12 +313,14 @@ export default function DHApplicationMixin(Base) {
name: action.name name: action.name
}) })
}, },
content: game.i18n.format('DAGGERHEART.APPLICATIONS.DeleteConfirmation.text', { name: action.name }) content: game.i18n.format('DAGGERHEART.APPLICATIONS.DeleteConfirmation.text', {
name: action.name
})
}); });
if (!confirmed) return; if (!confirmed) return;
return this.document.update({ return this.document.update({
'system.actions': this.document.system.actions.filter((a) => a.id !== action.id) 'system.actions': this.document.system.actions.filter(a => a.id !== action.id)
}); });
} }
} }
@ -337,35 +342,38 @@ export default function DHApplicationMixin(Base) {
name: 'CONTROLS.CommonEdit', name: 'CONTROLS.CommonEdit',
icon: 'fa-solid fa-pen-to-square', icon: 'fa-solid fa-pen-to-square',
callback: target => getDocFromElement(target).sheet.render({ force: true }) callback: target => getDocFromElement(target).sheet.render({ force: true })
}, }
]; ];
if (usable) options.unshift({ if (usable)
name: 'DAGGERHEART.APPLICATIONS.ContextMenu.useItem', options.unshift({
icon: 'fa-solid fa-burst', name: 'DAGGERHEART.APPLICATIONS.ContextMenu.useItem',
callback: (target, event) => getDocFromElement(target).use(event), icon: 'fa-solid fa-burst',
}); callback: (target, event) => getDocFromElement(target).use(event)
});
if (toChat) options.unshift({ if (toChat)
name: 'DAGGERHEART.APPLICATIONS.ContextMenu.sendToChat', options.unshift({
icon: 'fa-solid fa-message', name: 'DAGGERHEART.APPLICATIONS.ContextMenu.sendToChat',
callback: (target) => getDocFromElement(target).toChat(this.document.id), icon: 'fa-solid fa-message',
}); callback: target => getDocFromElement(target).toChat(this.document.id)
});
if (deletable) options.push({ if (deletable)
name: 'CONTROLS.CommonDelete', options.push({
icon: 'fa-solid fa-trash', name: 'CONTROLS.CommonDelete',
callback: (target, event) => { icon: 'fa-solid fa-trash',
const doc = getDocFromElement(target); callback: (target, event) => {
if (event.shiftKey) return doc.delete(); const doc = getDocFromElement(target);
else return doc.deleteDialog(); if (event.shiftKey) return doc.delete();
} else return doc.deleteDialog();
}) }
});
return options.map(option => ({ return options.map(option => ({
...option, ...option,
icon: `<i class="${option.icon}"></i>` icon: `<i class="${option.icon}"></i>`
})) }));
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
@ -400,17 +408,20 @@ export default function DHApplicationMixin(Base) {
const doc = itemUuid const doc = itemUuid
? getDocFromElement(extensibleElement) ? getDocFromElement(extensibleElement)
: this.document.system.attack?.id === actionId : this.document.system.attack?.id === actionId
? this.document.system.attack ? this.document.system.attack
: this.document.system.actions?.find(a => a.id === actionId); : this.document.system.actions?.find(a => a.id === actionId);
if (!doc) return; if (!doc) return;
const description = doc.system?.description ?? doc.description; const description = doc.system?.description ?? doc.description;
const isAction = !!actionId; const isAction = !!actionId;
descriptionElement.innerHTML = await foundry.applications.ux.TextEditor.implementation.enrichHTML(description, { descriptionElement.innerHTML = await foundry.applications.ux.TextEditor.implementation.enrichHTML(
relativeTo: isAction ? doc.parent : doc, description,
rollData: doc.getRollData?.(), {
secrets: isAction ? doc.parent.isOwner : doc.isOwner relativeTo: isAction ? doc.parent : doc,
}); rollData: doc.getRollData?.(),
secrets: isAction ? doc.parent.isOwner : doc.isOwner
}
);
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
@ -427,26 +438,28 @@ export default function DHApplicationMixin(Base) {
const parent = parentIsItem && documentClass === 'Item' ? null : this.document; const parent = parentIsItem && documentClass === 'Item' ? null : this.document;
if (type === 'action') { if (type === 'action') {
const { type: actionType } = await foundry.applications.api.DialogV2.input({ const { type: actionType } =
window: { title: 'Select Action Type' }, (await foundry.applications.api.DialogV2.input({
content: await foundry.applications.handlebars.renderTemplate( window: { title: 'Select Action Type' },
'systems/daggerheart/templates/actionTypes/actionType.hbs', content: await foundry.applications.handlebars.renderTemplate(
{ types: CONFIG.DH.ACTIONS.actionTypes } 'systems/daggerheart/templates/actionTypes/actionType.hbs',
), { types: CONFIG.DH.ACTIONS.actionTypes }
ok: { ),
label: game.i18n.format('DOCUMENT.Create', { ok: {
type: game.i18n.localize('DAGGERHEART.GENERAL.Action.single') label: game.i18n.format('DOCUMENT.Create', {
}), type: game.i18n.localize('DAGGERHEART.GENERAL.Action.single')
} })
}) ?? {}; }
})) ?? {};
if (!actionType) return; if (!actionType) return;
const cls = game.system.api.models.actions.actionsTypes[actionType] const cls = game.system.api.models.actions.actionsTypes[actionType];
const action = new cls({ const action = new cls(
_id: foundry.utils.randomID(), {
type: actionType, _id: foundry.utils.randomID(),
name: game.i18n.localize(CONFIG.DH.ACTIONS.actionTypes[actionType].name), type: actionType,
...cls.getSourceConfig(this.document) name: game.i18n.localize(CONFIG.DH.ACTIONS.actionTypes[actionType].name),
}, ...cls.getSourceConfig(this.document)
},
{ {
parent: this.document parent: this.document
} }
@ -456,25 +469,32 @@ export default function DHApplicationMixin(Base) {
force: true force: true
}); });
return action; return action;
} else { } else {
const cls = getDocumentClass(documentClass); const cls = getDocumentClass(documentClass);
const data = { const data = {
name: cls.defaultName({ type, parent }), name: cls.defaultName({ type, parent }),
type, type
} };
if (inVault) data["system.inVault"] = true; if (inVault) data['system.inVault'] = true;
if (disabled) data.disabled = true; if (disabled) data.disabled = true;
const isItemFeature = parentIsItem && type === 'feature';
if (isItemFeature) {
data.system = {
originItemType: CONFIG.DH.ITEM.featureTypes[this.document.type].id,
originId: this.document.uuid
};
}
const doc = await cls.create(data, { parent, renderSheet: !event.shiftKey }); const doc = await cls.create(data, { parent, renderSheet: !event.shiftKey });
if (parentIsItem && type === 'feature') {
if (isItemFeature) {
await this.document.update({ await this.document.update({
'system.features': this.document.system.toObject().features.concat(doc.uuid) 'system.features': this.document.system.toObject().features.concat(doc.uuid)
}); });
} }
return doc; return doc;
} }
} }
/** /**
@ -489,7 +509,7 @@ export default function DHApplicationMixin(Base) {
const { actionId } = target.closest('[data-action-id]').dataset; const { actionId } = target.closest('[data-action-id]').dataset;
const { actions, attack } = this.document.system; 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 }) new DHActionConfig(action).render({ force: true });
} }
/** /**
@ -500,8 +520,8 @@ export default function DHApplicationMixin(Base) {
const doc = getDocFromElement(target); const doc = getDocFromElement(target);
if (doc) { if (doc) {
if (event.shiftKey) return doc.delete() if (event.shiftKey) return doc.delete();
else return await doc.deleteDialog() else return await doc.deleteDialog();
} }
// TODO: REDO this // TODO: REDO this
@ -524,7 +544,7 @@ export default function DHApplicationMixin(Base) {
} }
return await this.document.update({ return await this.document.update({
'system.actions': actions.filter((a) => a.id !== action.id) 'system.actions': actions.filter(a => a.id !== action.id)
}); });
} }
@ -555,7 +575,7 @@ export default function DHApplicationMixin(Base) {
const { actionId } = target.closest('[data-action-id]').dataset; const { actionId } = target.closest('[data-action-id]').dataset;
const { actions, attack } = this.document.system; 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);
if(this.document instanceof foundry.documents.Item && !this.document.parent) return; if (this.document instanceof foundry.documents.Item && !this.document.parent) return;
} }
await doc.use(event); await doc.use(event);
@ -573,7 +593,6 @@ export default function DHApplicationMixin(Base) {
await action.use(event); await action.use(event);
} }
/** /**
* Toggle a ActiveEffect * Toggle a ActiveEffect
* @type {ApplicationClickAction} * @type {ApplicationClickAction}
@ -604,7 +623,6 @@ export default function DHApplicationMixin(Base) {
const descriptionElement = extensible?.querySelector('.invetory-description'); const descriptionElement = extensible?.querySelector('.invetory-description');
if (t && !!descriptionElement) this.#prepareInventoryDescription(extensible, descriptionElement); if (t && !!descriptionElement) this.#prepareInventoryDescription(extensible, descriptionElement);
} }
} }
return DHSheetV2; return DHSheetV2;

View file

@ -72,10 +72,10 @@ export default class DHBaseItemSheet extends DHApplicationMixin(ItemSheetV2) {
secrets: this.item.isOwner secrets: this.item.isOwner
}); });
break; break;
case "effects": case 'effects':
await this._prepareEffectsContext(context, options) await this._prepareEffectsContext(context, options);
break; break;
case "features": case 'features':
context.isGM = game.user.isGM; context.isGM = game.user.isGM;
break; break;
} }
@ -93,7 +93,7 @@ export default class DHBaseItemSheet extends DHApplicationMixin(ItemSheetV2) {
async _prepareEffectsContext(context, _options) { async _prepareEffectsContext(context, _options) {
context.effects = { context.effects = {
actives: [], actives: [],
inactives: [], inactives: []
}; };
for (const effect of this.item.effects) { for (const effect of this.item.effects) {
@ -113,30 +113,38 @@ export default class DHBaseItemSheet extends DHApplicationMixin(ItemSheetV2) {
* @protected * @protected
*/ */
static #getFeatureContextOptions() { static #getFeatureContextOptions() {
const options = this._getContextMenuCommonOptions({ usable: true, toChat: true, deletable: false }) const options = this._getContextMenuCommonOptions({ usable: true, toChat: true, deletable: false });
options.push( options.push({
{ name: 'CONTROLS.CommonDelete',
name: 'CONTROLS.CommonDelete', icon: '<i class="fa-solid fa-trash"></i>',
icon: '<i class="fa-solid fa-trash"></i>', callback: async target => {
callback: async (target) => { const feature = getDocFromElement(target);
const feature = getDocFromElement(target); if (!feature) return;
if (!feature) return; const confirmed = await foundry.applications.api.DialogV2.confirm({
const confirmed = await foundry.applications.api.DialogV2.confirm({ window: {
window: { title: game.i18n.format('DAGGERHEART.APPLICATIONS.DeleteConfirmation.title', {
title: game.i18n.format('DAGGERHEART.APPLICATIONS.DeleteConfirmation.title', { type: game.i18n.localize(`TYPES.Item.feature`),
type: game.i18n.localize(`TYPES.Item.feature`), name: feature.name
name: feature.name })
}) },
}, content: game.i18n.format('DAGGERHEART.APPLICATIONS.DeleteConfirmation.text', {
content: game.i18n.format('DAGGERHEART.APPLICATIONS.DeleteConfirmation.text', { name: feature.name }) name: feature.name
}); })
if (!confirmed) return; });
await this.document.update({ if (!confirmed) return;
'system.features': this.document.system.toObject().features.filter(uuid => uuid !== feature.uuid)
}); await feature.update({
}, system: {
originItemType: null,
originId: null,
subType: null
}
});
await this.document.update({
'system.features': this.document.system.toObject().features.filter(uuid => uuid !== feature.uuid)
});
} }
) });
return options; return options;
} }
@ -153,7 +161,7 @@ export default class DHBaseItemSheet extends DHApplicationMixin(ItemSheetV2) {
const actionIndex = button.closest('[data-index]').dataset.index; const actionIndex = button.closest('[data-index]').dataset.index;
const action = this.document.system.actions[actionIndex]; const action = this.document.system.actions[actionIndex];
if(!event.shiftKey) { if (!event.shiftKey) {
const confirmed = await foundry.applications.api.DialogV2.confirm({ const confirmed = await foundry.applications.api.DialogV2.confirm({
window: { window: {
title: game.i18n.format('DAGGERHEART.APPLICATIONS.DeleteConfirmation.title', { title: game.i18n.format('DAGGERHEART.APPLICATIONS.DeleteConfirmation.title', {
@ -166,7 +174,6 @@ export default class DHBaseItemSheet extends DHApplicationMixin(ItemSheetV2) {
if (!confirmed) return; if (!confirmed) return;
} }
await this.document.update({ await this.document.update({
'system.actions': this.document.system.actions.filter((_, index) => index !== Number.parseInt(actionIndex)) 'system.actions': this.document.system.actions.filter((_, index) => index !== Number.parseInt(actionIndex))
}); });
@ -182,7 +189,11 @@ export default class DHBaseItemSheet extends DHApplicationMixin(ItemSheetV2) {
const feature = await cls.create({ const feature = await cls.create({
type: 'feature', type: 'feature',
name: cls.defaultName({ type: 'feature' }), name: cls.defaultName({ type: 'feature' }),
"system.subType": CONFIG.DH.ITEM.featureSubTypes[type] system: {
subType: CONFIG.DH.ITEM.featureSubTypes[type],
originItemType: CONFIG.DH.ITEM.featureTypes[this.document.type].id,
originId: this.document.uuid
}
}); });
await this.document.update({ await this.document.update({
'system.features': [...this.document.system.features, feature].map(f => f.uuid) 'system.features': [...this.document.system.features, feature].map(f => f.uuid)
@ -196,11 +207,15 @@ export default class DHBaseItemSheet extends DHApplicationMixin(ItemSheetV2) {
static async #deleteFeature(_, target) { static async #deleteFeature(_, target) {
const feature = getDocFromElement(target); const feature = getDocFromElement(target);
if (!feature) return ui.notifications.warn(game.i18n.localize('DAGGERHEART.UI.Notifications.featureIsMissing')); if (!feature) return ui.notifications.warn(game.i18n.localize('DAGGERHEART.UI.Notifications.featureIsMissing'));
await feature.update({ 'system.subType': null }); await feature.update({
system: {
originItemType: null,
originId: null,
subType: null
}
});
await this.document.update({ await this.document.update({
'system.features': this.document.system.features 'system.features': this.document.system.features.map(x => x.uuid).filter(uuid => uuid !== feature.uuid)
.map(x => x.uuid)
.filter(uuid => uuid !== feature.uuid)
}); });
} }
@ -275,6 +290,12 @@ export default class DHBaseItemSheet extends DHApplicationMixin(ItemSheetV2) {
const item = await fromUuid(data.uuid); const item = await fromUuid(data.uuid);
if (item?.type === 'feature') { if (item?.type === 'feature') {
await item.update({
system: {
originItemType: CONFIG.DH.ITEM.featureTypes[this.document.type].id,
originId: this.document.uuid
}
});
const current = this.document.system.features.map(x => x.uuid); const current = this.document.system.features.map(x => x.uuid);
await this.document.update({ 'system.features': [...current, item.uuid] }); await this.document.update({ 'system.features': [...current, item.uuid] });
} }

View file

@ -5,8 +5,7 @@ export default class AncestrySheet extends DHHeritageSheet {
static DEFAULT_OPTIONS = { static DEFAULT_OPTIONS = {
classes: ['ancestry'], classes: ['ancestry'],
actions: { actions: {
editFeature: AncestrySheet.#editFeature, editFeature: AncestrySheet.#editFeature
removeFeature: AncestrySheet.#removeFeature
}, },
dragDrop: [{ dragSelector: null, dropSelector: '.tab.features .drop-section' }] dragDrop: [{ dragSelector: null, dropSelector: '.tab.features .drop-section' }]
}; };
@ -37,21 +36,6 @@ export default class AncestrySheet extends DHHeritageSheet {
feature.sheet.render(true); 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[`${target.dataset.type}Feature`];
if (feature) await feature.update({ 'system.subType': null });
await this.document.update({
'system.features': this.document.system.features.filter(x => x && x.uuid !== feature.uuid).map(x => x.uuid)
});
}
/* -------------------------------------------- */ /* -------------------------------------------- */
/* Application Drag/Drop */ /* Application Drag/Drop */
/* -------------------------------------------- */ /* -------------------------------------------- */
@ -73,7 +57,14 @@ export default class AncestrySheet extends DHHeritageSheet {
return; return;
} }
await item.update({ 'system.subType': subType }); await item.update({
system: {
subType: subType,
originItemType: CONFIG.DH.ITEM.featureTypes[this.document.type].id,
originId: this.document.uuid
}
});
await this.document.update({ await this.document.update({
'system.features': [...this.document.system.features.map(x => x.uuid), item.uuid] 'system.features': [...this.document.system.features.map(x => x.uuid), item.uuid]
}); });

View file

@ -9,7 +9,7 @@ export default class ClassSheet extends DHBaseItemSheet {
position: { width: 700 }, position: { width: 700 },
actions: { actions: {
removeItemFromCollection: ClassSheet.#removeItemFromCollection, removeItemFromCollection: ClassSheet.#removeItemFromCollection,
removeSuggestedItem: ClassSheet.#removeSuggestedItem, removeSuggestedItem: ClassSheet.#removeSuggestedItem
}, },
tagifyConfigs: [ tagifyConfigs: [
{ {
@ -93,7 +93,13 @@ export default class ClassSheet extends DHBaseItemSheet {
return; return;
} }
await item.update({ 'system.subType': CONFIG.DH.ITEM.featureSubTypes.hope }); await item.update({
system: {
subType: CONFIG.DH.ITEM.featureSubTypes.hope,
originItemType: CONFIG.DH.ITEM.featureTypes[this.document.type].id,
originId: this.document.uuid
}
});
await this.document.update({ await this.document.update({
'system.features': [...this.document.system.features.map(x => x.uuid), item.uuid] 'system.features': [...this.document.system.features.map(x => x.uuid), item.uuid]
}); });
@ -103,7 +109,13 @@ export default class ClassSheet extends DHBaseItemSheet {
return; return;
} }
await item.update({ 'system.subType': CONFIG.DH.ITEM.featureSubTypes.class }); await item.update({
system: {
subType: CONFIG.DH.ITEM.featureSubTypes.class,
originItemType: CONFIG.DH.ITEM.featureTypes[this.document.type].id,
originId: this.document.uuid
}
});
await this.document.update({ await this.document.update({
'system.features': [...this.document.system.features.map(x => x.uuid), item.uuid] 'system.features': [...this.document.system.features.map(x => x.uuid), item.uuid]
}); });

View file

@ -68,7 +68,13 @@ export default class SubclassSheet extends DHBaseItemSheet {
return; return;
} }
await item.update({ 'system.subType': CONFIG.DH.ITEM.featureSubTypes.foundation }); await item.update({
system: {
subType: CONFIG.DH.ITEM.featureSubTypes.foundation,
originItemType: CONFIG.DH.ITEM.featureTypes[this.document.type].id,
originId: this.document.uuid
}
});
await this.document.update({ await this.document.update({
'system.features': [...this.document.system.features.map(x => x.uuid), item.uuid] 'system.features': [...this.document.system.features.map(x => x.uuid), item.uuid]
}); });
@ -78,7 +84,13 @@ export default class SubclassSheet extends DHBaseItemSheet {
return; return;
} }
await item.update({ 'system.subType': CONFIG.DH.ITEM.featureSubTypes.specialization }); await item.update({
system: {
subType: CONFIG.DH.ITEM.featureSubTypes.specialization,
originItemType: CONFIG.DH.ITEM.featureTypes[this.document.type].id,
originId: this.document.uuid
}
});
await this.document.update({ await this.document.update({
'system.features': [...this.document.system.features.map(x => x.uuid), item.uuid] 'system.features': [...this.document.system.features.map(x => x.uuid), item.uuid]
}); });
@ -88,7 +100,13 @@ export default class SubclassSheet extends DHBaseItemSheet {
return; return;
} }
await item.update({ 'system.subType': CONFIG.DH.ITEM.featureSubTypes.mastery }); await item.update({
system: {
subType: CONFIG.DH.ITEM.featureSubTypes.mastery,
originItemType: CONFIG.DH.ITEM.featureTypes[this.document.type].id,
originId: this.document.uuid
}
});
await this.document.update({ await this.document.update({
'system.features': [...this.document.system.features.map(x => x.uuid), item.uuid] 'system.features': [...this.document.system.features.map(x => x.uuid), item.uuid]
}); });

View file

@ -20,18 +20,10 @@ export default class DHAncestry extends BaseDataItem {
} }
get primaryFeature() { get primaryFeature() {
return ( return this.features.find(x => x?.system?.subType === CONFIG.DH.ITEM.featureSubTypes.primary) ?? null;
this.features.find(x => x?.system?.subType === CONFIG.DH.ITEM.featureSubTypes.primary) ??
(this.features.filter(x => !x).length > 0 ? {} : null)
);
} }
get secondaryFeature() { get secondaryFeature() {
return ( return this.features.find(x => x?.system?.subType === CONFIG.DH.ITEM.featureSubTypes.secondary) ?? null;
this.features.find(x => x?.system?.subType === CONFIG.DH.ITEM.featureSubTypes.secondary) ??
(this.features.filter(x => !x || x.system.subType === CONFIG.DH.ITEM.featureSubTypes.primary).length > 1
? {}
: null)
);
} }
} }

View file

@ -136,13 +136,24 @@ export default class BaseDataItem extends foundry.abstract.TypeDataModel {
} }
async _preDelete() { async _preDelete() {
if (!this.actor || this.actor.type !== 'character') return; if (this.originId) {
if (this.actor && this.actor.type === 'character') {
const items = this.actor.items.filter(item => item.system.originId === this.parent.id); const items = this.actor.items.filter(item => item.system.originId === this.parent.id);
if (items.length > 0) if (items.length > 0)
await this.actor.deleteEmbeddedDocuments( await this.actor.deleteEmbeddedDocuments(
'Item', 'Item',
items.map(x => x.id) items.map(x => x.id)
); );
} else {
const linkedItem = await foundry.utils.fromUuid(this.originId);
if (linkedItem) {
await linkedItem.update({
'system.features': linkedItem.system.features
.filter(x => x.uuid !== this.parent.uuid)
.map(x => x.uuid)
});
}
}
}
} }
} }

View file

@ -22,9 +22,8 @@ export default class DHFeature extends BaseDataItem {
nullable: true, nullable: true,
initial: null initial: null
}), }),
subType: new fields.StringField({ choices: CONFIG.DH.ITEM.featureSubTypes, nullable: true, initial: null }),
originId: new fields.StringField({ nullable: true, initial: null }), originId: new fields.StringField({ nullable: true, initial: null }),
identifier: new fields.StringField(), subType: new fields.StringField({ choices: CONFIG.DH.ITEM.featureSubTypes, nullable: true, initial: null }),
actions: new fields.ArrayField(new ActionField()) actions: new fields.ArrayField(new ActionField())
}; };
} }

View file

@ -26,14 +26,14 @@ Parameters:
<legend> <legend>
{{localize title}} {{localize title}}
{{#if canCreate}} {{#if canCreate}}
<a data-action="createDoc" data-document-class="{{ifThen (eq type 'effect') 'ActiveEffect' 'Item' }}" <a data-action="createDoc" data-document-class="{{ifThen (eq type 'effect') 'ActiveEffect' 'Item' }}"
data-type="{{ifThen (eq type 'effect') 'base' type}}" data-type="{{ifThen (eq type 'effect') 'base' type}}"
{{#if inVault}}data-in-vault="{{inVault}}"{{/if}} {{#if inVault}}data-in-vault="{{inVault}}"{{/if}}
{{#if disabled}} data-disabled="{{disabled}}"{{/if}} {{#if disabled}} data-disabled="{{disabled}}"{{/if}}
data-tooltip="{{localize 'DOCUMENT.Create' type=''}}" data-tooltip="{{localize 'DOCUMENT.Create' type=''}}"
> >
<i class="fa-solid fa-plus icon-button"></i> <i class="fa-solid fa-plus icon-button"></i>
</a> </a>
{{/if }} {{/if }}
</legend> </legend>
{{#if (and cardView (eq type 'domainCard'))}} {{#if (and cardView (eq type 'domainCard'))}}

View file

@ -17,7 +17,7 @@
<img class="image" src="{{document.system.primaryFeature.img}}" /> <img class="image" src="{{document.system.primaryFeature.img}}" />
<span>{{document.system.primaryFeature.name}}</span> <span>{{document.system.primaryFeature.name}}</span>
<div class="controls"> <div class="controls">
<a data-action="removeFeature" data-type="primary"><i class="fa-solid fa-trash"></i></a> <a data-action="deleteFeature" data-item-uuid="{{document.system.primaryFeature.uuid}}"><i class="fa-solid fa-trash"></i></a>
</div> </div>
</div> </div>
{{/if}} {{/if}}
@ -38,7 +38,7 @@
<img class="image" src="{{document.system.secondaryFeature.img}}" /> <img class="image" src="{{document.system.secondaryFeature.img}}" />
<span>{{document.system.secondaryFeature.name}}</span> <span>{{document.system.secondaryFeature.name}}</span>
<div class="controls"> <div class="controls">
<a data-action="removeFeature" data-type="secondary"><i class="fa-solid fa-trash"></i></a> <a data-action="deleteFeature" data-item-uuid="{{document.system.secondaryFeature.uuid}}"><i class="fa-solid fa-trash"></i></a>
</div> </div>
</div> </div>
{{/if}} {{/if}}