From d417d2887a9b5381532ecebeabe218081f3f5be5 Mon Sep 17 00:00:00 2001 From: Zoltan The DM Date: Fri, 17 Nov 2023 10:16:56 -0800 Subject: [PATCH 1/9] fixed issue with renderWith not working --- src/lang/en.json | 4 ++++ src/module/compendium-browser.js | 21 +++++++++++++++------ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/lang/en.json b/src/lang/en.json index bd52d3e..c2c3122 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -70,6 +70,10 @@ }, "MaxLoaded": "(maximum displayed; to see more, use the filters)" }, + "ToolTip": { + "Feats": "Open Compendium Browser to feats", + "Spells": "Open Compendium Browser to relevant spells" + }, "Filters.ResetFilters": "Reset Filters" } } diff --git a/src/module/compendium-browser.js b/src/module/compendium-browser.js index c481524..0c17cef 100644 --- a/src/module/compendium-browser.js +++ b/src/module/compendium-browser.js @@ -1625,12 +1625,12 @@ class CompendiumBrowser extends Application { if (filter.type in typeMap) { let component = html.element.find( - `div.tab.active #${input.section}-${input.label} ${typeMap[filter.type]}` + `${this.getHtmlStringFromInput(input)} ${typeMap[filter.type]}` ); component[0].value = input.value; } else if (filter.type === "multiSelect") { - let components = html.element.find(`div.tab.active #${input.section}-${input.label}`); + let components = html.element.find(this.getHtmlStringFromInput(input)); for (let v of input.values) { let c = components.find(`input[data-value=${v}]`); @@ -1647,6 +1647,10 @@ class CompendiumBrowser extends Application { return this; } + getHtmlStringFromInput(input) { + return `div.tab.active #${input.section}-${stripDotCharacters(input.label)}`; + } + findFilter(type, category, label) { let target = `${type}Filters`; let catId = stripSpecialCharacters(category); @@ -1655,7 +1659,9 @@ class CompendiumBrowser extends Application { return; } - let filter = this[target].registeredFilterCategorys[catId].filters.find((x) => x.labelId === label); + const labelStripped = stripDotCharacters(label); + + let filter = this[target].registeredFilterCategorys[catId].filters.find((x) => x.labelId === labelStripped); if (!filter) { return; @@ -1720,9 +1726,10 @@ class CompendiumBrowser extends Application { await html.find(".spell-browser-btn").remove(); let tabBar = html.find("div.tab.spellbook .spellcasting-ability"); + const tooltip = game.i18n.localize("CMPBrowser.ToolTip.Spells") ?? "CMPBrowser.ToolTip.Spells"; const cbButton = $( `
- +
` @@ -1737,9 +1744,10 @@ class CompendiumBrowser extends Application { await html.find(".spell-browser-btn").remove(); let tabBar = html.find("div.spellbook-filters"); + const tooltip = game.i18n.localize("CMPBrowser.ToolTip.Spells") ?? "CMPBrowser.ToolTip.Spells"; const cbButton = $( `
- +
` @@ -1767,9 +1775,10 @@ class CompendiumBrowser extends Application { await html.find(".feat-browser-btn").remove(); let dropArea = html.find("h3:nth-child(3)"); + const tooltip = game.i18n.localize("CMPBrowser.ToolTip.Feats") ?? "CMPBrowser.ToolTip.Feats"; const cbButton = $( ` - + ` From 52f1bfa089410349424cfc21f9ec54706cdf39ae Mon Sep 17 00:00:00 2001 From: Zoltan The DM Date: Fri, 17 Nov 2023 10:29:26 -0800 Subject: [PATCH 2/9] added race to the list of filterables --- src/module/compendium-browser.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/module/compendium-browser.js b/src/module/compendium-browser.js index 0c17cef..28a9910 100644 --- a/src/module/compendium-browser.js +++ b/src/module/compendium-browser.js @@ -384,6 +384,8 @@ class CompendiumBrowser extends Application { // 0.4.1: Load and filter just one of spells, feats, and items (specified by browserTab) let numItemsLoaded = 0; let compactItems = {}; + const FeatureList = ["feat", "class", "subclass", "background", "race"]; + const NotItemList = ["spell", "feat", "class", "subclass", "background", "race"]; try { // Filter the full list, but only save the core compendium information + displayed info @@ -452,7 +454,7 @@ class CompendiumBrowser extends Application { if ( decoratedItem - && ["feat", "class", "subclass", "background"].includes(decoratedItem.type) + && FeatureList.includes(decoratedItem.type) && this.passesFilter(decoratedItem, this.featFilters.activeFilters) ) { itemsList[item5e.id] = { @@ -485,7 +487,7 @@ class CompendiumBrowser extends Application { if ( decoratedItem - && !["spell", "feat", "class", "subclass", "background"].includes( + && !NotItemList.includes( decoratedItem.type ) && this.passesFilter(decoratedItem, this.itemFilters.activeFilters) @@ -1407,6 +1409,7 @@ class CompendiumBrowser extends Application { feat: "ITEM.TypeFeat", subclass: "ITEM.TypeSubclass", background: "DND5E.Background", + race: "DND5E.Race", }), false ); @@ -1726,7 +1729,7 @@ class CompendiumBrowser extends Application { await html.find(".spell-browser-btn").remove(); let tabBar = html.find("div.tab.spellbook .spellcasting-ability"); - const tooltip = game.i18n.localize("CMPBrowser.ToolTip.Spells") ?? "CMPBrowser.ToolTip.Spells"; + const tooltip = game.i18n.localize("CMPBrowser.ToolTip.Spells"); const cbButton = $( `
@@ -1744,7 +1747,7 @@ class CompendiumBrowser extends Application { await html.find(".spell-browser-btn").remove(); let tabBar = html.find("div.spellbook-filters"); - const tooltip = game.i18n.localize("CMPBrowser.ToolTip.Spells") ?? "CMPBrowser.ToolTip.Spells"; + const tooltip = game.i18n.localize("CMPBrowser.ToolTip.Spells"); const cbButton = $( `
@@ -1775,7 +1778,7 @@ class CompendiumBrowser extends Application { await html.find(".feat-browser-btn").remove(); let dropArea = html.find("h3:nth-child(3)"); - const tooltip = game.i18n.localize("CMPBrowser.ToolTip.Feats") ?? "CMPBrowser.ToolTip.Feats"; + const tooltip = game.i18n.localize("CMPBrowser.ToolTip.Feats"); const cbButton = $( ` From c01fe515d162e55cb948d4a625c164376cd8aecb Mon Sep 17 00:00:00 2001 From: Zoltan The DM Date: Fri, 17 Nov 2023 13:48:25 -0800 Subject: [PATCH 3/9] 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 = $( ` - + ` From 8043efcf4ac974e059262be9d94ec11630cbac65 Mon Sep 17 00:00:00 2001 From: Zoltan The DM Date: Fri, 17 Nov 2023 14:28:06 -0800 Subject: [PATCH 4/9] added options to the config --- src/lang/en.json | 8 +++- src/module/compendium-browser.js | 63 +++++++++++++++++++++++++++++--- 2 files changed, 64 insertions(+), 7 deletions(-) diff --git a/src/lang/en.json b/src/lang/en.json index fb44f1a..03f9744 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -56,7 +56,13 @@ }, "SETTING": { "Maxload.NAME": "Maximum load", - "Maxload.HINT": "Maximum number of spells, feats, items, or NPCs to display; to see more use the filters. This setting is to allow manageing memory and server load." + "Maxload.HINT": "Maximum number of spells, feats, items, or NPCs to display; to see more use the filters. This setting is to allow manageing memory and server load.", + "extraButtonsGlobal.NAME": "Globally Enable Buttons", + "extraButtonsGlobal.HINT": "Globally enable shortcut buttons to the browser that are added to sheets (Must re-open window for it to apply)", + "extraSheetButtons.NAME": "Enable Extra Sheet Buttons", + "extraSheetButtons.HINT": "Enable extra shortcut buttons that appear on PC sheets (Must re-open window for it to apply)", + "extraAdvancementButtons.NAME": "Enable Extra Advancement Buttons", + "extraAdvancementButtons.HINT": "Enable extra shortcut buttons that appear on advancement windows (Must re-open window for it to apply)" }, "LOADING": { "Message": "Loading..." diff --git a/src/module/compendium-browser.js b/src/module/compendium-browser.js index cf5d80a..fa7cb99 100644 --- a/src/module/compendium-browser.js +++ b/src/module/compendium-browser.js @@ -4,13 +4,14 @@ import { registerSettings } from "./settings.js"; const STOP_SEARCH = "StopSearchException"; const NOT_MIGRATED = "NotMigratedException"; +const COMPENDIUM_BROWSER = "compendium-browser"; class CompendiumBrowser extends Application { static get defaultOptions() { return mergeObject(super.defaultOptions, { title: "CMPBrowser.compendiumBrowser", tabs: [{ navSelector: ".tabs", contentSelector: ".content", initial: "spell" }], - classes: ["compendium-browser"], + classes: [COMPENDIUM_BROWSER], template: "modules/compendium-browser/templates/template.html", width: 800, height: 730, @@ -19,7 +20,19 @@ class CompendiumBrowser extends Application { } get maxLoad() { - return game.settings.get("compendium-browser", "maxload"); + return game.settings.get(COMPENDIUM_BROWSER, "maxload"); + } + + static get extraButtonsGlobal() { + return game.settings.get(COMPENDIUM_BROWSER, "extraButtonsGlobal"); + } + + static get extraSheetButtons() { + return game.settings.get(COMPENDIUM_BROWSER, "extraSheetButtons"); + } + + static get extraAdvancementButtons() { + return game.settings.get(COMPENDIUM_BROWSER, "extraAdvancementButtons"); } async setup() { @@ -230,7 +243,7 @@ class CompendiumBrowser extends Application { } else if (setting === "allow-npc-browser") { this.settings.allowNpcBrowser = value; } - game.settings.set("compendium-browser", "settings", this.settings); + game.settings.set(COMPENDIUM_BROWSER, "settings", this.settings); }); // activating or deactivating filters @@ -1135,7 +1148,7 @@ class CompendiumBrowser extends Application { } } // creating game setting container - game.settings.register("compendium-browser", "settings", { + game.settings.register(COMPENDIUM_BROWSER, "settings", { name: "Compendium Browser Settings", hint: "Settings to exclude packs from loading and visibility of the browser", default: defaultSettings, @@ -1145,7 +1158,7 @@ class CompendiumBrowser extends Application { this.settings = settings; }, }); - game.settings.register("compendium-browser", "maxload", { + game.settings.register(COMPENDIUM_BROWSER, "maxload", { name: game.i18n.localize("CMPBrowser.SETTING.Maxload.NAME"), hint: game.i18n.localize("CMPBrowser.SETTING.Maxload.HINT"), scope: "world", @@ -1159,9 +1172,33 @@ class CompendiumBrowser extends Application { step: 100, }, }); + game.settings.register(COMPENDIUM_BROWSER, "extraButtonsGlobal", { + name: game.i18n.localize("CMPBrowser.SETTING.extraButtonsGlobal.NAME"), + hint: game.i18n.localize("CMPBrowser.SETTING.extraButtonsGlobal.HINT"), + scope: "world", + config: true, + default: true, + type: Boolean, + }); + game.settings.register(COMPENDIUM_BROWSER, "extraSheetButtons", { + name: game.i18n.localize("CMPBrowser.SETTING.extraSheetButtons.NAME"), + hint: game.i18n.localize("CMPBrowser.SETTING.extraSheetButtons.HINT"), + scope: "client", + config: true, + default: true, + type: Boolean, + }); + game.settings.register(COMPENDIUM_BROWSER, "extraAdvancementButtons", { + name: game.i18n.localize("CMPBrowser.SETTING.extraAdvancementButtons.NAME"), + hint: game.i18n.localize("CMPBrowser.SETTING.extraAdvancementButtons.HINT"), + scope: "client", + config: true, + default: true, + type: Boolean, + }); // load settings from container and apply to default settings (available compendie might have changed) - let settings = game.settings.get("compendium-browser", "settings"); + let settings = game.settings.get(COMPENDIUM_BROWSER, "settings"); for (let compKey in defaultSettings.loadedSpellCompendium) { // v0.7.1 Check for settings.loadedSpellCompendium if (settings.loadedSpellCompendium && settings.loadedSpellCompendium[compKey] !== undefined) { @@ -1726,6 +1763,10 @@ class CompendiumBrowser extends Application { } static async addTidySheetButton(cb, html, actor) { + // exit out because we dont want these + if (!CompendiumBrowser.extraButtonsGlobal || !CompendiumBrowser.extraSheetButtons) { + return; + } await CompendiumBrowser.addTidyFeatureButton(html, "race"); await CompendiumBrowser.addTidyFeatureButton(html, "background"); @@ -1750,6 +1791,11 @@ class CompendiumBrowser extends Application { } static async addDefaultSheetButton(cb, html, actor) { + // exit out because we dont want these + if (!CompendiumBrowser.extraButtonsGlobal || !CompendiumBrowser.extraSheetButtons) { + return; + } + if (cb.options.classes.includes("tidy5e")) { // no need as tidy sheet render will handle it return; @@ -1834,6 +1880,11 @@ class CompendiumBrowser extends Application { } static async addASISheetButton(cb, html) { + // exit out because we dont want these + if (!CompendiumBrowser.extraButtonsGlobal || !CompendiumBrowser.extraAdvancementButtons) { + return; + } + await html.find(".feat-browser-btn").remove(); let dropArea = html.find("h3:nth-child(3)"); From a54239a4f5a82e936775fcc9103eb27e146cdecc Mon Sep 17 00:00:00 2001 From: Zoltan The DM Date: Wed, 29 Nov 2023 16:50:23 -0800 Subject: [PATCH 5/9] Adds a new clickable banner when missing --- src/module/compendium-browser.js | 34 ++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/module/compendium-browser.js b/src/module/compendium-browser.js index fa7cb99..65e615c 100644 --- a/src/module/compendium-browser.js +++ b/src/module/compendium-browser.js @@ -1768,6 +1768,40 @@ class CompendiumBrowser extends Application { return; } + let MAP_THING = {}; + MAP_THING[game.i18n.localize("DND5E.Race")] = "race"; + MAP_THING[game.i18n.localize("DND5E.Background")] = "background"; + MAP_THING[game.i18n.localize("DND5E.Class")] = "class"; + + function isSearchable(name){ + return name == game.i18n.localize("DND5E.Race") || + name == game.i18n.localize("DND5E.Background") || + name == game.i18n.localize("DND5E.Class"); + } + + console.log(html.find(".inventory-list.features-list .item-list").filter(function (){ + return isSearchable($(this.previousElementSibling).find("h3.item-name")[0].innerText) && + $(this).find("li.item").length == 0; + })); + + html.find(".inventory-list.features-list .item-list").filter(function (){ + //find any section that is searchable + return isSearchable($(this.previousElementSibling).find("h3.item-name")[0].innerText) && + //find any section that is empty + $(this).find("li.item").length == 0; + }).each( function(){ + let type = MAP_THING[$(this.previousElementSibling).find("h3.item-name")[0].innerText] + let banner = $(`${game.i18n.localize(`CMPBrowser.FindA.${type}`)}`) + + banner.insertAfter(this); + + banner.click(async (ev) => { + ev.preventDefault(); + + game.compendiumBrowser.renderWith("feat", [{ section: "CMPBrowsergeneral", label: "CMPBrowser.overall", value: type }]); + }); + }); + await CompendiumBrowser.addTidyFeatureButton(html, "race"); await CompendiumBrowser.addTidyFeatureButton(html, "background"); await CompendiumBrowser.addTidyFeatureButton(html, "class"); From 2f0f01b5a9aaf64cc401209c5dfd4025d99f13f4 Mon Sep 17 00:00:00 2001 From: Zoltan The DM Date: Thu, 30 Nov 2023 15:08:20 -0800 Subject: [PATCH 6/9] adds some nice clickable banners in case there are missing sections in the TidySheets --- src/lang/en.json | 11 +++- src/module/compendium-browser.js | 101 ++++++++++++++++++++----------- 2 files changed, 77 insertions(+), 35 deletions(-) diff --git a/src/lang/en.json b/src/lang/en.json index 03f9744..ff64cf3 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -62,7 +62,11 @@ "extraSheetButtons.NAME": "Enable Extra Sheet Buttons", "extraSheetButtons.HINT": "Enable extra shortcut buttons that appear on PC sheets (Must re-open window for it to apply)", "extraAdvancementButtons.NAME": "Enable Extra Advancement Buttons", - "extraAdvancementButtons.HINT": "Enable extra shortcut buttons that appear on advancement windows (Must re-open window for it to apply)" + "extraAdvancementButtons.HINT": "Enable extra shortcut buttons that appear on advancement windows (Must re-open window for it to apply)", + "bannersGlobal.NAME": "Enable Banners - Global", + "bannersGlobal.HINT": "Enable Banners for missing key features on PC sheets for all players", + "bannersLocal.NAME": "Enable Banners - Local", + "bannersLocal.HINT": "Enable Banners for missing key features on PC sheets for self" }, "LOADING": { "Message": "Loading..." @@ -81,6 +85,11 @@ "Spells": "Find Spells", "Features": "Find Features" }, + "FindA": { + "race": "Missing a Race, click to open list", + "background": "Missing a Background, click to open list", + "class": "Missing a Class, click to open list" + }, "Filters.ResetFilters": "Reset Filters" } } diff --git a/src/module/compendium-browser.js b/src/module/compendium-browser.js index 65e615c..fde66f6 100644 --- a/src/module/compendium-browser.js +++ b/src/module/compendium-browser.js @@ -35,6 +35,14 @@ class CompendiumBrowser extends Application { return game.settings.get(COMPENDIUM_BROWSER, "extraAdvancementButtons"); } + static get bannersGlobal() { + return game.settings.get(COMPENDIUM_BROWSER, "bannersGlobal"); + } + + static get bannersLocal() { + return game.settings.get(COMPENDIUM_BROWSER, "bannersLocal"); + } + async setup() { // load settings this.initSettings(); @@ -1196,6 +1204,22 @@ class CompendiumBrowser extends Application { default: true, type: Boolean, }); + game.settings.register(COMPENDIUM_BROWSER, "bannersGlobal", { + name: game.i18n.localize("CMPBrowser.SETTING.bannersGlobal.NAME"), + hint: game.i18n.localize("CMPBrowser.SETTING.bannersGlobal.HINT"), + scope: "world", + config: true, + default: true, + type: Boolean, + }); + game.settings.register(COMPENDIUM_BROWSER, "bannersLocal", { + name: game.i18n.localize("CMPBrowser.SETTING.bannersLocal.NAME"), + hint: game.i18n.localize("CMPBrowser.SETTING.bannersLocal.HINT"), + scope: "client", + config: true, + default: true, + type: Boolean, + }); // load settings from container and apply to default settings (available compendie might have changed) let settings = game.settings.get(COMPENDIUM_BROWSER, "settings"); @@ -1763,45 +1787,17 @@ class CompendiumBrowser extends Application { } static async addTidySheetButton(cb, html, actor) { + await CompendiumBrowser.createBanners(html); + await CompendiumBrowser.addButtons(html, actor); + } + + static async addButtons(html, actor) { + // exit out because we dont want these if (!CompendiumBrowser.extraButtonsGlobal || !CompendiumBrowser.extraSheetButtons) { return; } - let MAP_THING = {}; - MAP_THING[game.i18n.localize("DND5E.Race")] = "race"; - MAP_THING[game.i18n.localize("DND5E.Background")] = "background"; - MAP_THING[game.i18n.localize("DND5E.Class")] = "class"; - - function isSearchable(name){ - return name == game.i18n.localize("DND5E.Race") || - name == game.i18n.localize("DND5E.Background") || - name == game.i18n.localize("DND5E.Class"); - } - - console.log(html.find(".inventory-list.features-list .item-list").filter(function (){ - return isSearchable($(this.previousElementSibling).find("h3.item-name")[0].innerText) && - $(this).find("li.item").length == 0; - })); - - html.find(".inventory-list.features-list .item-list").filter(function (){ - //find any section that is searchable - return isSearchable($(this.previousElementSibling).find("h3.item-name")[0].innerText) && - //find any section that is empty - $(this).find("li.item").length == 0; - }).each( function(){ - let type = MAP_THING[$(this.previousElementSibling).find("h3.item-name")[0].innerText] - let banner = $(`${game.i18n.localize(`CMPBrowser.FindA.${type}`)}`) - - banner.insertAfter(this); - - banner.click(async (ev) => { - ev.preventDefault(); - - game.compendiumBrowser.renderWith("feat", [{ section: "CMPBrowsergeneral", label: "CMPBrowser.overall", value: type }]); - }); - }); - await CompendiumBrowser.addTidyFeatureButton(html, "race"); await CompendiumBrowser.addTidyFeatureButton(html, "background"); await CompendiumBrowser.addTidyFeatureButton(html, "class"); @@ -1824,6 +1820,43 @@ class CompendiumBrowser extends Application { CompendiumBrowser.addSpellsButton(cbButton, actor.actor); } + static async createBanners(html) { + // Don't build the banners if configuration is turned off + if (!CompendiumBrowser.bannersGlobal() || CompendiumBrowser.bannersLocal()) { + return; + } + + let MAP_THING = {}; + MAP_THING[game.i18n.localize("DND5E.Race")] = "race"; + MAP_THING[game.i18n.localize("DND5E.Background")] = "background"; + MAP_THING[game.i18n.localize("ITEM.TypeClassPl")] = "class"; + + let isSearchable = (name) => { + return Object.keys(MAP_THING).includes(name); + }; + + //searches in a similar way to how tidy sheets does it. + //probably should just use actor data instead of going through the html + html.find(".inventory-list.features-list .item-list").filter(function () { + // find any section that is searchable + return isSearchable($(this.previousElementSibling).find("h3.item-name")[0].innerText) + // find any section that is empty + && $(this).find("li.item").length === 0; + }).each( function () { + let type = MAP_THING[$(this.previousElementSibling).find("h3.item-name")[0].innerText]; + let banner = $(`${game.i18n.localize(`CMPBrowser.FindA.${type}`)}`); + + banner.insertAfter(this); + + banner.click(async (ev) => { + ev.preventDefault(); + + game.compendiumBrowser.renderWith("feat", [{ section: "CMPBrowsergeneral", label: "CMPBrowser.overall", value: type }]); + }); + }); + + } + static async addDefaultSheetButton(cb, html, actor) { // exit out because we dont want these if (!CompendiumBrowser.extraButtonsGlobal || !CompendiumBrowser.extraSheetButtons) { From 7efe782bc644dd5586dc695fb88da13a259e45a1 Mon Sep 17 00:00:00 2001 From: Zoltan The DM Date: Thu, 30 Nov 2023 15:15:54 -0800 Subject: [PATCH 7/9] big oops on using getter functions --- src/module/compendium-browser.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/module/compendium-browser.js b/src/module/compendium-browser.js index fde66f6..83e4e3b 100644 --- a/src/module/compendium-browser.js +++ b/src/module/compendium-browser.js @@ -1822,7 +1822,7 @@ class CompendiumBrowser extends Application { static async createBanners(html) { // Don't build the banners if configuration is turned off - if (!CompendiumBrowser.bannersGlobal() || CompendiumBrowser.bannersLocal()) { + if (!CompendiumBrowser.bannersGlobal || CompendiumBrowser.bannersLocal) { return; } From 59bf58eac9363d4bde647602d60622ac0ee6ebbb Mon Sep 17 00:00:00 2001 From: Zoltan The DM Date: Thu, 30 Nov 2023 15:20:23 -0800 Subject: [PATCH 8/9] don't you hate it when you forget one character? --- src/module/compendium-browser.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/module/compendium-browser.js b/src/module/compendium-browser.js index 83e4e3b..ea59acb 100644 --- a/src/module/compendium-browser.js +++ b/src/module/compendium-browser.js @@ -1822,7 +1822,7 @@ class CompendiumBrowser extends Application { static async createBanners(html) { // Don't build the banners if configuration is turned off - if (!CompendiumBrowser.bannersGlobal || CompendiumBrowser.bannersLocal) { + if (!CompendiumBrowser.bannersGlobal || !CompendiumBrowser.bannersLocal) { return; } From df7168f49cca6d814a8c6ccbcd3c4bbab76f0ea9 Mon Sep 17 00:00:00 2001 From: Zoltan The DM Date: Wed, 6 Dec 2023 17:56:39 -0800 Subject: [PATCH 9/9] fixed lint error --- src/module/compendium-browser.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/module/compendium-browser.js b/src/module/compendium-browser.js index ea59acb..d728335 100644 --- a/src/module/compendium-browser.js +++ b/src/module/compendium-browser.js @@ -1835,8 +1835,8 @@ class CompendiumBrowser extends Application { return Object.keys(MAP_THING).includes(name); }; - //searches in a similar way to how tidy sheets does it. - //probably should just use actor data instead of going through the html + // searches in a similar way to how tidy sheets does it. + // probably should just use actor data instead of going through the html html.find(".inventory-list.features-list .item-list").filter(function () { // find any section that is searchable return isSearchable($(this.previousElementSibling).find("h3.item-name")[0].innerText)