Few fixes

This commit is contained in:
Dapoolp 2025-06-25 12:01:23 +02:00
parent 1bd2bbd02d
commit aacaf516b2
8 changed files with 50 additions and 39 deletions

View file

@ -1,3 +1,5 @@
import { actionsTypes } from '../action/_module.mjs';
/**
* Describes metadata about the item data model type
* @typedef {Object} ItemDataModelMetadata
@ -50,4 +52,24 @@ export default class BaseDataItem extends foundry.abstract.TypeDataModel {
const data = { ...actorRollData, item: { ...this } };
return data;
}
async _preCreate(data, options, user) {
if(!this.constructor.metadata.hasInitialAction || !foundry.utils.isEmpty(this.actions)) return;
const actionType = {
weapon: 'attack'
}[this.constructor.metadata.type],
cls = actionsTypes.attack,
action = new cls(
{
_id: foundry.utils.randomID(),
type: actionType,
name: game.i18n.localize(SYSTEM.ACTIONS.actionTypes[actionType].name),
...cls.getSourceConfig(this.parent)
},
{
parent: this.parent
}
);
this.updateSource({actions: [action]});
}
}