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,4 @@
import ActionField from '../fields/actionField.mjs';
import ForeignDocumentUUIDArrayField from '../fields/foreignDocumentUUIDArrayField.mjs';
import BaseDataItem from './base.mjs';
export default class DHAncestry extends BaseDataItem {
@ -13,10 +13,9 @@ export default class DHAncestry extends BaseDataItem {
/** @inheritDoc */
static defineSchema() {
const fields = foundry.data.fields;
return {
...super.defineSchema(),
actions: new fields.ArrayField(new ActionField())
features: new ForeignDocumentUUIDArrayField({ type: 'Item' })
};
}
}

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)
);
}
}

View file

@ -39,10 +39,7 @@ export default class DHBeastform extends BaseDataItem {
};
}
async _preCreate(data, options, user) {
const allowed = await super._preCreate(data, options, user);
if (allowed === false) return;
async _preCreate() {
if (!this.actor) return;
if (this.actor.type !== 'character') {

View file

@ -1,7 +1,6 @@
import BaseDataItem from './base.mjs';
import ForeignDocumentUUIDField from '../fields/foreignDocumentUUIDField.mjs';
import ForeignDocumentUUIDArrayField from '../fields/foreignDocumentUUIDArrayField.mjs';
import ActionField from '../fields/actionField.mjs';
export default class DHClass extends BaseDataItem {
/** @inheritDoc */
@ -28,8 +27,8 @@ export default class DHClass extends BaseDataItem {
label: 'DAGGERHEART.Sheets.Class.HitPoints'
}),
evasion: new fields.NumberField({ initial: 0, integer: true, label: 'DAGGERHEART.Sheets.Class.Evasion' }),
hopeFeatures: new foundry.data.fields.ArrayField(new ActionField()),
classFeatures: new foundry.data.fields.ArrayField(new ActionField()),
hopeFeatures: new ForeignDocumentUUIDArrayField({ type: 'Item' }),
classFeatures: new ForeignDocumentUUIDArrayField({ type: 'Item' }),
subclasses: new ForeignDocumentUUIDArrayField({ type: 'Item', required: false }),
inventory: new fields.SchemaField({
take: new ForeignDocumentUUIDArrayField({ type: 'Item', required: false }),
@ -57,6 +56,10 @@ export default class DHClass extends BaseDataItem {
return this.hopeFeatures.length > 0 ? this.hopeFeatures[0] : null;
}
get features() {
return [...this.hopeFeatures.filter(x => x), ...this.classFeatures.filter(x => x)];
}
async _preCreate(data, options, user) {
const allowed = await super._preCreate(data, options, user);
if (allowed === false) return;

View file

@ -1,4 +1,4 @@
import ActionField from '../fields/actionField.mjs';
import ForeignDocumentUUIDArrayField from '../fields/foreignDocumentUUIDArrayField.mjs';
import BaseDataItem from './base.mjs';
export default class DHCommunity extends BaseDataItem {
@ -16,7 +16,7 @@ export default class DHCommunity extends BaseDataItem {
const fields = foundry.data.fields;
return {
...super.defineSchema(),
actions: new fields.ArrayField(new ActionField())
features: new ForeignDocumentUUIDArrayField({ type: 'Item' })
};
}
}

View file

@ -16,6 +16,9 @@ export default class DHFeature extends BaseDataItem {
const fields = foundry.data.fields;
return {
...super.defineSchema(),
type: new fields.StringField({ choices: CONFIG.DH.ITEM.featureTypes, nullable: true, initial: null }),
originId: new fields.StringField({ nullable: true, initial: null }),
identifier: new fields.StringField(),
actions: new fields.ArrayField(new ActionField())
};
}

View file

@ -1,15 +1,6 @@
import ActionField from '../fields/actionField.mjs';
import ForeignDocumentUUIDArrayField from '../fields/foreignDocumentUUIDArrayField.mjs';
import ForeignDocumentUUIDField from '../fields/foreignDocumentUUIDField.mjs';
import BaseDataItem from './base.mjs';
const featureSchema = () => {
return new foundry.data.fields.SchemaField({
name: new foundry.data.fields.StringField({ required: true }),
effects: new ForeignDocumentUUIDArrayField({ type: 'ActiveEffect', required: false }),
actions: new foundry.data.fields.ArrayField(new ActionField())
});
};
export default class DHSubclass extends BaseDataItem {
/** @inheritDoc */
static get metadata() {
@ -31,20 +22,20 @@ export default class DHSubclass extends BaseDataItem {
nullable: true,
initial: null
}),
foundationFeature: featureSchema(),
specializationFeature: featureSchema(),
masteryFeature: featureSchema(),
foundationFeature: new ForeignDocumentUUIDField({ type: 'Item' }),
specializationFeature: new ForeignDocumentUUIDField({ type: 'Item' }),
masteryFeature: new ForeignDocumentUUIDField({ type: 'Item' }),
featureState: new fields.NumberField({ required: true, initial: 1, min: 1 }),
isMulticlass: new fields.BooleanField({ initial: false })
};
}
get features() {
return {
foundation: this.foundationFeature,
specialization: this.featureState >= 2 ? this.specializationFeature : null,
mastery: this.featureState === 3 ? this.masteryFeature : null
};
return [
{ ...this.foundationFeature.toObject(), identifier: 'foundationFeature' },
{ ...this.specializationFeature.toObject(), identifier: 'specializationFeature' },
{ ...this.masteryFeature.toObject(), identifier: 'masteryFeature' }
];
}
async _preCreate(data, options, user) {

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);
}
}
}