From c26dd7be948dffc714e7463c1a7d9a2e98e31978 Mon Sep 17 00:00:00 2001 From: Tobias Date: Wed, 8 Feb 2023 00:43:17 +0100 Subject: [PATCH] fixed some bugs about incorrectly transferred ini values after taking action / starting new round --- css/custom.css | 4 +--- js/sr2ini.js | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/css/custom.css b/css/custom.css index c50d853..3180fd4 100644 --- a/css/custom.css +++ b/css/custom.css @@ -31,7 +31,6 @@ input:invalid { width: 20px; } -/* Dropdown Content (Hidden by Default) */ .damage-monitor { display: none; position: absolute; @@ -54,14 +53,13 @@ input:invalid { height: 24px; } - - .damage-monitor button { font-size: smaller; height: 24px; width: 30px; padding: 2px; } + .damage-monitor button.active { filter: brightness(91%); } diff --git a/js/sr2ini.js b/js/sr2ini.js index ad711a6..77ac8dd 100644 --- a/js/sr2ini.js +++ b/js/sr2ini.js @@ -21,7 +21,7 @@ const damageMonitorHTML = [' don't add anything if ( $(this).hasClass("out-of-commission") ) { return true; - } + } // ini = zero if ( parseInt($(this).find(".combatantIni").text()) == 0 ) { $(this).addClass(zeroIniClass); + return true; } // ini = max and non-zero - else if ( parseInt($(this).find(".combatantIni").text()) == iniMax && iniMax > 0 ) { + if ( parseInt($(this).find(".combatantIni").text()) == iniMax && iniMax > 0 ) { $(this).addClass(maxIniClass).find(".act-button").prop("disabled", false).removeAttr("aria-disabled"); + return true; } + // everything else + $(this).addClass(regularClass); }) // sort rows and append them in new order @@ -141,8 +145,9 @@ function handleActButtonClick (e) { ini = Math.max(parseInt(ini) - 10, 0); // set new ini value + // can't use text() here because that would delete wound badges $tr.attr("data-true-ini", ini); - $tr.find(".combatantIni").text(getEffectiveIni($tr)); + $tr.find(".combatantIni").contents()[0].data = getEffectiveIni($tr); // resort table sortTable(); @@ -447,6 +452,7 @@ function editCombatant (e) { $tr.find(".combatantRea").text(rea); $tr.attr("data-true-ini", ini); $tr.find(".combatantIni").text(getEffectiveIni($tr)); +//TODO: add badges // sort table sortTable(); @@ -491,8 +497,7 @@ function startNewRound (e) { } else { $(this).attr("data-true-ini", rollForInitiative(dice, $(this).find(".combatantRea").text())); } - $(this).find(".combatantIni").text(getEffectiveIni($(this))); - let effectiveIni = $(this).find(".combatantIni").text(); + $(this).find(".combatantIni").contents()[0].data = getEffectiveIni($(this)); }); // resort table