daggerheart/module/data/fields/actionField.mjs
Dapoulp 52be430eff
Feature/247 auto add yope fear clear stress (#285)
* cleanup

* test

* Step 1

* #2

* Fix Effect Action & Add Hope tumation settings to hook

* remove circular dependency

* Snuck in some localization fixes I noticed

* Remove success condition for duality roll gain

* Changed config.roll.type logic

---------

Co-authored-by: WBHarry <williambjrklund@gmail.com>
2025-07-07 01:38:39 +02:00

37 lines
1.2 KiB
JavaScript

export default class ActionField extends foundry.data.fields.ObjectField {
getModel(value) {
return game.system.api.models.actions.actionsTypes[value.type] ?? game.system.api.models.actions.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);
}
}