mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-15 05:01:08 +01:00
FIX: ForeignDocumentUUIDField initialize like a getter
FEAT: ForeignDocumentUUIDArrayField created and used
This commit is contained in:
parent
5463f71526
commit
d18141bb65
7 changed files with 32 additions and 20 deletions
|
|
@ -1,5 +1,3 @@
|
||||||
export { default as DhClass } from './item/class.mjs';
|
|
||||||
export { default as DhSubclass } from './item/subclass.mjs';
|
|
||||||
export { default as DhCombat } from './combat.mjs';
|
export { default as DhCombat } from './combat.mjs';
|
||||||
export { default as DhCombatant } from './combatant.mjs';
|
export { default as DhCombatant } from './combatant.mjs';
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,3 @@
|
||||||
export { default as FormulaField } from './formulaField.mjs';
|
export { default as FormulaField } from './formulaField.mjs';
|
||||||
export { default as ForeignDocumentUUIDField } from './foreignDocumentUUIDField.mjs';
|
export { default as ForeignDocumentUUIDField } from './foreignDocumentUUIDField.mjs';
|
||||||
|
export { default as ForeignDocumentUUIDArrayField } from "./foreignDocumentUUIDArrayField.mjs";
|
||||||
21
module/data/fields/foreignDocumentUUIDArrayField.mjs
Normal file
21
module/data/fields/foreignDocumentUUIDArrayField.mjs
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
import ForeignDocumentUUIDField from "./foreignDocumentUUIDField.mjs";
|
||||||
|
/**
|
||||||
|
* A subclass of {@link foundry.data.fields.ArrayField} that defines an array of foreign document UUID references.
|
||||||
|
*/
|
||||||
|
export default class ForeignDocumentUUIDArrayField extends foundry.data.fields.ArrayField {
|
||||||
|
/**
|
||||||
|
* @param {foundry.data.types.DocumentUUIDFieldOptions} [fieldOption] - Options to configure each individual ForeignDocumentUUIDField.
|
||||||
|
* @param {foundry.data.types.ArrayFieldOptions} [options] - Options to configure the array behavior
|
||||||
|
* @param {foundry.data.types.DataFieldContext} [context] - Optional context for schema processing
|
||||||
|
*/
|
||||||
|
constructor(fieldOption = {}, options = {}, context = {}) {
|
||||||
|
super(new ForeignDocumentUUIDField(fieldOption), options, context);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @inheritdoc */
|
||||||
|
initialize(value, model, options = {}) {
|
||||||
|
const v = super.initialize(value, model, options);
|
||||||
|
return () => v.map(entry => typeof entry === 'function' ? entry() : entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -31,7 +31,7 @@ export default class ForeignDocumentUUIDField extends foundry.data.fields.Docume
|
||||||
console.error(error);
|
console.error(error);
|
||||||
return value ?? null;
|
return value ?? null;
|
||||||
}
|
}
|
||||||
})();
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**@override */
|
/**@override */
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@
|
||||||
* @property {string} type - The system type that this data model represents.
|
* @property {string} type - The system type that this data model represents.
|
||||||
* @property {boolean} hasDescription - Indicates whether items of this type have description field
|
* @property {boolean} hasDescription - Indicates whether items of this type have description field
|
||||||
* @property {boolean} isQuantifiable - Indicates whether items of this type have quantity field
|
* @property {boolean} isQuantifiable - Indicates whether items of this type have quantity field
|
||||||
* @property {Record<string,string>} embedded - Record of document names of pseudo-documents and the path to the collection
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const fields = foundry.data.fields;
|
const fields = foundry.data.fields;
|
||||||
|
|
@ -18,7 +17,6 @@ export default class BaseDataItem extends foundry.abstract.TypeDataModel {
|
||||||
type: "base",
|
type: "base",
|
||||||
hasDescription: false,
|
hasDescription: false,
|
||||||
isQuantifiable: false,
|
isQuantifiable: false,
|
||||||
embedded: {},
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import BaseDataItem from './base.mjs';
|
import BaseDataItem from './base.mjs';
|
||||||
import ForeignDocumentUUIDField from '../fields/foreignDocumentUUIDField.mjs';
|
import ForeignDocumentUUIDField from '../fields/foreignDocumentUUIDField.mjs';
|
||||||
|
import ForeignDocumentUUIDArrayField from '../fields/foreignDocumentUUIDArrayField.mjs';
|
||||||
import ActionField from '../fields/actionField.mjs';
|
import ActionField from '../fields/actionField.mjs';
|
||||||
|
|
||||||
export default class DHClass extends BaseDataItem {
|
export default class DHClass extends BaseDataItem {
|
||||||
|
|
@ -18,23 +19,16 @@ export default class DHClass extends BaseDataItem {
|
||||||
return {
|
return {
|
||||||
...super.defineSchema(),
|
...super.defineSchema(),
|
||||||
domains: new fields.ArrayField(new fields.StringField(), { max: 2 }),
|
domains: new fields.ArrayField(new fields.StringField(), { max: 2 }),
|
||||||
classItems: new fields.ArrayField(new ForeignDocumentUUIDField({ type: 'Item' })),
|
classItems: new ForeignDocumentUUIDArrayField({type: 'Item', required: false}),
|
||||||
|
|
||||||
evasion: new fields.NumberField({ initial: 0, integer: true }),
|
evasion: new fields.NumberField({ initial: 0, integer: true }),
|
||||||
hopeFeatures: new foundry.data.fields.ArrayField(new ActionField()),
|
hopeFeatures: new foundry.data.fields.ArrayField(new ActionField()),
|
||||||
classFeatures: new foundry.data.fields.ArrayField(new ActionField()),
|
classFeatures: new foundry.data.fields.ArrayField(new ActionField()),
|
||||||
subclasses: new fields.ArrayField(
|
subclasses: new ForeignDocumentUUIDArrayField({type: 'Item', required: false}),
|
||||||
new ForeignDocumentUUIDField({ type: 'Item', required: false, nullable: true, initial: undefined })
|
|
||||||
),
|
|
||||||
inventory: new fields.SchemaField({
|
inventory: new fields.SchemaField({
|
||||||
take: new fields.ArrayField(
|
take: new ForeignDocumentUUIDArrayField({type: 'Item', required: false}),
|
||||||
new ForeignDocumentUUIDField({ type: 'Item', required: false, nullable: true, initial: undefined })
|
choiceA: new ForeignDocumentUUIDArrayField({type: 'Item', required: false}),
|
||||||
),
|
choiceB: new ForeignDocumentUUIDArrayField({type: 'Item', required: false}),
|
||||||
choiceA: new fields.ArrayField(
|
|
||||||
new ForeignDocumentUUIDField({ type: 'Item', required: false, nullable: true, initial: undefined })
|
|
||||||
),
|
|
||||||
choiceB: new fields.ArrayField(
|
|
||||||
new ForeignDocumentUUIDField({ type: 'Item', required: false, nullable: true, initial: undefined })
|
|
||||||
)
|
|
||||||
}),
|
}),
|
||||||
characterGuide: new fields.SchemaField({
|
characterGuide: new fields.SchemaField({
|
||||||
suggestedTraits: new fields.SchemaField({
|
suggestedTraits: new fields.SchemaField({
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
import ActionField from '../fields/actionField.mjs';
|
import ActionField from '../fields/actionField.mjs';
|
||||||
import ForeignDocumentUUIDField from '../fields/foreignDocumentUUIDField.mjs';
|
import ForeignDocumentUUIDArrayField from '../fields/foreignDocumentUUIDArrayField.mjs';
|
||||||
import BaseDataItem from './base.mjs';
|
import BaseDataItem from './base.mjs';
|
||||||
|
|
||||||
const featureSchema = () => {
|
const featureSchema = () => {
|
||||||
return new foundry.data.fields.SchemaField({
|
return new foundry.data.fields.SchemaField({
|
||||||
name: new foundry.data.fields.StringField({ required: true }),
|
name: new foundry.data.fields.StringField({ required: true }),
|
||||||
effects: new foundry.data.fields.ArrayField(new ForeignDocumentUUIDField({ type: 'ActiveEffect' })),
|
effects: new ForeignDocumentUUIDArrayField({type: 'Item', required: false}),
|
||||||
actions: new foundry.data.fields.ArrayField(new ActionField())
|
actions: new foundry.data.fields.ArrayField(new ActionField())
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue