From 1da5d7a1f72bab04c9b2fa3f33af2d872ed09bb2 Mon Sep 17 00:00:00 2001 From: WBHarry Date: Sat, 6 Dec 2025 02:27:29 +0100 Subject: [PATCH] Fixed effect removal --- lang/en.json | 2 +- .../sheets-configs/setting-feature-config.mjs | 21 +++++++++++- module/config/itemConfig.mjs | 34 ++++++++----------- 3 files changed, 35 insertions(+), 22 deletions(-) diff --git a/lang/en.json b/lang/en.json index d2e67c15..1b0041f1 100755 --- a/lang/en.json +++ b/lang/en.json @@ -2385,7 +2385,7 @@ "downtimeMove": "Downtime Move", "armorFeature": "Armor Feature", "weaponFeature": "Weapon Feature", - "newFeature": "New ItemFeature", + "newFeature": "New Item Feature", "downtimeMoves": "Downtime Moves", "itemFeatures": "Item Features", "nrChoices": "# Moves Per Rest", diff --git a/module/applications/sheets-configs/setting-feature-config.mjs b/module/applications/sheets-configs/setting-feature-config.mjs index 0f37e548..e8bf6109 100644 --- a/module/applications/sheets-configs/setting-feature-config.mjs +++ b/module/applications/sheets-configs/setting-feature-config.mjs @@ -102,6 +102,8 @@ export default class SettingFeatureConfig extends HandlebarsApplicationMixin(App return ( (await foundry.applications.api.DialogV2.input({ window: { title: game.i18n.localize('DAGGERHEART.CONFIG.SelectAction.selectType') }, + position: { width: 300 }, + classes: ['daggerheart', 'dh-style'], content: await foundry.applications.handlebars.renderTemplate( 'systems/daggerheart/templates/actionTypes/actionType.hbs', { types: CONFIG.DH.ACTIONS.actionTypes } @@ -185,7 +187,24 @@ export default class SettingFeatureConfig extends HandlebarsApplicationMixin(App static async removeItem(_, target) { const { type, id } = target.dataset; if (type === 'effect') { - await this.settings.updateSource({ [`${this.movePath}.effects.-=${id}`]: null }); + const move = foundry.utils.getProperty(this.settings, this.movePath); + for (const action of move.actions) { + const remainingEffects = action.effects.filter(x => x._id !== id); + if (action.effects.length !== remainingEffects.length) { + await action.update({ + effects: remainingEffects.map(x => { + const { _id, ...rest } = x; + return { ...rest, _id: _id }; + }) + }); + } + } + await this.settings.updateSource({ + [this.movePath]: { + effects: move.effects.filter(x => x.id !== id), + actions: move.actions + } + }); } else { await this.settings.updateSource({ [`${this.actionsPath}.-=${target.dataset.id}`]: null }); } diff --git a/module/config/itemConfig.mjs b/module/config/itemConfig.mjs index d4383760..a9ad1d68 100644 --- a/module/config/itemConfig.mjs +++ b/module/config/itemConfig.mjs @@ -459,16 +459,13 @@ export const allArmorFeatures = () => { ...armorFeatures, ...Object.keys(homebrewFeatures).reduce((acc, key) => { const feature = homebrewFeatures[key]; - const actionEffects = []; - const actions = feature.actions.map(action => { - const effects = action.effects.map(effect => feature.effects.find(x => x.id === effect._id)); - actionEffects.push(...effects); - return { - ...action, - effects: effects, - type: action.type - }; - }); + const actions = feature.actions.map(action => ({ + ...action, + effects: action.effects.map(effect => feature.effects.find(x => x.id === effect._id)), + type: action.type + })); + const actionEffects = actions.flatMap(a => a.effects); + const effects = feature.effects.filter(effect => !actionEffects.some(x => x.id === effect.id)); acc[key] = { ...feature, label: feature.name, effects, actions }; @@ -1431,16 +1428,13 @@ export const allWeaponFeatures = () => { ...weaponFeatures, ...Object.keys(homebrewFeatures).reduce((acc, key) => { const feature = homebrewFeatures[key]; - const actionEffects = []; - const actions = feature.actions.map(action => { - const effects = action.effects.map(effect => feature.effects.find(x => x.id === effect._id)); - actionEffects.push(...effects); - return { - ...action, - effects: effects, - type: action.type - }; - }); + + const actions = feature.actions.map(action => ({ + ...action, + effects: action.effects.map(effect => feature.effects.find(x => x.id === effect._id)), + type: action.type + })); + const actionEffects = actions.flatMap(a => a.effects); const effects = feature.effects.filter(effect => !actionEffects.some(x => x.id === effect.id)); acc[key] = { ...feature, label: feature.name, effects, actions };