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 // Create a mapping of which dice contributes which parts
let dicePartMapping = []; let dicePartMapping = [];
entry.dices.forEach(dice => { entry.dices.forEach(dice => {
// Map the actual dice rolls (count number of rolls per dice)
for (let i = 0; i < dice.count; i++) { for (let i = 0; i < dice.count; i++) {
if (partIndex < formulaParts.length && !isNaN(parseInt(formulaParts[partIndex]))) { if (partIndex < formulaParts.length && !isNaN(parseInt(formulaParts[partIndex]))) {
dicePartMapping.push({ dicePartMapping.push({
partIndex: partIndex, 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++; partIndex++;
} }
@@ -342,8 +357,8 @@ function renderHistory() {
formulaParts.forEach((part, index) => { formulaParts.forEach((part, index) => {
const mapping = dicePartMapping.find(m => m.partIndex === index); const mapping = dicePartMapping.find(m => m.partIndex === index);
if (mapping) { if (mapping && mapping.isDiceRoll) {
// This part comes from a dice roll // This part comes from a dice roll - color it
const partSpan = document.createElement("span"); const partSpan = document.createElement("span");
partSpan.innerText = part; partSpan.innerText = part;
partSpan.style.color = mapping.dice.color; partSpan.style.color = mapping.dice.color;
@@ -357,7 +372,7 @@ function renderHistory() {
} }
diceFormula.appendChild(partSpan); diceFormula.appendChild(partSpan);
} else { } else {
// This is an addition value (modifier) // This is a modifier or unrelated value - no color
const partSpan = document.createElement("span"); const partSpan = document.createElement("span");
partSpan.innerText = part; partSpan.innerText = part;
diceFormula.appendChild(partSpan); 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 = [ const assets = [
"/", "/",
"/index.html", "/index.html",