Fixed up dice

This commit is contained in:
WBHarry 2025-07-13 02:49:43 +02:00
parent e37fc83c59
commit 132d9ee6c8
20 changed files with 417 additions and 68 deletions

View file

@ -25,6 +25,8 @@ export default class CharacterSheet extends DHBaseActorSheet {
toggleEquipItem: CharacterSheet.#toggleEquipItem,
useItem: this.useItem, //TODO Fix this
useAction: this.useAction,
toggleResourceDice: this.toggleResourceDice,
handleResourceDice: this.handleResourceDice,
toChat: this.toChat
},
window: {
@ -668,6 +670,45 @@ export default class CharacterSheet extends DHBaseActorSheet {
action.use(event);
}
/**
* Toggle the used state of a resource dice.
* @type {ApplicationClickAction}
*/
static async toggleResourceDice(event) {
const target = event.target.closest('.item-resource');
const item = this.getItem(event);
if (!item) return;
const diceState = item.system.resource.diceStates[target.dataset.dice];
await item.update({
[`system.resource.diceStates.${target.dataset.dice}.used`]: diceState?.used ? !diceState.used : true
});
}
/**
* Handle the roll values of resource dice.
* @type {ApplicationClickAction}
*/
static async handleResourceDice(event) {
const item = this.getItem(event);
if (!item) return;
const rollValues = await game.system.api.applications.dialogs.ResourceDiceDialog.create(
item.name,
this.document.name,
item.system.resource
);
if (!rollValues) return;
await item.update({
'system.resource.diceStates': rollValues.reduce((acc, value, index) => {
acc[index] = { value, used: false };
return acc;
}, {})
});
this.render();
}
/**
* Send item to Chat
* @type {ApplicationClickAction}