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]});
}
}

View file

@ -14,7 +14,8 @@ export default class DHWeapon extends BaseDataItem {
isQuantifiable: true,
embedded: {
feature: 'featureTest'
}
},
hasInitialAction: true
});
}
@ -51,24 +52,6 @@ export default class DHWeapon extends BaseDataItem {
};
}
async _preCreate(data, options, user) {
const actionType = 'attack',
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]});
return super._preCreate(data, options, user);
}
async _preUpdate(changes, options, user) {
const allowed = await super._preUpdate(changes, options, user);
if (allowed === false) return false;