264 - Action Feature Swap (#265)

* Removed action fields on Adversary/Environment in favor of using Feature Items

* Added drag/drop for features onto adversary/environment settings

* Added Drag of features from Adversary/Environment settings to anywhere in Foundry

* Updated all item types except Class/Subclass

* Added for Class/Subclass

* Items now copy over their features to Character

* Corrected back to actions for right items

* Fixed adversary/environment features display

* PR Fixes
This commit is contained in:
WBHarry 2025-07-05 22:35:05 +02:00 committed by GitHub
parent eac58c1386
commit e9ad9c539a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
58 changed files with 1146 additions and 1114 deletions

View file

@ -1,4 +1,5 @@
import BaseDataItem from './base.mjs';
import { actionsTypes } from '../action/_module.mjs';
import ActionField from '../fields/actionField.mjs';
export default class DHWeapon extends BaseDataItem {
@ -56,20 +57,20 @@ export default class DHWeapon extends BaseDataItem {
const allowed = await super._preUpdate(changes, options, user);
if (allowed === false) return false;
if (changes.system.features) {
if (changes.system?.features) {
const removed = this.features.filter(x => !changes.system.features.includes(x));
const added = changes.system.features.filter(x => !this.features.includes(x));
for (var feature of removed) {
for (var effectId of feature.effectIds) {
for (let weaponFeature of removed) {
for (var effectId of weaponFeature.effectIds) {
await this.parent.effects.get(effectId).delete();
}
changes.system.actions = this.actions.filter(x => !feature.actionIds.includes(x._id));
changes.system.actions = this.actions.filter(x => !weaponFeature.actionIds.includes(x._id));
}
for (var feature of added) {
const featureData = CONFIG.DH.ITEM.weaponFeatures[feature.value];
for (let weaponFeature of added) {
const featureData = CONFIG.DH.ITEM.weaponFeatures[weaponFeature.value];
if (featureData.effects?.length > 0) {
const embeddedItems = await this.parent.createEmbeddedDocuments('ActiveEffect', [
{
@ -78,18 +79,18 @@ export default class DHWeapon extends BaseDataItem {
changes: featureData.effects.flatMap(x => x.changes)
}
]);
feature.effectIds = embeddedItems.map(x => x.id);
weaponFeature.effectIds = embeddedItems.map(x => x.id);
}
if (featureData.actions?.length > 0) {
const newActions = featureData.actions.map(action => {
const cls = CONFIG.DH.ACTIONS.actionsTypes[action.type];
const cls = actionsTypes[action.type];
return new cls(
{ ...action, _id: foundry.utils.randomID(), name: game.i18n.localize(action.name) },
{ parent: this }
);
});
changes.system.actions = [...this.actions, ...newActions];
feature.actionIds = newActions.map(x => x._id);
weaponFeature.actionIds = newActions.map(x => x._id);
}
}
}