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,5 +1,3 @@
import { actionsTypes } from '../action/_module.mjs';
/**
* Describes metadata about the item data model type
* @typedef {Object} ItemDataModelMetadata
@ -61,8 +59,8 @@ export default class BaseDataItem extends foundry.abstract.TypeDataModel {
if (!this.constructor.metadata.hasInitialAction || !foundry.utils.isEmpty(this.actions)) return;
const metadataType = this.constructor.metadata.type;
const actionType = { weapon: "attack" }[metadataType];
const ActionClass = actionsTypes[actionType];
const actionType = { weapon: 'attack' }[metadataType];
const ActionClass = game.system.api.models.actions.actionsTypes[actionType];
const action = new ActionClass(
{
@ -79,4 +77,31 @@ export default class BaseDataItem extends foundry.abstract.TypeDataModel {
this.updateSource({ actions: [action] });
}
_onCreate(data) {
if (!this.actor || this.actor.type !== 'character' || !this.features) return;
this.actor.createEmbeddedDocuments(
'Item',
this.features.map(feature => ({
...feature,
system: {
...feature.system,
type: this.parent.type,
originId: data._id,
identifier: feature.identifier
}
}))
);
}
async _preDelete() {
if (!this.actor || this.actor.type !== 'character') return;
const items = this.actor.items.filter(item => item.system.originId === this.parent.id);
if (items.length > 0)
await this.actor.deleteEmbeddedDocuments(
'Item',
items.map(x => x.id)
);
}
}