fix addition

This commit is contained in:
2025-11-07 22:22:13 +01:00
parent 557a837fd6
commit 6b1fb83651
2 changed files with 20 additions and 5 deletions
+19 -4
View File
@@ -328,11 +328,26 @@ function renderHistory() {
// Create a mapping of which dice contributes which parts
let dicePartMapping = [];
entry.dices.forEach(dice => {
// Map the actual dice rolls (count number of rolls per dice)
for (let i = 0; i < dice.count; i++) {
if (partIndex < formulaParts.length && !isNaN(parseInt(formulaParts[partIndex]))) {
dicePartMapping.push({
partIndex: partIndex,
dice: dice
dice: dice,
isDiceRoll: true
});
partIndex++;
}
}
// Skip the dice addition - it should remain uncolored
if (dice.addition && partIndex < formulaParts.length) {
// Check if this part matches the dice addition
const currentPart = formulaParts[partIndex];
if (!isNaN(parseInt(currentPart)) && parseInt(currentPart) === Math.abs(dice.addition)) {
dicePartMapping.push({
partIndex: partIndex,
dice: dice,
isDiceRoll: false // This is a modifier, not a dice roll
});
partIndex++;
}
@@ -342,8 +357,8 @@ function renderHistory() {
formulaParts.forEach((part, index) => {
const mapping = dicePartMapping.find(m => m.partIndex === index);
if (mapping) {
// This part comes from a dice roll
if (mapping && mapping.isDiceRoll) {
// This part comes from a dice roll - color it
const partSpan = document.createElement("span");
partSpan.innerText = part;
partSpan.style.color = mapping.dice.color;
@@ -357,7 +372,7 @@ function renderHistory() {
}
diceFormula.appendChild(partSpan);
} else {
// This is an addition value (modifier)
// This is a modifier or unrelated value - no color
const partSpan = document.createElement("span");
partSpan.innerText = part;
diceFormula.appendChild(partSpan);
+1 -1
View File
@@ -1,4 +1,4 @@
const rpgDicesVersion = "rpg-dices-v0.4.0"
const rpgDicesVersion = "rpg-dices-v0.4.1"
const assets = [
"/",
"/index.html",