mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-03-07 14:36:13 +01:00
25 lines
771 B
JavaScript
25 lines
771 B
JavaScript
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;
|
|
}
|
|
}
|