mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-06-08 13:48:11 +02:00
REFACTOR:make more legible _preCreate
This commit is contained in:
parent
fe864f402a
commit
7785dea7fa
1 changed files with 20 additions and 15 deletions
|
|
@ -55,23 +55,28 @@ export default class BaseDataItem extends foundry.abstract.TypeDataModel {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**@inheritdoc */
|
||||||
async _preCreate(data, options, user) {
|
async _preCreate(data, options, user) {
|
||||||
|
// Skip if no initial action is required or actions already exist
|
||||||
if (!this.constructor.metadata.hasInitialAction || !foundry.utils.isEmpty(this.actions)) return;
|
if (!this.constructor.metadata.hasInitialAction || !foundry.utils.isEmpty(this.actions)) return;
|
||||||
const actionType = {
|
|
||||||
weapon: 'attack'
|
const metadataType = this.constructor.metadata.type;
|
||||||
}[this.constructor.metadata.type],
|
const actionType = { weapon: "attack" }[metadataType];
|
||||||
cls = actionsTypes[actionType]
|
const ActionClass = actionsTypes[actionType];
|
||||||
action = new cls(
|
|
||||||
{
|
const action = new ActionClass(
|
||||||
_id: foundry.utils.randomID(),
|
{
|
||||||
type: actionType,
|
_id: foundry.utils.randomID(),
|
||||||
name: game.i18n.localize(CONFIG.DH.ACTIONS.actionTypes[actionType].name),
|
type: actionType,
|
||||||
...cls.getSourceConfig(this.parent)
|
name: game.i18n.localize(CONFIG.DH.ACTIONS.actionTypes[actionType].name),
|
||||||
},
|
...ActionClass.getSourceConfig(this.parent)
|
||||||
{
|
},
|
||||||
parent: this.parent
|
{
|
||||||
}
|
parent: this.parent
|
||||||
);
|
}
|
||||||
|
);
|
||||||
|
|
||||||
this.updateSource({ actions: [action] });
|
this.updateSource({ actions: [action] });
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue