From 6b1fb83651009450b972465a5c7681c7eb489c1c Mon Sep 17 00:00:00 2001 From: Lurkars Date: Fri, 7 Nov 2025 22:22:13 +0100 Subject: [PATCH] fix addition --- script.js | 23 +++++++++++++++++++---- sw.js | 2 +- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/script.js b/script.js index 1baf46e..09af4cc 100755 --- a/script.js +++ b/script.js @@ -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); diff --git a/sw.js b/sw.js index 0dd537f..5c9722b 100755 --- a/sw.js +++ b/sw.js @@ -1,4 +1,4 @@ -const rpgDicesVersion = "rpg-dices-v0.4.0" +const rpgDicesVersion = "rpg-dices-v0.4.1" const assets = [ "/", "/index.html",