From c01fe515d162e55cb948d4a625c164376cd8aecb Mon Sep 17 00:00:00 2001 From: Zoltan The DM Date: Fri, 17 Nov 2023 13:48:25 -0800 Subject: [PATCH] added a bunch of extra buttons to sheets for easy access to compendium browser --- src/lang/en.json | 5 ++- src/module/compendium-browser.js | 66 ++++++++++++++++++++++++++++++-- 2 files changed, 65 insertions(+), 6 deletions(-) diff --git a/src/lang/en.json b/src/lang/en.json index c2c3122..fb44f1a 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -71,8 +71,9 @@ "MaxLoaded": "(maximum displayed; to see more, use the filters)" }, "ToolTip": { - "Feats": "Open Compendium Browser to feats", - "Spells": "Open Compendium Browser to relevant spells" + "Feats": "Find Feats", + "Spells": "Find Spells", + "Features": "Find Features" }, "Filters.ResetFilters": "Reset Filters" } diff --git a/src/module/compendium-browser.js b/src/module/compendium-browser.js index 28a9910..cf5d80a 100644 --- a/src/module/compendium-browser.js +++ b/src/module/compendium-browser.js @@ -1726,9 +1726,15 @@ class CompendiumBrowser extends Application { } static async addTidySheetButton(cb, html, actor) { + + await CompendiumBrowser.addTidyFeatureButton(html, "race"); + await CompendiumBrowser.addTidyFeatureButton(html, "background"); + await CompendiumBrowser.addTidyFeatureButton(html, "class"); + await html.find(".spell-browser-btn").remove(); let tabBar = html.find("div.tab.spellbook .spellcasting-ability"); + const tooltip = game.i18n.localize("CMPBrowser.ToolTip.Spells"); const cbButton = $( `
@@ -1744,13 +1750,22 @@ class CompendiumBrowser extends Application { } static async addDefaultSheetButton(cb, html, actor) { + if (cb.options.classes.includes("tidy5e")) { + // no need as tidy sheet render will handle it + return; + } + + await CompendiumBrowser.addDefaultFeatureButton(html, "race"); + await CompendiumBrowser.addDefaultFeatureButton(html, "background"); + await CompendiumBrowser.addDefaultFeatureButton(html, "class"); + + // handle spell browser button await html.find(".spell-browser-btn").remove(); let tabBar = html.find("div.spellbook-filters"); - const tooltip = game.i18n.localize("CMPBrowser.ToolTip.Spells"); const cbButton = $( `
- +
` @@ -1774,14 +1789,57 @@ class CompendiumBrowser extends Application { }); } + static async addTidyFeatureButton(html, type) { + const featBars = html.find(`div.features a.item-create[data-type="${type}"]`); + + const tooltip = game.i18n.localize("CMPBrowser.ToolTip.Features"); + const cbButton = $( + ` + + ` + ); + + $(featBars[0].parentNode).append(cbButton); + cbButton.click(async (ev) => { + ev.preventDefault(); + + game.compendiumBrowser.renderWith("feat", [{ section: "CMPBrowsergeneral", label: "CMPBrowser.overall", value: type }]); + }); + } + + static async addDefaultFeatureButton(html, type) { + await html.find(`.${type}-browser-btn`).remove(); + + const featBars = html.find(`div.features li.items-header a.item-control[data-type="${type}"]`); + + // Other sheets (like tidysheet) may cause this problem + if (!featBars.length) { + return; + } + + const cbButton = $( + ` + + ` + ); + + $(featBars[0].parentNode).append(cbButton); + $(featBars[0].parentNode).css({"flex-basis": "60px"}); + + cbButton.click(async (ev) => { + ev.preventDefault(); + + game.compendiumBrowser.renderWith("feat", [{ section: "CMPBrowsergeneral", label: "CMPBrowser.overall", value: type }]); + }); + } + static async addASISheetButton(cb, html) { await html.find(".feat-browser-btn").remove(); let dropArea = html.find("h3:nth-child(3)"); - const tooltip = game.i18n.localize("CMPBrowser.ToolTip.Feats"); const cbButton = $( ` - + `