mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-13 04:01:06 +01:00
First PR
This commit is contained in:
parent
7178148c80
commit
fad34ae975
26 changed files with 688 additions and 371 deletions
|
|
@ -1,11 +1,47 @@
|
|||
import { actionsTypes } from "../action/_module.mjs";
|
||||
|
||||
// Temporary Solution
|
||||
export default class ActionField extends foundry.data.fields.EmbeddedDataField {
|
||||
export default class ActionField extends foundry.data.fields.ObjectField {
|
||||
/** @override */
|
||||
initialize(value, model, options={}) {
|
||||
this.model = actionsTypes[value?.type] ?? actionsTypes.attack;
|
||||
this.fields = this._initialize(this.model.defineSchema());
|
||||
return super.initialize(value, model, options)
|
||||
// initialize(value, model, options={}) {
|
||||
// console.log('initialize', value.type)
|
||||
// this.model = actionsTypes[value?.type] ?? actionsTypes.attack;
|
||||
// this.fields = this._initialize(this.model.defineSchema());
|
||||
// return super.initialize(value, model, options)
|
||||
// }
|
||||
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