This commit is contained in:
WBHarry 2026-02-25 00:15:56 +01:00
parent 340abbc98c
commit 5113e37574
6 changed files with 51 additions and 9 deletions

View file

@ -376,6 +376,15 @@ export default class DHBaseAction extends ActionMixin(foundry.abstract.DataModel
return tags;
}
static migrateData(source) {
if (source.damage?.parts && Array.isArray(source.damage.parts)) {
source.damage.parts = source.damage.parts.reduce((acc, part) => {
acc[part.applyTo] = part;
return acc;
}, {});
}
}
}
export class ResourceUpdateMap extends Map {

View file

@ -704,7 +704,7 @@ export default class DhCharacter extends DhCreature {
isReversed: true
};
this.attack.damage.parts[0].value.custom.formula = `@prof${this.basicAttackDamageDice}${this.rules.attack.damage.bonus ? ` + ${this.rules.attack.damage.bonus}` : ''}`;
this.attack.damage.parts.hitPoints.value.custom.formula = `@prof${this.basicAttackDamageDice}${this.rules.attack.damage.bonus ? ` + ${this.rules.attack.damage.bonus}` : ''}`;
}
getRollData() {

View file

@ -1,4 +1,5 @@
export { ActionCollection } from './actionField.mjs';
export { default as CollectionField } from './collectionField.mjs';
export { default as FormulaField } from './formulaField.mjs';
export { default as ForeignDocumentUUIDField } from './foreignDocumentUUIDField.mjs';
export { default as ForeignDocumentUUIDArrayField } from './foreignDocumentUUIDArrayField.mjs';

View file

@ -1,5 +1,6 @@
import FormulaField from '../formulaField.mjs';
import { setsEqual } from '../../../helpers/utils.mjs';
import CollectionField from '../collectionField.mjs';
const fields = foundry.data.fields;
@ -12,7 +13,7 @@ export default class DamageField extends fields.SchemaField {
/** @inheritDoc */
constructor(options, context = {}) {
const damageFields = {
parts: new fields.ArrayField(new fields.EmbeddedDataField(DHDamageData)),
parts: new CollectionField(DHDamageData, { collectionClass: DamagePartsCollection }),
includeBase: new fields.BooleanField({
initial: false,
label: 'DAGGERHEART.ACTIONS.Settings.includeBase.label'
@ -300,3 +301,9 @@ export class DHDamageData extends DHResourceData {
};
}
}
class DamagePartsCollection extends foundry.utils.Collection {
get hitPoints() {
return this.get('hitPoints');
}
}

View file

@ -0,0 +1,25 @@
export default class CollectionField extends foundry.data.fields.TypedObjectField {
constructor(model, options = { collectionClass: foundry.utils.Collection }, context = {}) {
super(new foundry.data.fields.EmbeddedDataField(model), options, context);
this.#elementClass = model;
this.#collectionClass = options.collectionClass;
}
/**
* The collection class
*/
#collectionClass;
/**
* The collection element class.
*/
#elementClass;
initialize(value, model, _options = {}) {
console.log(model);
const collection = new this.#collectionClass(
Object.entries(value).map(([key, value]) => [key, new this.#elementClass(value)])
);
return collection;
}
}