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;
|
||||
|
||||
initialize(value) {
|
||||
return new IterableObject(value, this.#elementClass);
|
||||
}
|
||||
}
|
||||
|
||||
class IterableObject {
|
||||
constructor(values, 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)) {
|
||||
this[key] = new elementClass(value);
|
||||
object[key] = new this.#elementClass(value);
|
||||
}
|
||||
return object;
|
||||
}
|
||||
}
|
||||
|
||||
*[Symbol.iterator]() {
|
||||
/**
|
||||
* 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(func) {
|
||||
},
|
||||
map: function (func) {
|
||||
return Array.from(this, func);
|
||||
}
|
||||
}
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue