diff --git a/lang/de.json b/lang/de.json index e26d9e5d..6ab4ed09 100644 --- a/lang/de.json +++ b/lang/de.json @@ -18,5 +18,22 @@ "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", + "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?", + "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.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 4ba9666c..1f398f9f 100644 --- a/lang/en.json +++ b/lang/en.json @@ -18,5 +18,23 @@ "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}" -} \ No newline at end of file + "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). 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?", + "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.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 b48a6eb4..cccf91cb 100644 --- a/lang/es-ES.json +++ b/lang/es-ES.json @@ -18,5 +18,22 @@ "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", + "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?", + "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.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 33982b12..85464b1b 100644 --- a/lang/fr.json +++ b/lang/fr.json @@ -18,5 +18,22 @@ "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", + "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). 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 ?", + "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.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 c86d9e1a..0cfce974 100644 --- a/lang/ko.json +++ b/lang/ko.json @@ -18,5 +18,22 @@ "BRT.LootRollAmountPlaceholder" : "표 전체를 여러 번 굴림(수식 추가)", "BRT.DrawResultPlural": "{name}의 결과로 선택된 건 {amount}입니다", "BRT.DrawResultSingular": "{name}의 결과로 선택된 건 {amount}입니다", - "BRT.DrawResultZero": "{name}에서 굴림" + "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). 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?", + "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.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 2551f7dc..ec58b132 100644 --- a/lang/pt-BR.json +++ b/lang/pt-BR.json @@ -18,5 +18,22 @@ "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", + "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?", + "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.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-table-view.js b/scripts/better-table-view.js index 4ca8b4fb..d5110632 100644 --- a/scripts/better-table-view.js +++ b/scripts/better-table-view.js @@ -11,6 +11,33 @@ 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(); + header.remove(); + + newHeader.find("a.create-result")[0].onclick = async (event) => { + event.preventDefault(); + if (!game.keyboard.isCtrl(event)) { + await rollTableConfig._onCreateResult(event); + } else { + for (let i=0; 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; switch (selectedTableType) { diff --git a/scripts/better-tables.js b/scripts/better-tables.js index 9745f1bc..a6c380fa 100644 --- a/scripts/better-tables.js +++ b/scripts/better-tables.js @@ -102,9 +102,17 @@ export class BetterTables { async betterTableRoll(tableEntity) { const brtBuilder = new BRTBuilder(tableEntity); const results = await brtBuilder.betterRoll(); - await brtBuilder.createChatCard(results); - } + 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); + } else { + await brtBuilder.createChatCard(results); + } + } /** * Create a new RollTable by extracting entries from a compendium. @@ -178,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')); + } + }); + } } /** @@ -201,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")); + } + }); + } } /** @@ -220,27 +233,175 @@ 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); } + /** + * 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); + } + + 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 + * @param {Object} html message content + * @returns {Promise} + */ + static async handleChatMessageButtons(message, html) { + BetterTables._addRerollButtonToMessage(message, html); + BetterTables._addRollButtonsToEntityLink(html); + } + + /** + * 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()}); + } + } + + 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 ed7855c1..83d3a09c 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(); }); @@ -27,19 +32,30 @@ 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("better-rolltables", "default-spell-compendium")) { - 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); } }); -Hooks.on("renderRollTableConfig", BetterRT.enhanceRollTableView); -Hooks.on('getCompendiumDirectoryEntryContext', BetterTables.enhanceCompendiumContextMenu); -Hooks.on('getRollTableDirectoryEntryContext', BetterTables.enhanceRolltableContextMenu); - function registerSettings() { let defaultLootSheet = "dnd5e.LootSheet5eNPC"; let defaultSpellCompendium = "dnd5e.spells"; @@ -71,6 +87,63 @@ function registerSettings() { default: defaultSpellCompendium, 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"), + config: true, + 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 + }); + + 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 + }); + + 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 28c92828..5ec94bde 100644 --- a/scripts/core/config.js +++ b/scripts/core/config.js @@ -16,6 +16,13 @@ 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"; +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/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); } diff --git a/styles/brt.css b/styles/brt.css index 6b65783b..18d70fbb 100644 --- a/styles/brt.css +++ b/styles/brt.css @@ -35,4 +35,17 @@ .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; +} + +.roll-table-roll-link { + background: #DDD; + padding: 1px 2px; + margin-left: -1px; + border: 1px solid; + border-left: 0; } \ No newline at end of file diff --git a/templates/loot-chat-card.hbs b/templates/loot-chat-card.hbs index 68055ba8..1ed56a73 100644 --- a/templates/loot-chat-card.hbs +++ b/templates/loot-chat-card.hbs @@ -1,11 +1,9 @@ -
      +
      {{#if tableData.description}}
      {{tableData.description}}
      {{/if}} {{#if currency}} -
      - {{localize 'BRT.Currency'}} {{currency}} -
      +
      {{localize 'BRT.Currency'}}{{currency}}
      {{/if}}
        @@ -20,7 +18,7 @@ {{/if}} data-id="{{itemData.item.id}}"> {{itemData.item.name}} -   × {{itemData.quantity}} + {{#ifgt itemData.quantity 1 }}  × {{itemData.quantity}}{{/ifgt}}
      {{/each}}