From e27c2a220ffc2095fbb50874ad3daf7f939b5295 Mon Sep 17 00:00:00 2001 From: Byroks Date: Tue, 27 Oct 2026 20:21:49 +0100 Subject: [PATCH] =?UTF-8?q?W=C3=BCrfelerfolge=20einf=C3=A4rben=20&=20setti?= =?UTF-8?q?ngs=20f=C3=BCr=20die=20farben?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/helpers/settings.mjs | 68 ++++++++++++++++++++++++++++++++++- src/styles/chat-messages.scss | 26 ++++++++++++-- src/system.mjs | 23 ++++++++++++ 3 files changed, 113 insertions(+), 4 deletions(-) diff --git a/src/helpers/settings.mjs b/src/helpers/settings.mjs index ce25cbf..09b7eca 100644 --- a/src/helpers/settings.mjs +++ b/src/helpers/settings.mjs @@ -9,7 +9,6 @@ export const loadSettings = async function () { requiresReload: true }); - // Automatically collapse chat message descriptions game.settings.register("midgard6-lvd", "beschreibungChatActive", { name: game.i18n.localize("Midgard6.Settings.beschreibungChatActive.name"), hint: game.i18n.localize("Midgard6.Settings.beschreibungChatActive.hint"), @@ -18,4 +17,71 @@ export const loadSettings = async function () { default: false, type: Boolean }); + + game.settings.register("midgard6-lvd", "beschreibungChatActive", { + name: game.i18n.localize("Midgard6.Settings.beschreibungChatActive.name"), + hint: game.i18n.localize("Midgard6.Settings.beschreibungChatActive.hint"), + scope: "client", + config: true, + default: false, + type: Boolean + }); + + game.settings.register("midgard6-lvd", "colorSuccessBg", { + name: "Erfolg: Hintergrundfarbe", + hint: "Farbe für kritische Erfolge.", + scope: "client", + config: true, + type: String, + default: "#5db68b", + onChange: () => updateAllCssVariables() + }); + + game.settings.register("midgard6-lvd", "colorFailBg", { + name: "Fehlschlag: Hintergrundfarbe", + hint: "Farbe für kritische Fehlschläge.", + scope: "client", + config: true, + type: String, + default: "#e3e4e5", + onChange: () => updateAllCssVariables() + }); + + game.settings.register("midgard6-lvd", "colorCritSuccessBg", { + name: "Kritischer Erffolg: Hintergrundfarbe", + hint: "Farbe für überdurchschnittliche Würfe.", + scope: "client", + config: true, + type: String, + default: "#9de0f0", + onChange: () => updateAllCssVariables() + }); + + game.settings.register("midgard6-lvd", "colorCritFailureBg", { + name: "Kritischer Erffolg: Hintergrundfarbe", + hint: "Farbe für überdurchschnittliche Würfe.", + scope: "client", + config: true, + type: String, + default: "#ea7699", + onChange: () => updateAllCssVariables() + }); }; + +function updateAllCssVariables() { + const root = document.documentElement; + + const successColor = game.settings.get("midgard6-lvd", "colorSuccessBg"); + const failColor = game.settings.get("midgard6-lvd", "colorFailBg"); + const critSuccessColor = game.settings.get("midgard6-lvd", "colorCritSuccessBg"); + const critFailColor = game.settings.get("midgard6-lvd", "colorCritFailureBg"); + + root.style.setProperty("--M6-success-color", successColor); + root.style.setProperty("--M6-failure-color", failColor); + root.style.setProperty("--M6-crit-success-color", critSuccessColor); + root.style.setProperty("--M6-crit-failure-color", critFailColor); +} + +Hooks.once("ready", () => { + updateAllCssVariables(); +}); diff --git a/src/styles/chat-messages.scss b/src/styles/chat-messages.scss index b827ad6..cff7837 100644 --- a/src/styles/chat-messages.scss +++ b/src/styles/chat-messages.scss @@ -1,3 +1,10 @@ +:root { + --M6-crit-success-color: #9de0f0; + --M6-success-color: #5db68b; + --M6-failure-color: #e3e4e5; + --M6-crit-failure-color: #ea7699; +} + .chat-message { background: none; border-radius: 0; @@ -46,9 +53,6 @@ } } - /* Add a background color to the button if it is clicked on (add the .active class with JS), and when you move the mouse over it (hover) */ - - /* Style the collapsible content. Note: hidden by default */ .content { padding: 0 18px; display: none; @@ -93,4 +97,20 @@ font-weight: 500; padding: 0.3em; } + + .roll-crit-fail { + background-color: var(--M6-crit-failure-color); + } + + .roll-crit-success { + background-color: var(--M6-crit-success-color); + } + + .roll-success { + background-color: var(--M6-success-color); + } + + .roll-failure { + background-color: var(--M6-failure-color); + } } diff --git a/src/system.mjs b/src/system.mjs index 59dabfa..525751c 100644 --- a/src/system.mjs +++ b/src/system.mjs @@ -116,4 +116,27 @@ Hooks.on("renderChatMessageHTML", (message, html, data) => { ); }); } + + const diceTotalElement = html.querySelector(".dice-total"); + if (!diceTotalElement) return; + + if (!message.rolls || message.rolls.length === 0) return; + + const mainRoll = message.rolls[0]; + const totalValue = mainRoll.total; + + const firstDiceTerm = mainRoll.terms.find((t) => t instanceof foundry.dice.terms.DiceTerm); + const activeResult = firstDiceTerm.results.find((x) => x.active).result; + const maxPossible = firstDiceTerm.faces; + diceTotalElement.classList.remove("roll-crit-fail", "roll-crit-success", "roll-high"); + + if (activeResult === 1) { + diceTotalElement.classList.add("roll-crit-fail"); + } else if (activeResult === maxPossible || mainRoll.isCritical || totalValue >= 30) { + diceTotalElement.classList.add("roll-crit-success"); + } else if (totalValue >= 20) { + diceTotalElement.classList.add("roll-success"); + } else if (totalValue <= 20) { + diceTotalElement.classList.add("roll-failure"); + } });