mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-18 07:59:03 +01:00
Added use of ItemLinkFields
This commit is contained in:
parent
8cdad5172e
commit
569e567dfd
18 changed files with 232 additions and 288 deletions
|
|
@ -23,15 +23,17 @@ export default class ForeignDocumentUUIDField extends foundry.data.fields.Docume
|
|||
/**@override */
|
||||
initialize(value, _model, _options = {}) {
|
||||
if (this.idOnly) return value;
|
||||
return () => {
|
||||
try {
|
||||
const doc = fromUuidSync(value);
|
||||
return doc;
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return value ?? null;
|
||||
}
|
||||
};
|
||||
return () => ForeignDocumentUUIDField.getInitializedField(value);
|
||||
}
|
||||
|
||||
static getInitializedField(value) {
|
||||
try {
|
||||
const doc = fromUuidSync(value);
|
||||
return doc;
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return value ?? null;
|
||||
}
|
||||
}
|
||||
|
||||
/**@override */
|
||||
|
|
|
|||
19
module/data/fields/itemLinkFields.mjs
Normal file
19
module/data/fields/itemLinkFields.mjs
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import ForeignDocumentUUIDField from './foreignDocumentUUIDField.mjs';
|
||||
|
||||
export default class ItemLinkFields extends foundry.data.fields.ArrayField {
|
||||
constructor(options, context) {
|
||||
super(new ItemLinkField(), options, context);
|
||||
}
|
||||
}
|
||||
|
||||
class ItemLinkField extends foundry.data.fields.SchemaField {
|
||||
constructor(context) {
|
||||
super(
|
||||
{
|
||||
type: new foundry.data.fields.StringField({ choices: CONFIG.DH.ITEM.featureSubTypes, nullable: true }),
|
||||
item: new ForeignDocumentUUIDField({ type: 'Item' })
|
||||
},
|
||||
context
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue