Added DestroyOnEmpty property

This commit is contained in:
WBHarry 2025-08-28 09:16:45 +02:00
parent 4dfc18f727
commit 7082cc009f
65 changed files with 87 additions and 20 deletions

View file

@ -1,5 +1,4 @@
import BaseDataItem from './base.mjs';
import { ActionField } from '../fields/actionField.mjs';
export default class DHConsumable extends BaseDataItem {
/** @inheritDoc */
@ -19,7 +18,8 @@ export default class DHConsumable extends BaseDataItem {
const fields = foundry.data.fields;
return {
...super.defineSchema(),
consumeOnUse: new fields.BooleanField({ initial: false })
consumeOnUse: new fields.BooleanField({ initial: true }),
destroyOnEmpty: new fields.BooleanField({ initial: true })
};
}
@ -27,14 +27,4 @@ export default class DHConsumable extends BaseDataItem {
/**@override */
static DEFAULT_ICON = 'systems/daggerheart/assets/icons/documents/items/round-potion.svg';
async _preUpdate(changes, options, userId) {
const allowed = await super._preUpdate(changes, options, userId);
if (allowed === false) return;
if (changes.system?.quantity !== undefined && Number(changes.system.quantity) === 0) {
this.parent.delete();
return;
}
}
}