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

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