[Feature] Damage Iterrable Rework (#1685)

* Initial

* More

* Fixed current actionConfig damage

* Reworked ActionConfig damage ui

* .

* Updated all Adversary compendium damage entries

* more

* The rest

* Fixed misses

* .

* .

* Also migrate sub fields of MappingField

* Removed MappingField

* Fix regression with re-tiering adversaries when dealing non-hp damage

* Allow iterable object to be detected as an object by foundry

---------

Co-authored-by: Carlos Fernandez <cfern1990@gmail.com>
This commit is contained in:
WBHarry 2026-03-08 00:58:24 +01:00 committed by GitHub
parent d3ebd30e59
commit 5a4bbc91f5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
536 changed files with 2476 additions and 2368 deletions

View file

@ -1,4 +1,5 @@
export { ActionCollection } from './actionField.mjs';
export { default as IterableTypedObjectField } from './iterableTypedObjectField.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 IterableTypedObjectField from '../iterableTypedObjectField.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 IterableTypedObjectField(DHDamageData),
includeBase: new fields.BooleanField({
initial: false,
label: 'DAGGERHEART.ACTIONS.Settings.includeBase.label'

View file

@ -0,0 +1,32 @@
export default class IterableTypedObjectField 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;
}
#elementClass;
/** Initializes an object with an iterator. This modifies the prototype instead of */
initialize(values) {
const object = Object.create(IterableObjectPrototype);
for (const [key, value] of Object.entries(values)) {
object[key] = new this.#elementClass(value);
}
return object;
}
}
/**
* The prototype of an iterable object.
* This allows the functionality of a class but also allows foundry.utils.getType() to return "Object" instead of "Unknown".
*/
const IterableObjectPrototype = {
[Symbol.iterator]: function*() {
for (const value of Object.values(this)) {
yield value;
}
},
map: function (func) {
return Array.from(this, func);
}
};