From 2f0f01b5a9aaf64cc401209c5dfd4025d99f13f4 Mon Sep 17 00:00:00 2001 From: Zoltan The DM Date: Thu, 30 Nov 2023 15:08:20 -0800 Subject: [PATCH] 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) {