mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-03-07 22:46:12 +01:00
Initial
This commit is contained in:
parent
340abbc98c
commit
5113e37574
6 changed files with 51 additions and 9 deletions
25
module/data/fields/collectionField.mjs
Normal file
25
module/data/fields/collectionField.mjs
Normal 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;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue