From 21399d984e4dd14c0f5359d80a637c6c8ef28028 Mon Sep 17 00:00:00 2001 From: Daimakaicho Date: Wed, 14 Jul 2021 23:59:53 +0200 Subject: [PATCH 01/20] hide multiplier if quantity is 1 --- scripts/brt-main.js | 5 +++++ templates/loot-chat-card.hbs | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/scripts/brt-main.js b/scripts/brt-main.js index ed7855c1..740cb3cc 100644 --- a/scripts/brt-main.js +++ b/scripts/brt-main.js @@ -17,6 +17,11 @@ Hooks.once("init", () => { return options.inverse(this); }); + /** checks if the first argument is greater than the second argument */ + Handlebars.registerHelper('ifgt', function (v1, v2, options) { + return v1 > v2 ? options.fn(this) : options.inverse(this); + }); + registerSettings(); game.betterTables = new BetterTables(); }); diff --git a/templates/loot-chat-card.hbs b/templates/loot-chat-card.hbs index 68055ba8..99140e94 100644 --- a/templates/loot-chat-card.hbs +++ b/templates/loot-chat-card.hbs @@ -20,7 +20,7 @@ {{/if}} data-id="{{itemData.item.id}}"> {{itemData.item.name}} -   × {{itemData.quantity}} + {{#ifgt itemData.quantity 1 }}  × {{itemData.quantity}}{{/ifgt}} {{/each}} From 026a5fe0015bcbfcc3cff5b52630b0864754cf1d Mon Sep 17 00:00:00 2001 From: Daimakaicho Date: Thu, 15 Jul 2021 00:00:27 +0200 Subject: [PATCH 02/20] use css to avoid one useless tag --- templates/loot-chat-card.hbs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/templates/loot-chat-card.hbs b/templates/loot-chat-card.hbs index 99140e94..02e85b8c 100644 --- a/templates/loot-chat-card.hbs +++ b/templates/loot-chat-card.hbs @@ -3,9 +3,7 @@
{{tableData.description}}
{{/if}} {{#if currency}} -
- {{localize 'BRT.Currency'}} {{currency}} -
+
{{localize 'BRT.Currency'}}{{currency}}
{{/if}}
    From 8612bd789b8332d5422849a3abaebde3f3fd5bcf Mon Sep 17 00:00:00 2001 From: Daimakaicho Date: Thu, 15 Jul 2021 00:01:55 +0200 Subject: [PATCH 03/20] split card data generation with card creation to allow reuse + add pack and rolltable id to template --- scripts/loot/loot-chat-card.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/scripts/loot/loot-chat-card.js b/scripts/loot/loot-chat-card.js index 876d07d1..465ebdac 100644 --- a/scripts/loot/loot-chat-card.js +++ b/scripts/loot/loot-chat-card.js @@ -78,7 +78,7 @@ export class LootChatCard { return this.historyFolder; } - async createChatCard(table) { + async prepareCharCart(table) { await this.findOrCreateItems(); let currencyString = ""; @@ -90,7 +90,9 @@ export class LootChatCard { const chatCardData = { tableData: table.data, itemsData: this.itemsData, - currency: currencyString + currency: currencyString, + compendium: table.pack, + id: table.id }; const cardHtml = await renderTemplate("modules/better-rolltables/templates/loot-chat-card.hbs", chatCardData); @@ -104,13 +106,16 @@ export class LootChatCard { flavorString = game.i18n.format('BRT.DrawResultZero', { name: table.data.name }); } - let chatData = { + return { flavor: flavorString, sound: "sounds/dice.wav", user: game.user.data._id, content: cardHtml }; + } + async createChatCard(table) { + const chatData = await this.prepareCharCart(table); addRollModeToChatData(chatData); ChatMessage.create(chatData); } From 726c87d87243c7ee028b079a353b6f4b1d2d664a Mon Sep 17 00:00:00 2001 From: Daimakaicho Date: Thu, 15 Jul 2021 00:02:10 +0200 Subject: [PATCH 04/20] add a reroll button on card --- templates/loot-chat-card.hbs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/templates/loot-chat-card.hbs b/templates/loot-chat-card.hbs index 02e85b8c..6bf97771 100644 --- a/templates/loot-chat-card.hbs +++ b/templates/loot-chat-card.hbs @@ -23,4 +23,10 @@ {{/each}}
+ +
+ +
\ No newline at end of file From b6a85af1e8bbd220bd286c2c79d83cbea5088e6c Mon Sep 17 00:00:00 2001 From: Daimakaicho Date: Thu, 15 Jul 2021 00:03:14 +0200 Subject: [PATCH 05/20] split rolling on compendium for better reuse --- scripts/better-tables.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/scripts/better-tables.js b/scripts/better-tables.js index 9745f1bc..421ac3ad 100644 --- a/scripts/better-tables.js +++ b/scripts/better-tables.js @@ -220,27 +220,37 @@ export class BetterTables { } /** - * - * @param {String} compendium ID of the compendium to roll + * Create card content from compendium content + * @param {String} compendium compendium name + * @returns {Promise<{flavor: string, sound: string, user: *, content: *}>} */ - static async menuCallBackRollCompendium(compendium) { + static async rollCompendiumAsRolltable(compendium) { // Get random item from compendium const item = await getRandomItemFromCompendium(compendium); // prepare card data const fontSize = Math.max(60, 100 - Math.max(0, item.name.length - 27) * 2); const chatCardData = { + compendium: compendium, itemsData: [ { item: item, quantity: 1, fontSize: fontSize } ] }; const cardHtml = await renderTemplate("modules/better-rolltables/templates/loot-chat-card.hbs", chatCardData); - const chatData = { + return { flavor: `Rolled from compendium ${item.pack}`, sound: "sounds/dice.wav", user: game.user.data._id, content: cardHtml }; + } + + /** + * + * @param {String} compendium ID of the compendium to roll + */ + static async menuCallBackRollCompendium(compendium) { + const chatData = await BetterTables.rollCompendiumAsRolltable(compendium); ChatMessage.create(chatData); } } \ No newline at end of file From 72b0e393bf2611bdba429a3c040b33553c432781 Mon Sep 17 00:00:00 2001 From: Daimakaicho Date: Thu, 15 Jul 2021 00:03:49 +0200 Subject: [PATCH 06/20] handle reroll buttons on cards --- scripts/better-tables.js | 58 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/scripts/better-tables.js b/scripts/better-tables.js index 421ac3ad..dea7d4cb 100644 --- a/scripts/better-tables.js +++ b/scripts/better-tables.js @@ -253,4 +253,62 @@ export class BetterTables { const chatData = await BetterTables.rollCompendiumAsRolltable(compendium); ChatMessage.create(chatData); } + /** + * Create card content from rolltable + * @param {RollTable} tableEntity rolltable to generate content from + * @returns {Promise<{flavor: *, sound: string, user: *, content: *}>} + */ + static async prepareCardData(tableEntity) { + const brtBuilder = new BRTBuilder(tableEntity); + const results = await brtBuilder.betterRoll(); + + const br = new BetterResults(results); + const betterResults = await br.buildResults(tableEntity); + const currencyData = br.getCurrencyData(); + + const lootChatCard = new LootChatCard(betterResults, currencyData); + return lootChatCard.prepareCharCart(tableEntity); + } + + /** + * Handle Reroll buttons on cards + * @param {ChatMessage} message newly created message + * @param {Object} html message content + * @returns {Promise} + */ + static async handleChatMessageButtons(message, html) { + if (!game.user.isGM) return; + + $(html).find(".brt-card-buttons button").each(async function(index, button) { + const id = $(button).data("id"); + const pack = $(button).data("pack"); + if (!id && !pack) return; + + if (pack && !id) { + $(button) + .click(async () => { + const cardContent = await BetterTables.rollCompendiumAsRolltable(pack); + await message.update({ "content": cardContent.content, "timestamp": Date.now()}); + }) + .removeAttr("style"); + } else { + let rolltable = undefined; + if (pack && id) { + rolltable = await game.packs.get(pack)?.getDocument(id); + } + else { + rolltable = game.tables.get(id); + } + + if (rolltable) { + $(button) + .click(async () => { + const cardContent = await BetterTables.prepareCardData(rolltable); + await message.update({ "content": cardContent.content, "timestamp": Date.now()}); + }) + .removeAttr("style"); + } + } + }); + } } \ No newline at end of file From 83898858b4dabeecba96cb35d053907ccfbc901c Mon Sep 17 00:00:00 2001 From: Daimakaicho Date: Thu, 15 Jul 2021 00:04:35 +0200 Subject: [PATCH 07/20] leverage loot card logic to condensed better table result --- scripts/better-tables.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/scripts/better-tables.js b/scripts/better-tables.js index dea7d4cb..4d589145 100644 --- a/scripts/better-tables.js +++ b/scripts/better-tables.js @@ -99,10 +99,15 @@ export class BetterTables { return await brtBuilder.betterRoll(); } - async betterTableRoll(tableEntity) { + async betterTableRoll(tableEntity, options) { const brtBuilder = new BRTBuilder(tableEntity); const results = await brtBuilder.betterRoll(); - await brtBuilder.createChatCard(results); + + const br = new BetterResults(results); + const betterResults = await br.buildResults(tableEntity); + + const lootChatCard = new LootChatCard(betterResults, undefined); + await lootChatCard.createChatCard(tableEntity); } From ba2e27cab41d0e97a5883b843980f8b5ec76901e Mon Sep 17 00:00:00 2001 From: Daimakaicho Date: Thu, 15 Jul 2021 00:05:08 +0200 Subject: [PATCH 08/20] hook new chat message to add logic to reroll buttons --- scripts/brt-main.js | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/brt-main.js b/scripts/brt-main.js index 740cb3cc..1d7cffe5 100644 --- a/scripts/brt-main.js +++ b/scripts/brt-main.js @@ -44,6 +44,7 @@ Hooks.on("updateCompendium", async function (pack, documents, option, userId) { Hooks.on("renderRollTableConfig", BetterRT.enhanceRollTableView); Hooks.on('getCompendiumDirectoryEntryContext', BetterTables.enhanceCompendiumContextMenu); Hooks.on('getRollTableDirectoryEntryContext', BetterTables.enhanceRolltableContextMenu); +Hooks.on('renderChatMessage', BetterTables.handleChatMessageButtons); function registerSettings() { let defaultLootSheet = "dnd5e.LootSheet5eNPC"; From a373b79ebac2172842cbeb31802a0ea095f53e8a Mon Sep 17 00:00:00 2001 From: Daimakaicho Date: Thu, 15 Jul 2021 00:05:36 +0200 Subject: [PATCH 09/20] update translation files --- lang/de.json | 3 ++- lang/en.json | 3 ++- lang/es-ES.json | 3 ++- lang/fr.json | 3 ++- lang/ko.json | 3 ++- lang/pt-BR.json | 3 ++- scripts/better-tables.js | 1 - 7 files changed, 12 insertions(+), 7 deletions(-) diff --git a/lang/de.json b/lang/de.json index e26d9e5d..c9e33a11 100644 --- a/lang/de.json +++ b/lang/de.json @@ -18,5 +18,6 @@ "BRT.LootRollAmountPlaceholder" : "Mehrfach auf die Tabelle würfeln.", "BRT.DrawResultPlural": "Zieht {amount} Ergebnisse aus {name}", "BRT.DrawResultSingular": "Zieht {amount} Ergebnis aus {name}", - "BRT.DrawResultZero": "Würfle auf {name}" + "BRT.DrawResultZero": "Würfle auf {name}", + "BRT.DrawReroll": "Reroll" } \ No newline at end of file diff --git a/lang/en.json b/lang/en.json index 4ba9666c..524a8de4 100644 --- a/lang/en.json +++ b/lang/en.json @@ -18,5 +18,6 @@ "BRT.LootRollAmountPlaceholder" : "Roll the entire table multiple times", "BRT.DrawResultPlural": "Draws {amount} results from {name}", "BRT.DrawResultSingular": "Draw {amount} result from {name}", - "BRT.DrawResultZero": "Rolling on {name}" + "BRT.DrawResultZero": "Rolling on {name}", + "BRT.DrawReroll": "Reroll" } \ No newline at end of file diff --git a/lang/es-ES.json b/lang/es-ES.json index b48a6eb4..f180ee1c 100644 --- a/lang/es-ES.json +++ b/lang/es-ES.json @@ -18,5 +18,6 @@ "BRT.LootRollAmountPlaceholder" : "Lanzar por la tabla al completo múltiples veces", "BRT.DrawResultPlural": "Obtiene {amount} resultados de {name}", "BRT.DrawResultSingular": "Obtiene {amount} resultado de {name}", - "BRT.DrawResultZero": "Lanzar de {name}" + "BRT.DrawResultZero": "Lanzar de {name}", + "BRT.DrawReroll": "Reroll" } \ No newline at end of file diff --git a/lang/fr.json b/lang/fr.json index 33982b12..e85544b5 100644 --- a/lang/fr.json +++ b/lang/fr.json @@ -18,5 +18,6 @@ "BRT.LootRollAmountPlaceholder" : "Jette un jet sur l'intégralité de la table plusieurs fois", "BRT.DrawResultPlural": "Vous avez tiré {amount} résultats de {name}", "BRT.DrawResultSingular": "Vous avez tiré {amount} résultat de {name}", - "BRT.DrawResultZero": "Tirage sur {name}" + "BRT.DrawResultZero": "Tirage sur {name}", + "BRT.DrawReroll": "Relancer" } \ No newline at end of file diff --git a/lang/ko.json b/lang/ko.json index c86d9e1a..dea5f41c 100644 --- a/lang/ko.json +++ b/lang/ko.json @@ -18,5 +18,6 @@ "BRT.LootRollAmountPlaceholder" : "표 전체를 여러 번 굴림(수식 추가)", "BRT.DrawResultPlural": "{name}의 결과로 선택된 건 {amount}입니다", "BRT.DrawResultSingular": "{name}의 결과로 선택된 건 {amount}입니다", - "BRT.DrawResultZero": "{name}에서 굴림" + "BRT.DrawResultZero": "{name}에서 굴림", + "BRT.DrawReroll": "Reroll" } diff --git a/lang/pt-BR.json b/lang/pt-BR.json index 2551f7dc..0a163f15 100644 --- a/lang/pt-BR.json +++ b/lang/pt-BR.json @@ -18,5 +18,6 @@ "BRT.LootRollAmountPlaceholder" : "Role a tabela inteira várias vezes", "BRT.DrawResultPlural": "Sacar {amount} resultados de {name}", "BRT.DrawResultSingular": "Sacar {amount} resultado de {name}", - "BRT.DrawResultZero": "Rolagem em {name}" + "BRT.DrawResultZero": "Rolagem em {name}", + "BRT.DrawReroll": "Reroll" } diff --git a/scripts/better-tables.js b/scripts/better-tables.js index 4d589145..db503a5a 100644 --- a/scripts/better-tables.js +++ b/scripts/better-tables.js @@ -110,7 +110,6 @@ export class BetterTables { await lootChatCard.createChatCard(tableEntity); } - /** * Create a new RollTable by extracting entries from a compendium. * From da76f79a5b7fe4ea28b8f5aefe853b028783fb4b Mon Sep 17 00:00:00 2001 From: Daimakaicho Date: Thu, 15 Jul 2021 00:15:55 +0200 Subject: [PATCH 10/20] add settings to disable Reroll butons on card --- scripts/better-tables.js | 2 +- scripts/brt-main.js | 8 ++++++++ scripts/core/config.js | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/scripts/better-tables.js b/scripts/better-tables.js index db503a5a..0b9965d6 100644 --- a/scripts/better-tables.js +++ b/scripts/better-tables.js @@ -281,7 +281,7 @@ export class BetterTables { * @returns {Promise} */ static async handleChatMessageButtons(message, html) { - if (!game.user.isGM) return; + if (!game.user.isGM || !game.settings.get(BRTCONFIG.NAMESPACE, BRTCONFIG.SHOW_REROLL_BUTTONS)) return; $(html).find(".brt-card-buttons button").each(async function(index, button) { const id = $(button).data("id"); diff --git a/scripts/brt-main.js b/scripts/brt-main.js index 1d7cffe5..df9b732e 100644 --- a/scripts/brt-main.js +++ b/scripts/brt-main.js @@ -77,6 +77,14 @@ function registerSettings() { default: defaultSpellCompendium, type: String }); + + game.settings.register(BRTCONFIG.NAMESPACE, BRTCONFIG.SHOW_REROLL_BUTTONS, { + name: i18n("BRT.Settings.RerollButtons.Title"), + hint: i18n("BRT.Settings.RerollButtons.Description"), + config: true, + default: false, + type: Boolean + }); } diff --git a/scripts/core/config.js b/scripts/core/config.js index 28c92828..9f0d822d 100644 --- a/scripts/core/config.js +++ b/scripts/core/config.js @@ -16,6 +16,7 @@ BRTCONFIG.TABLE_TYPE_STORY = "story"; BRTCONFIG.SPELL_COMPENDIUM_KEY = "default-spell-compendium"; BRTCONFIG.LOOT_SHEET_TO_USE_KEY = "loot-sheet-to-use"; +BRTCONFIG.SHOW_REROLL_BUTTONS = "show-reroll-buttons"; //in fp2e quantity is in data.data.quantity.value , in 5e data.data.quantity BRTCONFIG.QUANTITY_PROPERTY_PATH = "data.quantity"; From cd6f558c8a44d663ffec6691ad3440feaebee731 Mon Sep 17 00:00:00 2001 From: Daimakaicho Date: Thu, 15 Jul 2021 00:16:09 +0200 Subject: [PATCH 11/20] update translation files --- lang/de.json | 4 +++- lang/en.json | 7 +++++-- lang/es-ES.json | 4 +++- lang/fr.json | 4 +++- lang/ko.json | 4 +++- lang/pt-BR.json | 4 +++- 6 files changed, 20 insertions(+), 7 deletions(-) diff --git a/lang/de.json b/lang/de.json index c9e33a11..89f0d1cc 100644 --- a/lang/de.json +++ b/lang/de.json @@ -19,5 +19,7 @@ "BRT.DrawResultPlural": "Zieht {amount} Ergebnisse aus {name}", "BRT.DrawResultSingular": "Zieht {amount} Ergebnis aus {name}", "BRT.DrawResultZero": "Würfle auf {name}", - "BRT.DrawReroll": "Reroll" + "BRT.DrawReroll": "Reroll", + "BRT.Settings.RerollButtons.Title":"Show reroll buttons", + "BRT.Settings.RerollButtons.Description":"Display a Reroll button on each result card of a roll on a rolltable (only for newly created cards)" } \ No newline at end of file diff --git a/lang/en.json b/lang/en.json index 524a8de4..206fc5a6 100644 --- a/lang/en.json +++ b/lang/en.json @@ -19,5 +19,8 @@ "BRT.DrawResultPlural": "Draws {amount} results from {name}", "BRT.DrawResultSingular": "Draw {amount} result from {name}", "BRT.DrawResultZero": "Rolling on {name}", - "BRT.DrawReroll": "Reroll" -} \ No newline at end of file + "BRT.DrawReroll": "Reroll", + "BRT.Settings.RerollButtons.Title":"Show Reroll buttons", + "BRT.Settings.RerollButtons.Description":"Display a Reroll button on each result card of a roll on a rolltable (only for newly created cards)" +} + diff --git a/lang/es-ES.json b/lang/es-ES.json index f180ee1c..c5ae4407 100644 --- a/lang/es-ES.json +++ b/lang/es-ES.json @@ -19,5 +19,7 @@ "BRT.DrawResultPlural": "Obtiene {amount} resultados de {name}", "BRT.DrawResultSingular": "Obtiene {amount} resultado de {name}", "BRT.DrawResultZero": "Lanzar de {name}", - "BRT.DrawReroll": "Reroll" + "BRT.DrawReroll": "Reroll", + "BRT.Settings.RerollButtons.Title":"Show reroll buttons", + "BRT.Settings.RerollButtons.Description":"Display a Reroll button on each result card of a roll on a rolltable (only for newly created cards)" } \ No newline at end of file diff --git a/lang/fr.json b/lang/fr.json index e85544b5..08acb3a2 100644 --- a/lang/fr.json +++ b/lang/fr.json @@ -19,5 +19,7 @@ "BRT.DrawResultPlural": "Vous avez tiré {amount} résultats de {name}", "BRT.DrawResultSingular": "Vous avez tiré {amount} résultat de {name}", "BRT.DrawResultZero": "Tirage sur {name}", - "BRT.DrawReroll": "Relancer" + "BRT.DrawReroll": "Relancer", + "BRT.Settings.RerollButtons.Title":"Afficher les boutons pour relancer", + "BRT.Settings.RerollButtons.Description": "Affiche un bouton Relancer sur chaque message de résultat d'un jet sur une table (uniquement pour les nouveaux messages)" } \ No newline at end of file diff --git a/lang/ko.json b/lang/ko.json index dea5f41c..68c82b8d 100644 --- a/lang/ko.json +++ b/lang/ko.json @@ -19,5 +19,7 @@ "BRT.DrawResultPlural": "{name}의 결과로 선택된 건 {amount}입니다", "BRT.DrawResultSingular": "{name}의 결과로 선택된 건 {amount}입니다", "BRT.DrawResultZero": "{name}에서 굴림", - "BRT.DrawReroll": "Reroll" + "BRT.DrawReroll": "Reroll", + "BRT.Settings.RerollButtons.Title":"Show reroll buttons", + "BRT.Settings.RerollButtons.Description":"Display a Reroll button on each result card of a roll on a rolltable (only for newly created cards)" } diff --git a/lang/pt-BR.json b/lang/pt-BR.json index 0a163f15..0b998212 100644 --- a/lang/pt-BR.json +++ b/lang/pt-BR.json @@ -19,5 +19,7 @@ "BRT.DrawResultPlural": "Sacar {amount} resultados de {name}", "BRT.DrawResultSingular": "Sacar {amount} resultado de {name}", "BRT.DrawResultZero": "Rolagem em {name}", - "BRT.DrawReroll": "Reroll" + "BRT.DrawReroll": "Reroll", + "BRT.Settings.RerollButtons.Title":"Show reroll buttons", + "BRT.Settings.RerollButtons.Description":"Display a Reroll button on each result card of a roll on a rolltable (only for newly created cards)" } From b57182624d24d22df6fa14eeb41dca8444ae8f27 Mon Sep 17 00:00:00 2001 From: Daimakaicho Date: Thu, 15 Jul 2021 08:12:56 +0200 Subject: [PATCH 12/20] add settings to toggle new features + rework reroll button visual --- lang/de.json | 14 ++++- lang/en.json | 15 ++++- lang/es-ES.json | 14 ++++- lang/fr.json | 12 +++- lang/ko.json | 14 ++++- lang/pt-BR.json | 14 ++++- scripts/better-tables.js | 117 +++++++++++++++++++++-------------- scripts/brt-main.js | 32 ++++++++++ scripts/core/config.js | 4 ++ styles/brt.css | 5 ++ templates/loot-chat-card.hbs | 13 ++-- 11 files changed, 187 insertions(+), 67 deletions(-) diff --git a/lang/de.json b/lang/de.json index 89f0d1cc..eab12635 100644 --- a/lang/de.json +++ b/lang/de.json @@ -20,6 +20,16 @@ "BRT.DrawResultSingular": "Zieht {amount} Ergebnis aus {name}", "BRT.DrawResultZero": "Würfle auf {name}", "BRT.DrawReroll": "Reroll", - "BRT.Settings.RerollButtons.Title":"Show reroll buttons", - "BRT.Settings.RerollButtons.Description":"Display a Reroll button on each result card of a roll on a rolltable (only for newly created cards)" + "BRT.Settings.RerollButtons.Title": "Show Reroll buttons", + "BRT.Settings.RerollButtons.Description": "Display a Reroll button on each result card of a roll on a rolltable (only for newly created cards). Work only on loot chat card or if condensed roll output is enabled. Default tables are not affected.", + "BRT.Settings.ShowWarningBeforeReroll.Title": "Confirm reroll ?", + "BRT.Settings.ShowWarningBeforeReroll.Description": "Show a confirm dialog before reroll message content.", + "BRT.Settings.UseCondensedBetterRoll.Title": "Use condensed roll output", + "BRT.Settings.UseCondensedBetterRoll.Description": "If enabled, this will aggregate same output with a multiplier to save space. This option may speed up rolltable draws. Default tables are not affected.", + "BRT.Settings.AddRollInRolltableContextMenu.Title": "Roll from rolltable contextmenu", + "BRT.Settings.AddRollInRolltableContextMenu.Description": "Add an option in rolltable's contextmenu to roll table without opening it. Work on all table type.", + "BRT.Settings.AddRollInCompediumContextMenu.Title": "Roll from compendium contextmenu", + "BRT.Settings.AddRollInCompediumContextMenu.Description": "Add an option in compendium's contextmenu to roll on this compendium without creating rolltable from it. Work on all non-empty compendiums.", + "BRT.Settings.RerollWarning.Title": "Reroll?", + "BRT.Settings.RerollWarning.Description": "Message content will be lost. Are you sure you want to reroll?" } \ No newline at end of file diff --git a/lang/en.json b/lang/en.json index 206fc5a6..fa359b2f 100644 --- a/lang/en.json +++ b/lang/en.json @@ -20,7 +20,16 @@ "BRT.DrawResultSingular": "Draw {amount} result from {name}", "BRT.DrawResultZero": "Rolling on {name}", "BRT.DrawReroll": "Reroll", - "BRT.Settings.RerollButtons.Title":"Show Reroll buttons", - "BRT.Settings.RerollButtons.Description":"Display a Reroll button on each result card of a roll on a rolltable (only for newly created cards)" + "BRT.Settings.RerollButtons.Title": "Show Reroll buttons", + "BRT.Settings.RerollButtons.Description": "Display a Reroll button on each result card of a roll on a rolltable (only for newly created cards). Work only on loot chat card or if condensed roll output is enabled. Default tables are not affected.", + "BRT.Settings.ShowWarningBeforeReroll.Title": "Confirm reroll ?", + "BRT.Settings.ShowWarningBeforeReroll.Description": "Show a confirm dialog before reroll message content.", + "BRT.Settings.UseCondensedBetterRoll.Title": "Use condensed roll output", + "BRT.Settings.UseCondensedBetterRoll.Description": "If enabled, this will aggregate same output with a multiplier to save space. This option may speed up rolltable draws. Default tables are not affected.", + "BRT.Settings.AddRollInRolltableContextMenu.Title": "Roll from rolltable contextmenu", + "BRT.Settings.AddRollInRolltableContextMenu.Description": "Add an option in rolltable's contextmenu to roll table without opening it. Work on all table type.", + "BRT.Settings.AddRollInCompediumContextMenu.Title": "Roll from compendium contextmenu", + "BRT.Settings.AddRollInCompediumContextMenu.Description": "Add an option in compendium's contextmenu to roll on this compendium without creating rolltable from it. Work on all non-empty compendiums.", + "BRT.Settings.RerollWarning.Title": "Reroll?", + "BRT.Settings.RerollWarning.Description": "Message content will be lost. Are you sure you want to reroll?" } - diff --git a/lang/es-ES.json b/lang/es-ES.json index c5ae4407..99e6bd03 100644 --- a/lang/es-ES.json +++ b/lang/es-ES.json @@ -20,6 +20,16 @@ "BRT.DrawResultSingular": "Obtiene {amount} resultado de {name}", "BRT.DrawResultZero": "Lanzar de {name}", "BRT.DrawReroll": "Reroll", - "BRT.Settings.RerollButtons.Title":"Show reroll buttons", - "BRT.Settings.RerollButtons.Description":"Display a Reroll button on each result card of a roll on a rolltable (only for newly created cards)" + "BRT.Settings.RerollButtons.Title": "Show Reroll buttons", + "BRT.Settings.RerollButtons.Description": "Display a Reroll button on each result card of a roll on a rolltable (only for newly created cards). Work only on loot chat card or if condensed roll output is enabled. Default tables are not affected.", + "BRT.Settings.ShowWarningBeforeReroll.Title": "Confirm reroll ?", + "BRT.Settings.ShowWarningBeforeReroll.Description": "Show a confirm dialog before reroll message content.", + "BRT.Settings.UseCondensedBetterRoll.Title": "Use condensed roll output", + "BRT.Settings.UseCondensedBetterRoll.Description": "If enabled, this will aggregate same output with a multiplier to save space. This option may speed up rolltable draws. Default tables are not affected.", + "BRT.Settings.AddRollInRolltableContextMenu.Title": "Roll from rolltable contextmenu", + "BRT.Settings.AddRollInRolltableContextMenu.Description": "Add an option in rolltable's contextmenu to roll table without opening it. Work on all table type.", + "BRT.Settings.AddRollInCompediumContextMenu.Title": "Roll from compendium contextmenu", + "BRT.Settings.AddRollInCompediumContextMenu.Description": "Add an option in compendium's contextmenu to roll on this compendium without creating rolltable from it. Work on all non-empty compendiums.", + "BRT.Settings.RerollWarning.Title": "Reroll?", + "BRT.Settings.RerollWarning.Description": "Message content will be lost. Are you sure you want to reroll?" } \ No newline at end of file diff --git a/lang/fr.json b/lang/fr.json index 08acb3a2..96a669e1 100644 --- a/lang/fr.json +++ b/lang/fr.json @@ -21,5 +21,15 @@ "BRT.DrawResultZero": "Tirage sur {name}", "BRT.DrawReroll": "Relancer", "BRT.Settings.RerollButtons.Title":"Afficher les boutons pour relancer", - "BRT.Settings.RerollButtons.Description": "Affiche un bouton Relancer sur chaque message de résultat d'un jet sur une table (uniquement pour les nouveaux messages)" + "BRT.Settings.RerollButtons.Description": "Affiche un bouton Relancer sur chaque message de résultat d'un jet sur une table (uniquement pour les nouveaux messages). Ne fonctionne que sur les tables de type Loot ou si les résultats sont condensés. Les tables par défaut ne sont pas affectées.", + "BRT.Settings.ShowWarningBeforeReroll.Title": "Confirmer la relance ?", + "BRT.Settings.ShowWarningBeforeReroll.Description": "Demande une confirmation avant de relancer le contenu d'un message.", + "BRT.Settings.UseCondensedBetterRoll.Title": "Condenser les résultats", + "BRT.Settings.UseCondensedBetterRoll.Description": "Si activé, les éléments identiques d'un résultat seront aggrégés avec un multiplicateur pour gagner de l'espace. Cette option peut accélérer le tirage aléatoire sur une table. Les tables par défaut ne sont pas affectées.", + "BRT.Settings.AddRollInRolltableContextMenu.Title": "Lancer depuis le menu contextuel d'une table", + "BRT.Settings.AddRollInRolltableContextMenu.Description": "Ajoute une option pour lancer un jet sur une table sans avoir à l'ouvrir. Fonctionne sur tous les types de tables.", + "BRT.Settings.AddRollInCompediumContextMenu.Title": "Lancer depuis le menu contextuel d'un compendium", + "BRT.Settings.AddRollInCompediumContextMenu.Description": "Ajoute une option pour lancer un jet sur un compendium sans avoir à créer une table à partir de son contenu. Fonctionne sur tous les compendiums non vides.", + "BRT.Settings.RerollWarning.Title": "Relancer ?", + "BRT.Settings.RerollWarning.Description": "Le contenu du message sera perdu. Êtes-vous sûr(e) de vouloir relancer ?" } \ No newline at end of file diff --git a/lang/ko.json b/lang/ko.json index 68c82b8d..345c9633 100644 --- a/lang/ko.json +++ b/lang/ko.json @@ -20,6 +20,16 @@ "BRT.DrawResultSingular": "{name}의 결과로 선택된 건 {amount}입니다", "BRT.DrawResultZero": "{name}에서 굴림", "BRT.DrawReroll": "Reroll", - "BRT.Settings.RerollButtons.Title":"Show reroll buttons", - "BRT.Settings.RerollButtons.Description":"Display a Reroll button on each result card of a roll on a rolltable (only for newly created cards)" + "BRT.Settings.RerollButtons.Title": "Show Reroll buttons", + "BRT.Settings.RerollButtons.Description": "Display a Reroll button on each result card of a roll on a rolltable (only for newly created cards). Work only on loot chat card or if condensed roll output is enabled. Default tables are not affected.", + "BRT.Settings.ShowWarningBeforeReroll.Title": "Confirm reroll ?", + "BRT.Settings.ShowWarningBeforeReroll.Description": "Show a confirm dialog before reroll message content.", + "BRT.Settings.UseCondensedBetterRoll.Title": "Use condensed roll output", + "BRT.Settings.UseCondensedBetterRoll.Description": "If enabled, this will aggregate same output with a multiplier to save space. This option may speed up rolltable draws. Default tables are not affected.", + "BRT.Settings.AddRollInRolltableContextMenu.Title": "Roll from rolltable contextmenu", + "BRT.Settings.AddRollInRolltableContextMenu.Description": "Add an option in rolltable's contextmenu to roll table without opening it. Work on all table type.", + "BRT.Settings.AddRollInCompediumContextMenu.Title": "Roll from compendium contextmenu", + "BRT.Settings.AddRollInCompediumContextMenu.Description": "Add an option in compendium's contextmenu to roll on this compendium without creating rolltable from it. Work on all non-empty compendiums.", + "BRT.Settings.RerollWarning.Title": "Reroll?", + "BRT.Settings.RerollWarning.Description": "Message content will be lost. Are you sure you want to reroll?" } diff --git a/lang/pt-BR.json b/lang/pt-BR.json index 0b998212..4a554776 100644 --- a/lang/pt-BR.json +++ b/lang/pt-BR.json @@ -20,6 +20,16 @@ "BRT.DrawResultSingular": "Sacar {amount} resultado de {name}", "BRT.DrawResultZero": "Rolagem em {name}", "BRT.DrawReroll": "Reroll", - "BRT.Settings.RerollButtons.Title":"Show reroll buttons", - "BRT.Settings.RerollButtons.Description":"Display a Reroll button on each result card of a roll on a rolltable (only for newly created cards)" + "BRT.Settings.RerollButtons.Title": "Show Reroll buttons", + "BRT.Settings.RerollButtons.Description": "Display a Reroll button on each result card of a roll on a rolltable (only for newly created cards). Work only on loot chat card or if condensed roll output is enabled. Default tables are not affected.", + "BRT.Settings.ShowWarningBeforeReroll.Title": "Confirm reroll ?", + "BRT.Settings.ShowWarningBeforeReroll.Description": "Show a confirm dialog before reroll message content.", + "BRT.Settings.UseCondensedBetterRoll.Title": "Use condensed roll output", + "BRT.Settings.UseCondensedBetterRoll.Description": "If enabled, this will aggregate same output with a multiplier to save space. This option may speed up rolltable draws. Default tables are not affected.", + "BRT.Settings.AddRollInRolltableContextMenu.Title": "Roll from rolltable contextmenu", + "BRT.Settings.AddRollInRolltableContextMenu.Description": "Add an option in rolltable's contextmenu to roll table without opening it. Work on all table type.", + "BRT.Settings.AddRollInCompediumContextMenu.Title": "Roll from compendium contextmenu", + "BRT.Settings.AddRollInCompediumContextMenu.Description": "Add an option in compendium's contextmenu to roll on this compendium without creating rolltable from it. Work on all non-empty compendiums.", + "BRT.Settings.RerollWarning.Title": "Reroll?", + "BRT.Settings.RerollWarning.Description": "Message content will be lost. Are you sure you want to reroll?" } diff --git a/scripts/better-tables.js b/scripts/better-tables.js index 0b9965d6..2a407ad6 100644 --- a/scripts/better-tables.js +++ b/scripts/better-tables.js @@ -99,15 +99,19 @@ export class BetterTables { return await brtBuilder.betterRoll(); } - async betterTableRoll(tableEntity, options) { + async betterTableRoll(tableEntity) { const brtBuilder = new BRTBuilder(tableEntity); const results = await brtBuilder.betterRoll(); - const br = new BetterResults(results); - const betterResults = await br.buildResults(tableEntity); + if (game.settings.get(BRTCONFIG.NAMESPACE, BRTCONFIG.USE_CONDENSED_BETTERROLL)) { + const br = new BetterResults(results); + const betterResults = await br.buildResults(tableEntity); - const lootChatCard = new LootChatCard(betterResults, undefined); - await lootChatCard.createChatCard(tableEntity); + const lootChatCard = new LootChatCard(betterResults, undefined); + await lootChatCard.createChatCard(tableEntity); + } else { + await brtBuilder.createChatCard(results); + } } /** @@ -182,13 +186,16 @@ export class BetterTables { } }); - options.push({ - "name": "Roll on compendium", - "icon": '', - "callback": li => { - BetterTables.menuCallBackRollCompendium(li.data('pack')); - } - }); + if (game.settings.get(BRTCONFIG.NAMESPACE, BRTCONFIG.ADD_ROLL_IN_COMPENDIUM_CONTEXTMENU)) + { + options.push({ + "name": "Roll on compendium", + "icon": '', + "callback": li => { + BetterTables.menuCallBackRollCompendium(li.data('pack')); + } + }); + } } /** @@ -205,13 +212,15 @@ export class BetterTables { * @param {Array} options */ static async enhanceRolltableContextMenu(html, options) { - options.push({ - "name": "Roll table", - "icon": '', - "callback": li => { - BetterTables.menuCallBackRollTable(li.data("entityId")); - } - }); + if (game.settings.get(BRTCONFIG.NAMESPACE, BRTCONFIG.ADD_ROLL_IN_ROLLTABLE_CONTEXTMENU)) { + options.push({ + "name": "Roll table", + "icon": '', + "callback": li => { + BetterTables.menuCallBackRollTable(li.data("entityId")); + } + }); + } } /** @@ -283,36 +292,48 @@ export class BetterTables { static async handleChatMessageButtons(message, html) { if (!game.user.isGM || !game.settings.get(BRTCONFIG.NAMESPACE, BRTCONFIG.SHOW_REROLL_BUTTONS)) return; - $(html).find(".brt-card-buttons button").each(async function(index, button) { - const id = $(button).data("id"); - const pack = $(button).data("pack"); - if (!id && !pack) return; - - if (pack && !id) { - $(button) - .click(async () => { - const cardContent = await BetterTables.rollCompendiumAsRolltable(pack); - await message.update({ "content": cardContent.content, "timestamp": Date.now()}); - }) - .removeAttr("style"); - } else { - let rolltable = undefined; - if (pack && id) { - rolltable = await game.packs.get(pack)?.getDocument(id); - } - else { - rolltable = game.tables.get(id); - } + const tableDrawNode = $(html).find(".table-draw"); + const id = $(tableDrawNode).data("id"); + const pack = $(tableDrawNode).data("pack"); + if (!id && !pack) return; - if (rolltable) { - $(button) - .click(async () => { - const cardContent = await BetterTables.prepareCardData(rolltable); - await message.update({ "content": cardContent.content, "timestamp": Date.now()}); - }) - .removeAttr("style"); - } + let rerollButton = $(``).append(""); + let cardContent = undefined; + + if (pack && !id) { + cardContent = await BetterTables.rollCompendiumAsRolltable(pack); + } else { + let rolltable = undefined; + if (pack && id) { + rolltable = await game.packs.get(pack)?.getDocument(id); } - }); + else { + rolltable = game.tables.get(id); + } + if (rolltable) { + cardContent = await BetterTables.prepareCardData(rolltable); + } + } + rerollButton.click(async () => BetterTables.updateChatMessage(message, cardContent.content)); + $(html).find(".message-sender").prepend(rerollButton); + } + + /** + * Update a message with a new content + * @param {ChatMessage} message message to update + * @param {String} content new HTML content of message + * @returns {Promise} + */ + static async updateChatMessage(message, content) { + if (game.settings.get(BRTCONFIG.NAMESPACE, BRTCONFIG.SHOW_WARNING_BEFORE_REROLL)) { + Dialog.confirm({ + title: game.i18n.localize("BRT.Settings.RerollWarning.Title"), + content: game.i18n.localize("BRT.Settings.RerollWarning.Description"), + yes: () => message.update({"content": content, "timestamp": Date.now()}), + defaultYes: false + }); + } else { + message.update({"content": content, "timestamp": Date.now()}); + } } } \ No newline at end of file diff --git a/scripts/brt-main.js b/scripts/brt-main.js index df9b732e..167f846b 100644 --- a/scripts/brt-main.js +++ b/scripts/brt-main.js @@ -78,6 +78,14 @@ function registerSettings() { type: String }); + game.settings.register(BRTCONFIG.NAMESPACE, BRTCONFIG.USE_CONDENSED_BETTERROLL, { + name: i18n("BRT.Settings.UseCondensedBetterRoll.Title"), + hint: i18n("BRT.Settings.UseCondensedBetterRoll.Description"), + config: true, + default: false, + type: Boolean + }); + game.settings.register(BRTCONFIG.NAMESPACE, BRTCONFIG.SHOW_REROLL_BUTTONS, { name: i18n("BRT.Settings.RerollButtons.Title"), hint: i18n("BRT.Settings.RerollButtons.Description"), @@ -85,6 +93,30 @@ function registerSettings() { default: false, type: Boolean }); + + game.settings.register(BRTCONFIG.NAMESPACE, BRTCONFIG.SHOW_WARNING_BEFORE_REROLL, { + name: i18n("BRT.Settings.ShowWarningBeforeReroll.Title"), + hint: i18n("BRT.Settings.ShowWarningBeforeReroll.Description"), + config: true, + default: false, + type: Boolean + }); + + game.settings.register(BRTCONFIG.NAMESPACE, BRTCONFIG.ADD_ROLL_IN_ROLLTABLE_CONTEXTMENU, { + name: i18n("BRT.Settings.AddRollInRolltableContextMenu.Title"), + hint: i18n("BRT.Settings.AddRollInRolltableContextMenu.Description"), + config: true, + default: false, + type: Boolean + }); + + game.settings.register(BRTCONFIG.NAMESPACE, BRTCONFIG.ADD_ROLL_IN_COMPENDIUM_CONTEXTMENU, { + name: i18n("BRT.Settings.AddRollInCompediumContextMenu.Title"), + hint: i18n("BRT.Settings.AddRollInCompediumContextMenu.Description"), + config: true, + default: false, + type: Boolean + }); } diff --git a/scripts/core/config.js b/scripts/core/config.js index 9f0d822d..c190ac62 100644 --- a/scripts/core/config.js +++ b/scripts/core/config.js @@ -17,6 +17,10 @@ BRTCONFIG.TABLE_TYPE_STORY = "story"; BRTCONFIG.SPELL_COMPENDIUM_KEY = "default-spell-compendium"; BRTCONFIG.LOOT_SHEET_TO_USE_KEY = "loot-sheet-to-use"; BRTCONFIG.SHOW_REROLL_BUTTONS = "show-reroll-buttons"; +BRTCONFIG.USE_CONDENSED_BETTERROLL = "use-condensed-betterroll"; +BRTCONFIG.ADD_ROLL_IN_COMPENDIUM_CONTEXTMENU = "add-roll-on-compendium-contextmenu"; +BRTCONFIG.ADD_ROLL_IN_ROLLTABLE_CONTEXTMENU = "add-roll-on-rolltable-contextmenu"; +BRTCONFIG.SHOW_WARNING_BEFORE_REROLL = "show-warning-before-reroll"; //in fp2e quantity is in data.data.quantity.value , in 5e data.data.quantity BRTCONFIG.QUANTITY_PROPERTY_PATH = "data.quantity"; diff --git a/styles/brt.css b/styles/brt.css index 6b65783b..5b53ec21 100644 --- a/styles/brt.css +++ b/styles/brt.css @@ -35,4 +35,9 @@ .story-text-selectable * { user-select: text; -moz-user-select: text; +} + +/* Used to display a button to reroll card output */ +.roll-table-reroll-button { + margin-right: 5px; } \ No newline at end of file diff --git a/templates/loot-chat-card.hbs b/templates/loot-chat-card.hbs index 6bf97771..71bccda7 100644 --- a/templates/loot-chat-card.hbs +++ b/templates/loot-chat-card.hbs @@ -1,10 +1,15 @@ -
+
{{#if tableData.description}}
{{tableData.description}}
{{/if}} {{#if currency}}
{{localize 'BRT.Currency'}}{{currency}}
{{/if}} +
+ +
    {{#each itemsData as |itemData|}} @@ -23,10 +28,4 @@ {{/each}}
- -
- -
\ No newline at end of file From 099f32aec63b838b17d148ba7d4da055db714602 Mon Sep 17 00:00:00 2001 From: Daimakaicho Date: Thu, 15 Jul 2021 08:40:45 +0200 Subject: [PATCH 13/20] cleanup template --- templates/loot-chat-card.hbs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/templates/loot-chat-card.hbs b/templates/loot-chat-card.hbs index 71bccda7..1ed56a73 100644 --- a/templates/loot-chat-card.hbs +++ b/templates/loot-chat-card.hbs @@ -5,11 +5,6 @@ {{#if currency}}
{{localize 'BRT.Currency'}}{{currency}}
{{/if}} -
- -
    {{#each itemsData as |itemData|}} From bad882ef047ff31b45f979a3769e8675ab49fa49 Mon Sep 17 00:00:00 2001 From: Daimakaicho Date: Thu, 15 Jul 2021 11:23:19 +0200 Subject: [PATCH 14/20] add option to stick rolltable header on top --- lang/de.json | 4 +++- lang/en.json | 5 ++++- lang/es-ES.json | 4 +++- lang/fr.json | 4 +++- lang/ko.json | 4 +++- lang/pt-BR.json | 4 +++- scripts/better-table-view.js | 7 +++++++ scripts/brt-main.js | 8 ++++++++ scripts/core/config.js | 1 + 9 files changed, 35 insertions(+), 6 deletions(-) diff --git a/lang/de.json b/lang/de.json index eab12635..d905e094 100644 --- a/lang/de.json +++ b/lang/de.json @@ -31,5 +31,7 @@ "BRT.Settings.AddRollInCompediumContextMenu.Title": "Roll from compendium contextmenu", "BRT.Settings.AddRollInCompediumContextMenu.Description": "Add an option in compendium's contextmenu to roll on this compendium without creating rolltable from it. Work on all non-empty compendiums.", "BRT.Settings.RerollWarning.Title": "Reroll?", - "BRT.Settings.RerollWarning.Description": "Message content will be lost. Are you sure you want to reroll?" + "BRT.Settings.RerollWarning.Description": "Message content will be lost. Are you sure you want to reroll?", + "BRT.Settings.StickRolltableHeader.Title": "Stick rolltable header to top?", + "BRT.Settings.StickRolltableHeader.Description": "If enabled, roll table header will no more scroll with content." } \ No newline at end of file diff --git a/lang/en.json b/lang/en.json index fa359b2f..8a4a770d 100644 --- a/lang/en.json +++ b/lang/en.json @@ -31,5 +31,8 @@ "BRT.Settings.AddRollInCompediumContextMenu.Title": "Roll from compendium contextmenu", "BRT.Settings.AddRollInCompediumContextMenu.Description": "Add an option in compendium's contextmenu to roll on this compendium without creating rolltable from it. Work on all non-empty compendiums.", "BRT.Settings.RerollWarning.Title": "Reroll?", - "BRT.Settings.RerollWarning.Description": "Message content will be lost. Are you sure you want to reroll?" + "BRT.Settings.RerollWarning.Description": "Message content will be lost. Are you sure you want to reroll?", + "BRT.Settings.StickRolltableHeader.Title": "Stick rolltable header to top?", + "BRT.Settings.StickRolltableHeader.Description": "If enabled, roll table header will no more scroll with content." + } diff --git a/lang/es-ES.json b/lang/es-ES.json index 99e6bd03..28bd60ab 100644 --- a/lang/es-ES.json +++ b/lang/es-ES.json @@ -31,5 +31,7 @@ "BRT.Settings.AddRollInCompediumContextMenu.Title": "Roll from compendium contextmenu", "BRT.Settings.AddRollInCompediumContextMenu.Description": "Add an option in compendium's contextmenu to roll on this compendium without creating rolltable from it. Work on all non-empty compendiums.", "BRT.Settings.RerollWarning.Title": "Reroll?", - "BRT.Settings.RerollWarning.Description": "Message content will be lost. Are you sure you want to reroll?" + "BRT.Settings.RerollWarning.Description": "Message content will be lost. Are you sure you want to reroll?", + "BRT.Settings.StickRolltableHeader.Title": "Stick rolltable header to top?", + "BRT.Settings.StickRolltableHeader.Description": "If enabled, roll table header will no more scroll with content." } \ No newline at end of file diff --git a/lang/fr.json b/lang/fr.json index 96a669e1..96e62803 100644 --- a/lang/fr.json +++ b/lang/fr.json @@ -31,5 +31,7 @@ "BRT.Settings.AddRollInCompediumContextMenu.Title": "Lancer depuis le menu contextuel d'un compendium", "BRT.Settings.AddRollInCompediumContextMenu.Description": "Ajoute une option pour lancer un jet sur un compendium sans avoir à créer une table à partir de son contenu. Fonctionne sur tous les compendiums non vides.", "BRT.Settings.RerollWarning.Title": "Relancer ?", - "BRT.Settings.RerollWarning.Description": "Le contenu du message sera perdu. Êtes-vous sûr(e) de vouloir relancer ?" + "BRT.Settings.RerollWarning.Description": "Le contenu du message sera perdu. Êtes-vous sûr(e) de vouloir relancer ?", + "BRT.Settings.StickRolltableHeader.Title": "Figer l'entête des tables ?", + "BRT.Settings.StickRolltableHeader.Description": "Fige l'entête de tables afin que celui-ci soit toujours visible." } \ No newline at end of file diff --git a/lang/ko.json b/lang/ko.json index 345c9633..be613a76 100644 --- a/lang/ko.json +++ b/lang/ko.json @@ -31,5 +31,7 @@ "BRT.Settings.AddRollInCompediumContextMenu.Title": "Roll from compendium contextmenu", "BRT.Settings.AddRollInCompediumContextMenu.Description": "Add an option in compendium's contextmenu to roll on this compendium without creating rolltable from it. Work on all non-empty compendiums.", "BRT.Settings.RerollWarning.Title": "Reroll?", - "BRT.Settings.RerollWarning.Description": "Message content will be lost. Are you sure you want to reroll?" + "BRT.Settings.RerollWarning.Description": "Message content will be lost. Are you sure you want to reroll?", + "BRT.Settings.StickRolltableHeader.Title": "Stick rolltable header to top?", + "BRT.Settings.StickRolltableHeader.Description": "If enabled, roll table header will no more scroll with content." } diff --git a/lang/pt-BR.json b/lang/pt-BR.json index 4a554776..7933c5d1 100644 --- a/lang/pt-BR.json +++ b/lang/pt-BR.json @@ -31,5 +31,7 @@ "BRT.Settings.AddRollInCompediumContextMenu.Title": "Roll from compendium contextmenu", "BRT.Settings.AddRollInCompediumContextMenu.Description": "Add an option in compendium's contextmenu to roll on this compendium without creating rolltable from it. Work on all non-empty compendiums.", "BRT.Settings.RerollWarning.Title": "Reroll?", - "BRT.Settings.RerollWarning.Description": "Message content will be lost. Are you sure you want to reroll?" + "BRT.Settings.RerollWarning.Description": "Message content will be lost. Are you sure you want to reroll?", + "BRT.Settings.StickRolltableHeader.Title": "Stick rolltable header to top?", + "BRT.Settings.StickRolltableHeader.Description": "If enabled, roll table header will no more scroll with content." } diff --git a/scripts/better-table-view.js b/scripts/better-table-view.js index 4ca8b4fb..a5f2f359 100644 --- a/scripts/better-table-view.js +++ b/scripts/better-table-view.js @@ -11,6 +11,13 @@ export class BetterRT { let tableViewClass = tableElement.getElementsByClassName(tableClassName)[0]; + if (game.settings.get(BRTCONFIG.NAMESPACE, BRTCONFIG.STICK_ROLLTABLE_HEADER)) { + const header = $(html).find("section.results ol li:first-child"); + // we need to use
      parent to preserve styling + $(html).find("section.results").prepend($('
        ').append(header.clone())); + header.remove(); + } + /** height size increase by type: */ let addHeight = 0; switch (selectedTableType) { diff --git a/scripts/brt-main.js b/scripts/brt-main.js index 167f846b..70183213 100644 --- a/scripts/brt-main.js +++ b/scripts/brt-main.js @@ -117,6 +117,14 @@ function registerSettings() { default: false, type: Boolean }); + + game.settings.register(BRTCONFIG.NAMESPACE, BRTCONFIG.STICK_ROLLTABLE_HEADER, { + name: i18n("BRT.Settings.StickRolltableHeader.Title"), + hint: i18n("BRT.Settings.StickRolltableHeader.Description"), + config: true, + default: false, + type: Boolean + }); } diff --git a/scripts/core/config.js b/scripts/core/config.js index c190ac62..bad8b6be 100644 --- a/scripts/core/config.js +++ b/scripts/core/config.js @@ -21,6 +21,7 @@ BRTCONFIG.USE_CONDENSED_BETTERROLL = "use-condensed-betterroll"; BRTCONFIG.ADD_ROLL_IN_COMPENDIUM_CONTEXTMENU = "add-roll-on-compendium-contextmenu"; BRTCONFIG.ADD_ROLL_IN_ROLLTABLE_CONTEXTMENU = "add-roll-on-rolltable-contextmenu"; BRTCONFIG.SHOW_WARNING_BEFORE_REROLL = "show-warning-before-reroll"; +BRTCONFIG.STICK_ROLLTABLE_HEADER = "stick-rolltable-header"; //in fp2e quantity is in data.data.quantity.value , in 5e data.data.quantity BRTCONFIG.QUANTITY_PROPERTY_PATH = "data.quantity"; From 671193995fb381854e1bf9259e6d882792f1e053 Mon Sep 17 00:00:00 2001 From: Daimakaicho Date: Thu, 15 Jul 2021 13:57:10 +0200 Subject: [PATCH 15/20] add a roll button to linked tables in journal entries --- lang/de.json | 4 +++- lang/en.json | 4 +++- lang/es-ES.json | 4 +++- lang/fr.json | 4 +++- lang/ko.json | 4 +++- lang/pt-BR.json | 4 +++- scripts/better-tables.js | 33 +++++++++++++++++++++++++++++++-- scripts/brt-main.js | 22 +++++++++++++++++++++- scripts/core/config.js | 1 + styles/brt.css | 8 ++++++++ 10 files changed, 79 insertions(+), 9 deletions(-) diff --git a/lang/de.json b/lang/de.json index d905e094..6ab4ed09 100644 --- a/lang/de.json +++ b/lang/de.json @@ -33,5 +33,7 @@ "BRT.Settings.RerollWarning.Title": "Reroll?", "BRT.Settings.RerollWarning.Description": "Message content will be lost. Are you sure you want to reroll?", "BRT.Settings.StickRolltableHeader.Title": "Stick rolltable header to top?", - "BRT.Settings.StickRolltableHeader.Description": "If enabled, roll table header will no more scroll with content." + "BRT.Settings.StickRolltableHeader.Description": "If enabled, roll table header will no more scroll with content.", + "BRT.Settings.RollTableFromJournal.Title": "Add roll button to tables in journal entries?", + "BRT.Settings.RollTableFromJournal.Description": "If enabled, a roll button is added to linked tables in journal entries." } \ No newline at end of file diff --git a/lang/en.json b/lang/en.json index 8a4a770d..1f398f9f 100644 --- a/lang/en.json +++ b/lang/en.json @@ -33,6 +33,8 @@ "BRT.Settings.RerollWarning.Title": "Reroll?", "BRT.Settings.RerollWarning.Description": "Message content will be lost. Are you sure you want to reroll?", "BRT.Settings.StickRolltableHeader.Title": "Stick rolltable header to top?", - "BRT.Settings.StickRolltableHeader.Description": "If enabled, roll table header will no more scroll with content." + "BRT.Settings.StickRolltableHeader.Description": "If enabled, roll table header will no more scroll with content.", + "BRT.Settings.RollTableFromJournal.Title": "Add roll button to tables in journal entries?", + "BRT.Settings.RollTableFromJournal.Description": "If enabled, a roll button is added to linked tables in journal entries." } diff --git a/lang/es-ES.json b/lang/es-ES.json index 28bd60ab..cccf91cb 100644 --- a/lang/es-ES.json +++ b/lang/es-ES.json @@ -33,5 +33,7 @@ "BRT.Settings.RerollWarning.Title": "Reroll?", "BRT.Settings.RerollWarning.Description": "Message content will be lost. Are you sure you want to reroll?", "BRT.Settings.StickRolltableHeader.Title": "Stick rolltable header to top?", - "BRT.Settings.StickRolltableHeader.Description": "If enabled, roll table header will no more scroll with content." + "BRT.Settings.StickRolltableHeader.Description": "If enabled, roll table header will no more scroll with content.", + "BRT.Settings.RollTableFromJournal.Title": "Add roll button to tables in journal entries?", + "BRT.Settings.RollTableFromJournal.Description": "If enabled, a roll button is added to linked tables in journal entries." } \ No newline at end of file diff --git a/lang/fr.json b/lang/fr.json index 96e62803..85464b1b 100644 --- a/lang/fr.json +++ b/lang/fr.json @@ -33,5 +33,7 @@ "BRT.Settings.RerollWarning.Title": "Relancer ?", "BRT.Settings.RerollWarning.Description": "Le contenu du message sera perdu. Êtes-vous sûr(e) de vouloir relancer ?", "BRT.Settings.StickRolltableHeader.Title": "Figer l'entête des tables ?", - "BRT.Settings.StickRolltableHeader.Description": "Fige l'entête de tables afin que celui-ci soit toujours visible." + "BRT.Settings.StickRolltableHeader.Description": "Fige l'entête de tables afin que celui-ci soit toujours visible.", + "BRT.Settings.RollTableFromJournal.Title": "Ajouter un bouton de lancer aux tables dans les journaux ?", + "BRT.Settings.RollTableFromJournal.Description": "Si activé, un bouton pour lancer un tirage sur une table est ajouté aux tables liées dans un journal." } \ No newline at end of file diff --git a/lang/ko.json b/lang/ko.json index be613a76..0cfce974 100644 --- a/lang/ko.json +++ b/lang/ko.json @@ -33,5 +33,7 @@ "BRT.Settings.RerollWarning.Title": "Reroll?", "BRT.Settings.RerollWarning.Description": "Message content will be lost. Are you sure you want to reroll?", "BRT.Settings.StickRolltableHeader.Title": "Stick rolltable header to top?", - "BRT.Settings.StickRolltableHeader.Description": "If enabled, roll table header will no more scroll with content." + "BRT.Settings.StickRolltableHeader.Description": "If enabled, roll table header will no more scroll with content.", + "BRT.Settings.RollTableFromJournal.Title": "Add roll button to tables in journal entries?", + "BRT.Settings.RollTableFromJournal.Description": "If enabled, a roll button is added to linked tables in journal entries." } diff --git a/lang/pt-BR.json b/lang/pt-BR.json index 7933c5d1..ec58b132 100644 --- a/lang/pt-BR.json +++ b/lang/pt-BR.json @@ -33,5 +33,7 @@ "BRT.Settings.RerollWarning.Title": "Reroll?", "BRT.Settings.RerollWarning.Description": "Message content will be lost. Are you sure you want to reroll?", "BRT.Settings.StickRolltableHeader.Title": "Stick rolltable header to top?", - "BRT.Settings.StickRolltableHeader.Description": "If enabled, roll table header will no more scroll with content." + "BRT.Settings.StickRolltableHeader.Description": "If enabled, roll table header will no more scroll with content.", + "BRT.Settings.RollTableFromJournal.Title": "Add roll button to tables in journal entries?", + "BRT.Settings.RollTableFromJournal.Description": "If enabled, a roll button is added to linked tables in journal entries." } diff --git a/scripts/better-tables.js b/scripts/better-tables.js index 2a407ad6..71c014a6 100644 --- a/scripts/better-tables.js +++ b/scripts/better-tables.js @@ -290,8 +290,6 @@ export class BetterTables { * @returns {Promise} */ static async handleChatMessageButtons(message, html) { - if (!game.user.isGM || !game.settings.get(BRTCONFIG.NAMESPACE, BRTCONFIG.SHOW_REROLL_BUTTONS)) return; - const tableDrawNode = $(html).find(".table-draw"); const id = $(tableDrawNode).data("id"); const pack = $(tableDrawNode).data("pack"); @@ -336,4 +334,35 @@ export class BetterTables { message.update({"content": content, "timestamp": Date.now()}); } } + + static async handleRolltableLink(sheet, html, data) { + // handling rolltables imported in campaign + $(html).find("a.entity-link[data-entity='RollTable']").each((index,link) => { + const id = $(link).data("id"); + const rolltable = game.tables.get(id); + + const rollNode = $(``) + .click(async () => { + await game.betterTables.generateChatLoot(rolltable); + }) + $(link).after(rollNode); + }); + + // handling rolltables in compendiums + $(html).find("a.entity-link[data-pack]").each(async (index,link) => { + const pack_name = $(link).data("pack"); + const pack = game.packs.get(pack_name); + if (!pack) return; + + const id = $(link).data("id"); + const document = await pack.getDocument(id); + if (!document || document.documentName !== "RollTable") return; + + const rollNode = $(``) + .click(async () => { + await game.betterTables.generateChatLoot(document); + }) + $(link).after(rollNode); + }); + } } \ No newline at end of file diff --git a/scripts/brt-main.js b/scripts/brt-main.js index 70183213..0ae91fd6 100644 --- a/scripts/brt-main.js +++ b/scripts/brt-main.js @@ -44,7 +44,18 @@ Hooks.on("updateCompendium", async function (pack, documents, option, userId) { Hooks.on("renderRollTableConfig", BetterRT.enhanceRollTableView); Hooks.on('getCompendiumDirectoryEntryContext', BetterTables.enhanceCompendiumContextMenu); Hooks.on('getRollTableDirectoryEntryContext', BetterTables.enhanceRolltableContextMenu); -Hooks.on('renderChatMessage', BetterTables.handleChatMessageButtons); + +Hooks.on('renderChatMessage', async (message, html, data) => { + if (game.settings.get(BRTCONFIG.NAMESPACE, BRTCONFIG.SHOW_REROLL_BUTTONS)) { + BetterTables.handleChatMessageButtons(message, html) + } +}); + +Hooks.on('renderDocumentSheet', async (sheet, html, data) => { + if (game.user.isGM && game.settings.get(BRTCONFIG.NAMESPACE, BRTCONFIG.ROLL_TABLE_FROM_JOURNAL)) { + BetterTables.handleRolltableLink(sheet, html, data) + } +}); function registerSettings() { let defaultLootSheet = "dnd5e.LootSheet5eNPC"; @@ -125,6 +136,15 @@ function registerSettings() { default: false, type: Boolean }); + + game.settings.register(BRTCONFIG.NAMESPACE, BRTCONFIG.ROLL_TABLE_FROM_JOURNAL, { + name: i18n("BRT.Settings.RollTableFromJournal.Title"), + hint: i18n("BRT.Settings.RollTableFromJournal.Description"), + config: true, + default: false, + type: Boolean + }); + } diff --git a/scripts/core/config.js b/scripts/core/config.js index bad8b6be..5ec94bde 100644 --- a/scripts/core/config.js +++ b/scripts/core/config.js @@ -22,6 +22,7 @@ BRTCONFIG.ADD_ROLL_IN_COMPENDIUM_CONTEXTMENU = "add-roll-on-compendium-contextme BRTCONFIG.ADD_ROLL_IN_ROLLTABLE_CONTEXTMENU = "add-roll-on-rolltable-contextmenu"; BRTCONFIG.SHOW_WARNING_BEFORE_REROLL = "show-warning-before-reroll"; BRTCONFIG.STICK_ROLLTABLE_HEADER = "stick-rolltable-header"; +BRTCONFIG.ROLL_TABLE_FROM_JOURNAL = "roll-table-from-journal"; //in fp2e quantity is in data.data.quantity.value , in 5e data.data.quantity BRTCONFIG.QUANTITY_PROPERTY_PATH = "data.quantity"; diff --git a/styles/brt.css b/styles/brt.css index 5b53ec21..18d70fbb 100644 --- a/styles/brt.css +++ b/styles/brt.css @@ -40,4 +40,12 @@ /* Used to display a button to reroll card output */ .roll-table-reroll-button { margin-right: 5px; +} + +.roll-table-roll-link { + background: #DDD; + padding: 1px 2px; + margin-left: -1px; + border: 1px solid; + border-left: 0; } \ No newline at end of file From a060a86d89925b96b7c6e46c69df72cc7c3d8205 Mon Sep 17 00:00:00 2001 From: Daimakaicho Date: Thu, 15 Jul 2021 15:45:16 +0200 Subject: [PATCH 16/20] fix hardcoded settings reference --- scripts/brt-main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/brt-main.js b/scripts/brt-main.js index 0ae91fd6..d16e052f 100644 --- a/scripts/brt-main.js +++ b/scripts/brt-main.js @@ -36,7 +36,7 @@ Hooks.once("ready", async () => { // refresh spell cache for random spell scroll generation on compendium updates Hooks.on("updateCompendium", async function (pack, documents, option, userId) { - if (pack === game.settings.get("better-rolltables", "default-spell-compendium")) { + if (pack === game.settings.get(BRTCONFIG.NAMESPACE, BRTCONFIG.SPELL_COMPENDIUM_KEY)) { await game.betterTables.updateSpellCache(); } }); From 140126459176ace5c72ce79e55d255ee24c57e52 Mon Sep 17 00:00:00 2001 From: Daimakaicho Date: Thu, 15 Jul 2021 16:15:42 +0200 Subject: [PATCH 17/20] add roll button on table linked in chat message and actor sheet --- scripts/better-tables.js | 87 +++++++++++++++++++++++++++++----------- scripts/brt-main.js | 22 ++++++++++ 2 files changed, 85 insertions(+), 24 deletions(-) diff --git a/scripts/better-tables.js b/scripts/better-tables.js index 71c014a6..a6c380fa 100644 --- a/scripts/better-tables.js +++ b/scripts/better-tables.js @@ -283,6 +283,67 @@ export class BetterTables { return lootChatCard.prepareCharCart(tableEntity); } + static async _addRerollButtonToMessage(message, html) { + if (game.user.isGM && game.settings.get(BRTCONFIG.NAMESPACE, BRTCONFIG.ROLL_TABLE_FROM_JOURNAL)) { + if (game.settings.get(BRTCONFIG.NAMESPACE, BRTCONFIG.SHOW_REROLL_BUTTONS)) { + const tableDrawNode = $(html).find(".table-draw"); + const id = $(tableDrawNode).data("id"); + const pack = $(tableDrawNode).data("pack"); + if (!id && !pack) return; + + let rerollButton = $(``).append(""); + let cardContent = undefined; + + if (pack && !id) { + cardContent = await BetterTables.rollCompendiumAsRolltable(pack); + } else { + let rolltable = undefined; + if (pack && id) { + rolltable = await game.packs.get(pack)?.getDocument(id); + } else { + rolltable = game.tables.get(id); + } + if (rolltable) { + cardContent = await BetterTables.prepareCardData(rolltable); + } + } + rerollButton.click(async () => BetterTables.updateChatMessage(message, cardContent.content)); + $(html).find(".message-sender").prepend(rerollButton); + } + } + } + + static async _addRollButtonsToEntityLink( html) { + // handling rolltables imported in campaign + $(html).find("a.entity-link[data-entity='RollTable']").each((index,link) => { + const id = $(link).data("id"); + const rolltable = game.tables.get(id); + + const rollNode = $(``) + .click(async () => { + await game.betterTables.generateChatLoot(rolltable); + }) + $(link).after(rollNode); + }); + + // handling rolltables in compendiums + $(html).find("a.entity-link[data-pack]").each(async (index,link) => { + const pack_name = $(link).data("pack"); + const pack = game.packs.get(pack_name); + if (!pack) return; + + const id = $(link).data("id"); + const document = await pack.getDocument(id); + if (!document || document.documentName !== "RollTable") return; + + const rollNode = $(``) + .click(async () => { + await game.betterTables.generateChatLoot(document); + }) + $(link).after(rollNode); + }); + } + /** * Handle Reroll buttons on cards * @param {ChatMessage} message newly created message @@ -290,30 +351,8 @@ export class BetterTables { * @returns {Promise} */ static async handleChatMessageButtons(message, html) { - const tableDrawNode = $(html).find(".table-draw"); - const id = $(tableDrawNode).data("id"); - const pack = $(tableDrawNode).data("pack"); - if (!id && !pack) return; - - let rerollButton = $(``).append(""); - let cardContent = undefined; - - if (pack && !id) { - cardContent = await BetterTables.rollCompendiumAsRolltable(pack); - } else { - let rolltable = undefined; - if (pack && id) { - rolltable = await game.packs.get(pack)?.getDocument(id); - } - else { - rolltable = game.tables.get(id); - } - if (rolltable) { - cardContent = await BetterTables.prepareCardData(rolltable); - } - } - rerollButton.click(async () => BetterTables.updateChatMessage(message, cardContent.content)); - $(html).find(".message-sender").prepend(rerollButton); + BetterTables._addRerollButtonToMessage(message, html); + BetterTables._addRollButtonsToEntityLink(html); } /** diff --git a/scripts/brt-main.js b/scripts/brt-main.js index d16e052f..d8f4a9bd 100644 --- a/scripts/brt-main.js +++ b/scripts/brt-main.js @@ -32,6 +32,28 @@ Hooks.once("ready", async () => { } await game.betterTables.updateSpellCache(); + + // refresh spell cache for random spell scroll generation on compendium updates + Hooks.on("updateCompendium", async function (pack, documents, option, userId) { + if (pack === game.settings.get(BRTCONFIG.NAMESPACE, BRTCONFIG.SPELL_COMPENDIUM_KEY)) { + await game.betterTables.updateSpellCache(); + } + }); + + Hooks.on("renderRollTableConfig", BetterRT.enhanceRollTableView); + Hooks.on('getCompendiumDirectoryEntryContext', BetterTables.enhanceCompendiumContextMenu); + Hooks.on('getRollTableDirectoryEntryContext', BetterTables.enhanceRolltableContextMenu); + Hooks.on('renderChatMessage', BetterTables.handleChatMessageButtons); + + Hooks.on('renderDocumentSheet', async (sheet, html, data) => { + if (game.user.isGM && game.settings.get(BRTCONFIG.NAMESPACE, BRTCONFIG.ROLL_TABLE_FROM_JOURNAL)) { + BetterTables.handleRolltableLink(sheet, html, data) + } + }); + + if (game.system.id === "dnd5e") { + Hooks.on('renderActorSheet5eCharacter', BetterTables.handleChatMessageButtons); + } }); // refresh spell cache for random spell scroll generation on compendium updates From ca483f84035ae163d98c06fee85e96c985da0e81 Mon Sep 17 00:00:00 2001 From: Daimakaicho Date: Thu, 15 Jul 2021 16:16:26 +0200 Subject: [PATCH 18/20] remove sticked header because of bug --- scripts/better-table-view.js | 8 +++++++- scripts/brt-main.js | 23 ----------------------- 2 files changed, 7 insertions(+), 24 deletions(-) diff --git a/scripts/better-table-view.js b/scripts/better-table-view.js index a5f2f359..f28b5151 100644 --- a/scripts/better-table-view.js +++ b/scripts/better-table-view.js @@ -11,12 +11,18 @@ export class BetterRT { let tableViewClass = tableElement.getElementsByClassName(tableClassName)[0]; + /* if (game.settings.get(BRTCONFIG.NAMESPACE, BRTCONFIG.STICK_ROLLTABLE_HEADER)) { const header = $(html).find("section.results ol li:first-child"); // we need to use
          parent to preserve styling - $(html).find("section.results").prepend($('
            ').append(header.clone())); + const newHeader = header.clone(); + newHeader.find(".create-result").click(async (event) => rollTabe.update() ); + newHeader.find(".normalize-results").click((event) => ); header.remove(); + $(html).find("section.results").prepend($('
              ').append(newHeader)); + } + */ /** height size increase by type: */ let addHeight = 0; diff --git a/scripts/brt-main.js b/scripts/brt-main.js index d8f4a9bd..83d3a09c 100644 --- a/scripts/brt-main.js +++ b/scripts/brt-main.js @@ -56,29 +56,6 @@ Hooks.once("ready", async () => { } }); -// refresh spell cache for random spell scroll generation on compendium updates -Hooks.on("updateCompendium", async function (pack, documents, option, userId) { - if (pack === game.settings.get(BRTCONFIG.NAMESPACE, BRTCONFIG.SPELL_COMPENDIUM_KEY)) { - await game.betterTables.updateSpellCache(); - } -}); - -Hooks.on("renderRollTableConfig", BetterRT.enhanceRollTableView); -Hooks.on('getCompendiumDirectoryEntryContext', BetterTables.enhanceCompendiumContextMenu); -Hooks.on('getRollTableDirectoryEntryContext', BetterTables.enhanceRolltableContextMenu); - -Hooks.on('renderChatMessage', async (message, html, data) => { - if (game.settings.get(BRTCONFIG.NAMESPACE, BRTCONFIG.SHOW_REROLL_BUTTONS)) { - BetterTables.handleChatMessageButtons(message, html) - } -}); - -Hooks.on('renderDocumentSheet', async (sheet, html, data) => { - if (game.user.isGM && game.settings.get(BRTCONFIG.NAMESPACE, BRTCONFIG.ROLL_TABLE_FROM_JOURNAL)) { - BetterTables.handleRolltableLink(sheet, html, data) - } -}); - function registerSettings() { let defaultLootSheet = "dnd5e.LootSheet5eNPC"; let defaultSpellCompendium = "dnd5e.spells"; From da28b53dfae8fbeaf4e57756fc69b0d2c30886c4 Mon Sep 17 00:00:00 2001 From: Daimakaicho Date: Thu, 15 Jul 2021 16:41:41 +0200 Subject: [PATCH 19/20] fix table header button not working --- scripts/better-table-view.js | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/scripts/better-table-view.js b/scripts/better-table-view.js index f28b5151..cf78f604 100644 --- a/scripts/better-table-view.js +++ b/scripts/better-table-view.js @@ -11,18 +11,31 @@ export class BetterRT { let tableViewClass = tableElement.getElementsByClassName(tableClassName)[0]; - /* + if (game.settings.get(BRTCONFIG.NAMESPACE, BRTCONFIG.STICK_ROLLTABLE_HEADER)) { const header = $(html).find("section.results ol li:first-child"); // we need to use
                parent to preserve styling const newHeader = header.clone(); - newHeader.find(".create-result").click(async (event) => rollTabe.update() ); - newHeader.find(".normalize-results").click((event) => ); header.remove(); + + newHeader.find("a.create-result")[0].onclick = async (event) => { + event.preventDefault(); + if (!game.keyboard.isCtrl()) { + await rollTableConfig._onCreateResult(event); + } else { + for (let i; i < 10; i++) + await rollTableConfig._onCreateResult(event); + } + }; + + newHeader.find("a.normalize-results")[0].onclick = async (event) => { + event.preventDefault(); + await rollTableConfig._onNormalizeResults(event); + }; + $(html).find("section.results").prepend($('
                  ').append(newHeader)); } - */ /** height size increase by type: */ let addHeight = 0; From 382dde509334354f53a8803a939a39fb2e12a0d3 Mon Sep 17 00:00:00 2001 From: Daimakaicho Date: Thu, 15 Jul 2021 16:50:56 +0200 Subject: [PATCH 20/20] (experimental) hold ctrl key when clicking + action to add 10 rows at once in rolltable --- scripts/better-table-view.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/better-table-view.js b/scripts/better-table-view.js index cf78f604..d5110632 100644 --- a/scripts/better-table-view.js +++ b/scripts/better-table-view.js @@ -20,11 +20,12 @@ export class BetterRT { newHeader.find("a.create-result")[0].onclick = async (event) => { event.preventDefault(); - if (!game.keyboard.isCtrl()) { + if (!game.keyboard.isCtrl(event)) { await rollTableConfig._onCreateResult(event); } else { - for (let i; i < 10; i++) + for (let i=0; i < 10; i++) { await rollTableConfig._onCreateResult(event); + } } };