mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-13 20:21:06 +01:00
Merged with data-models-structure branch
This commit is contained in:
commit
d1c968d0a2
62 changed files with 1760 additions and 956 deletions
40
module/data/fields/actionField.mjs
Normal file
40
module/data/fields/actionField.mjs
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
import { actionsTypes } from '../action/_module.mjs';
|
||||
|
||||
// Temporary Solution
|
||||
export default class ActionField extends foundry.data.fields.ObjectField {
|
||||
getModel(value) {
|
||||
return actionsTypes[value.type] ?? actionsTypes.attack;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
||||
/** @override */
|
||||
_cleanType(value, options) {
|
||||
if (!(typeof value === 'object')) value = {};
|
||||
|
||||
const cls = this.getModel(value);
|
||||
if (cls) return cls.cleanData(value, options);
|
||||
return value;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
||||
/** @override */
|
||||
initialize(value, model, options = {}) {
|
||||
const cls = this.getModel(value);
|
||||
if (cls) return new cls(value, { parent: model, ...options });
|
||||
return foundry.utils.deepClone(value);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Migrate this field's candidate source data.
|
||||
* @param {object} sourceData Candidate source data of the root model.
|
||||
* @param {any} fieldData The value of this field within the source data.
|
||||
*/
|
||||
migrateSource(sourceData, fieldData) {
|
||||
const cls = this.getModel(fieldData);
|
||||
if (cls) cls.migrateDataSafe(fieldData);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue