mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-12 03:31:07 +01:00
110 - Class Data Model (#111)
* Added PreCreate/Create/Delete logic for Class/Subclass and set it as foreignUUID fields in PC * Moved methods into TypedModelData * Simplified Subclass
This commit is contained in:
parent
53be047e12
commit
746e0f239a
14 changed files with 190 additions and 224 deletions
|
|
@ -3,40 +3,39 @@
|
|||
* that resolves to either the document, the index(for items in compenidums) or the UUID string.
|
||||
*/
|
||||
export default class ForeignDocumentUUIDField extends foundry.data.fields.DocumentUUIDField {
|
||||
/**
|
||||
* @param {foundry.data.types.DocumentUUIDFieldOptions} [options] Options which configure the behavior of the field
|
||||
* @param {foundry.data.types.DataFieldContext} [context] Additional context which describes the field
|
||||
*/
|
||||
constructor(options, context) {
|
||||
super(options, context);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {foundry.data.types.DocumentUUIDFieldOptions} [options] Options which configure the behavior of the field
|
||||
* @param {foundry.data.types.DataFieldContext} [context] Additional context which describes the field
|
||||
*/
|
||||
constructor(options, context) {
|
||||
super(options, context);
|
||||
}
|
||||
/** @inheritdoc */
|
||||
static get _defaults() {
|
||||
return foundry.utils.mergeObject(super._defaults, {
|
||||
nullable: true,
|
||||
readonly: false,
|
||||
idOnly: false
|
||||
});
|
||||
}
|
||||
|
||||
/** @inheritdoc */
|
||||
static get _defaults() {
|
||||
return foundry.utils.mergeObject(super._defaults, {
|
||||
nullable: true,
|
||||
readonly: false,
|
||||
idOnly: false,
|
||||
});
|
||||
}
|
||||
/**@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;
|
||||
}
|
||||
})();
|
||||
}
|
||||
|
||||
/**@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;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**@override */
|
||||
toObject(value) {
|
||||
return value?.uuid ?? value;
|
||||
}
|
||||
/**@override */
|
||||
toObject(value) {
|
||||
return value?.uuid ?? value;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue