From 9ff282f308555ba589f9c03e722ec19cd791f7da Mon Sep 17 00:00:00 2001 From: KitCat Date: Wed, 27 Mar 2024 12:00:12 +0000 Subject: [PATCH] Sync spontaneous spell slot usage between actions --- CHANGELOG | 1 + modules/argon/buttons/buttonPanelButton.mjs | 11 +++++++---- modules/argon/buttons/itemButton.mjs | 2 +- modules/argon/panels/accordionPanel.mjs | 18 ++++++++++++++++++ 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index f3d9a0c..6f74a29 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -4,6 +4,7 @@ - Remove disabled spellbooks that contain spells from action bar - Remove spells button from showing up in action section, if no spells are available for that section - Fix subskills not being rollable from drawer panel +- Sync spontaneous spell slot usage between actions ## v0.9.2 - Simplify spell selection if only one spellbook is active diff --git a/modules/argon/buttons/buttonPanelButton.mjs b/modules/argon/buttons/buttonPanelButton.mjs index d11c3d1..fab396e 100644 --- a/modules/argon/buttons/buttonPanelButton.mjs +++ b/modules/argon/buttons/buttonPanelButton.mjs @@ -260,7 +260,10 @@ export function spellbookButtonPanelActionButton(ARGON) { max: (level && hasSpellUses) ? spellLevelInfo.max : null, value: (level && hasSpellUses) ? spellLevelInfo.value : null }, - buttons: spells.filter(item => item.system.level === level) + buttons: spells.filter(item => item.system.level === level), + spellLevel: level, + spellbookId: this.spellbookId, + isSpellCategory: true }); } @@ -324,9 +327,9 @@ export function spellbookButtonPanelActionButton(ARGON) { return new AccordionPanel({ accordionPanelCategories: this.categories .map(category => new AccordionPanelCategory({ - label: category.label, - uses: category.uses, - buttons: category.buttons.map(item => new ItemButton({item})) + ...category, + buttons: category.buttons.map(item => new ItemButton({item})), + isSpellCategory: true })) }); } diff --git a/modules/argon/buttons/itemButton.mjs b/modules/argon/buttons/itemButton.mjs index c8acaaf..83bc18d 100644 --- a/modules/argon/buttons/itemButton.mjs +++ b/modules/argon/buttons/itemButton.mjs @@ -278,7 +278,7 @@ export function itemButton(ARGON) { } if (this.parent.isAccordionPanelCategory) { - this.parent.use(); + Hooks.callAll("ECHPF1.spellUsed", this.item); } } } diff --git a/modules/argon/panels/accordionPanel.mjs b/modules/argon/panels/accordionPanel.mjs index 289db30..e0813e2 100644 --- a/modules/argon/panels/accordionPanel.mjs +++ b/modules/argon/panels/accordionPanel.mjs @@ -1,3 +1,17 @@ +let spellAccordionPanelCategories = { + "primary": {0: [], 1: [], 2: [], 3: [], 4: [], 5: [], 6: [], 7: [], 8: [], 9: []}, + "secondary": {0: [], 1: [], 2: [], 3: [], 4: [], 5: [], 6: [], 7: [], 8: [], 9: []}, + "tertiary": {0: [], 1: [], 2: [], 3: [], 4: [], 5: [], 6: [], 7: [], 8: [], 9: []}, + "spelllike": {0: [], 1: [], 2: [], 3: [], 4: [], 5: [], 6: [], 7: [], 8: [], 9: []}, +} +Hooks.on("ECHPF1.spellUsed", (item) => { + const categories = spellAccordionPanelCategories[item.system.spellbook][item.system.level]; + categories.map(category => { + category.use(); + }) +}); + + export function accordionPanel(ARGON) { return class Pathfinder1eAccordionPanel extends ARGON.MAIN.BUTTON_PANELS.ACCORDION.AccordionPanel { get actionType() { @@ -31,6 +45,10 @@ export function accordionPanelCategory(ARGON) { constructor(args) { super(args); this.isAccordionPanelCategory = true; + + if (args.isSpellCategory) { + spellAccordionPanelCategories[args.spellbookId][args.spellLevel].push(this); + } } get isUnchained() {