Refactor/actions v2 (#402)

* Action Refactor Part #1

* Fixed Weapon/Armor features. Fixed Feature actions

* f

* Action Refactor Part #2

* Fixes

* Remove ActionsField from Companion

* Fixes

* Localization fix

* BaseDataItem hasActions false

---------

Co-authored-by: WBHarry <williambjrklund@gmail.com>
This commit is contained in:
Dapoulp 2025-07-25 01:10:49 +02:00 committed by GitHub
parent 80744381f5
commit 0632a8c6bb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
52 changed files with 988 additions and 743 deletions

View file

@ -1,6 +1,5 @@
import AttachableItem from './attachableItem.mjs';
import { actionsTypes } from '../action/_module.mjs';
import ActionField from '../fields/actionField.mjs';
import { ActionsField, ActionField } from '../fields/actionField.mjs';
export default class DHWeapon extends AttachableItem {
/** @inheritDoc */
@ -9,8 +8,8 @@ export default class DHWeapon extends AttachableItem {
label: 'TYPES.Item.weapon',
type: 'weapon',
hasDescription: true,
isInventoryItem: true
// hasInitialAction: true
isInventoryItem: true,
hasActions: true
});
}
@ -64,8 +63,7 @@ export default class DHWeapon extends AttachableItem {
]
}
}
}),
actions: new fields.ArrayField(new ActionField())
})
};
}
@ -95,7 +93,10 @@ export default class DHWeapon extends AttachableItem {
}
await this.parent.deleteEmbeddedDocuments('ActiveEffect', removedEffectsUpdate);
changes.system.actions = this.actions.filter(x => !removedActionsUpdate.includes(x._id));
changes.system.actions = removedActionsUpdate.reduce((acc, id) => {
acc[`-=${id}`] = null;
return acc;
}, {});
for (let weaponFeature of added) {
const featureData = CONFIG.DH.ITEM.weaponFeatures[weaponFeature.value];
@ -110,7 +111,7 @@ export default class DHWeapon extends AttachableItem {
weaponFeature.effectIds = embeddedItems.map(x => x.id);
}
const newActions = [];
const newActions = {};
if (featureData.actions?.length > 0) {
for (let action of featureData.actions) {
const embeddedEffects = await this.parent.createEmbeddedDocuments(
@ -122,24 +123,25 @@ export default class DHWeapon extends AttachableItem {
description: game.i18n.localize(effect.description)
}))
);
const cls = actionsTypes[action.type];
newActions.push(
new cls(
{
...action,
_id: foundry.utils.randomID(),
name: game.i18n.localize(action.name),
description: game.i18n.localize(action.description),
effects: embeddedEffects.map(x => ({ _id: x.id }))
},
{ parent: this }
)
const cls = game.system.api.models.actions.actionsTypes[action.type];
const actionId = foundry.utils.randomID();
newActions[actionId] = new cls(
{
...cls.getSourceConfig(this),
...action,
_id: actionId,
name: game.i18n.localize(action.name),
description: game.i18n.localize(action.description),
effects: embeddedEffects.map(x => ({ _id: x.id }))
},
{ parent: this }
);
}
}
changes.system.actions = [...this.actions, ...newActions];
weaponFeature.actionIds = newActions.map(x => x._id);
changes.system.actions = newActions;
weaponFeature.actionIds = Object.keys(newActions);
}
}
}