mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-03-07 06:26:13 +01:00
Allow iterable object to be detected as an object by foundry
This commit is contained in:
parent
8727cb0dca
commit
0ace9f2b8e
1 changed files with 16 additions and 14 deletions
|
|
@ -6,25 +6,27 @@ export default class IterableTypedObjectField extends foundry.data.fields.TypedO
|
||||||
|
|
||||||
#elementClass;
|
#elementClass;
|
||||||
|
|
||||||
initialize(value) {
|
/** Initializes an object with an iterator. This modifies the prototype instead of */
|
||||||
return new IterableObject(value, this.#elementClass);
|
initialize(values) {
|
||||||
|
const object = Object.create(IterableObjectPrototype);
|
||||||
|
for (const [key, value] of Object.entries(values)) {
|
||||||
|
object[key] = new this.#elementClass(value);
|
||||||
|
}
|
||||||
|
return object;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class IterableObject {
|
/**
|
||||||
constructor(values, elementClass) {
|
* The prototype of an iterable object.
|
||||||
for (const [key, value] of Object.entries(values)) {
|
* This allows the functionality of a class but also allows foundry.utils.getType() to return "Object" instead of "Unknown".
|
||||||
this[key] = new elementClass(value);
|
*/
|
||||||
}
|
const IterableObjectPrototype = {
|
||||||
}
|
[Symbol.iterator]: function*() {
|
||||||
|
|
||||||
*[Symbol.iterator]() {
|
|
||||||
for (const value of Object.values(this)) {
|
for (const value of Object.values(this)) {
|
||||||
yield value;
|
yield value;
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
map: function (func) {
|
||||||
map(func) {
|
|
||||||
return Array.from(this, func);
|
return Array.from(this, func);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
Loading…
Add table
Add a link
Reference in a new issue