mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-03-07 14:36:13 +01:00
More
This commit is contained in:
parent
5113e37574
commit
c99a76f4f4
15 changed files with 78 additions and 67 deletions
|
|
@ -1,5 +1,5 @@
|
|||
export { ActionCollection } from './actionField.mjs';
|
||||
export { default as CollectionField } from './collectionField.mjs';
|
||||
export { default as IterableTypedObjectField } from './iterableTypedObjectField.mjs';
|
||||
export { default as FormulaField } from './formulaField.mjs';
|
||||
export { default as ForeignDocumentUUIDField } from './foreignDocumentUUIDField.mjs';
|
||||
export { default as ForeignDocumentUUIDArrayField } from './foreignDocumentUUIDArrayField.mjs';
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import FormulaField from '../formulaField.mjs';
|
||||
import { setsEqual } from '../../../helpers/utils.mjs';
|
||||
import CollectionField from '../collectionField.mjs';
|
||||
import IterableTypedObjectField from '../iterableTypedObjectField.mjs';
|
||||
|
||||
const fields = foundry.data.fields;
|
||||
|
||||
|
|
@ -13,7 +13,7 @@ export default class DamageField extends fields.SchemaField {
|
|||
/** @inheritDoc */
|
||||
constructor(options, context = {}) {
|
||||
const damageFields = {
|
||||
parts: new CollectionField(DHDamageData, { collectionClass: DamagePartsCollection }),
|
||||
parts: new IterableTypedObjectField(DHDamageData),
|
||||
includeBase: new fields.BooleanField({
|
||||
initial: false,
|
||||
label: 'DAGGERHEART.ACTIONS.Settings.includeBase.label'
|
||||
|
|
@ -301,9 +301,3 @@ export class DHDamageData extends DHResourceData {
|
|||
};
|
||||
}
|
||||
}
|
||||
|
||||
class DamagePartsCollection extends foundry.utils.Collection {
|
||||
get hitPoints() {
|
||||
return this.get('hitPoints');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,25 +0,0 @@
|
|||
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;
|
||||
}
|
||||
}
|
||||
30
module/data/fields/iterableTypedObjectField.mjs
Normal file
30
module/data/fields/iterableTypedObjectField.mjs
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
export default class IterableTypedObjectField 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;
|
||||
}
|
||||
|
||||
#elementClass;
|
||||
|
||||
initialize(value) {
|
||||
return new IterableObject(value, this.#elementClass);
|
||||
}
|
||||
}
|
||||
|
||||
class IterableObject {
|
||||
constructor(values, elementClass) {
|
||||
for (const [key, value] of Object.entries(values)) {
|
||||
this[key] = new elementClass(value);
|
||||
}
|
||||
}
|
||||
|
||||
*[Symbol.iterator]() {
|
||||
for (const value of Object.values(this)) {
|
||||
yield value;
|
||||
}
|
||||
}
|
||||
|
||||
map(func) {
|
||||
return Array.from(this, func);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue