Würfelerfolge einfärben & settings für die farben
Foundry VTT System Release / build-and-release (push) Successful in 2m10s

This commit was merged in pull request #11.
This commit is contained in:
Byroks committed 2026-10-27 20:21:49 +01:00
1 parent 914fe01a2c
commit e27c2a220f
3 files changed
+113 -4

No files matched your search

+67 -1
View File
@@ -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();
});
+23 -3
View File
@@ -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);
}
}
+23
View File
@@ -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");
}
});