fixed a bug where disabling and enabling buttons for dead/KOed/ini-zero combatants wasn't working correctly; also added a surrounding <div> in table row stub

This commit is contained in:
Tobias 2023-09-20 12:50:51 +02:00
parent 5294b19a13
commit 0b020decc1

View File

@ -36,7 +36,9 @@ const COMBATANT_TABLE_ROW = [
'<td class="combatant-ini" title="Effective initiative (w/ wound penalties)" data-bs-toggle="modal" data-bs-target="#combatant-modal" data-augmented-ui="both"></td>\n',
'<td class="combatant-dice-and-rea" title="Iniative dice and reaction" data-bs-toggle="modal" data-bs-target="#combatant-modal" data-augmented-ui="both"><span class="combatant-dice"></span>D+<span class="combatant-rea"></span></td>\n',
'<td class="combatant-actions" data-augmented-ui="both">\n',
'<button type="button" class="sr2-button act-button" title="Act and reduce ini by 10"><svg viewbox="0 0 512 512"><use href="#act" /></svg></button>\n',
'<div>\n',
'<button type="button" class="sr2-button act-button" title="Act and reduce ini by 10"><svg viewbox="0 0 512 512"><use href="#act" /></svg></button>\n',
'</div>\n',
'<div class="damage-dropdown">\n',
'<button type="button" class="sr2-button damage-button" title="Take damage"><svg viewbox="0 0 512 512"><use href="#take-damage" /></svg></button>\n',
'</div>\n',
@ -413,10 +415,11 @@ function startNewRound() {
// sort combatants by ini value and add contextual classes
function sortTable() {
// do some clean up: remove previous classes from rows, disable act buttons, remove effective ini and damage badges
// do some clean up: remove previous classes from rows, remove effective ini and damage badges
$(".combatant-row").removeClass("ko-or-dead max-ini zero-ini"); //REGULAR_INI
$(".combatant-row").find(".act-button").prop("disabled", true).attr("aria-disabled", "true");
$(".combatant-ini").empty();
// disable all act buttons
$(".combatant-row").find(".act-button").prop("disabled", true).attr("aria-disabled", "true");
// mark KO or death with class
$(".combatant-row").each(function() {
if (parseInt($(this).attr("data-damage-stun")) == 10 || parseInt($(this).attr("data-damage-physical")) == 10) {
@ -440,16 +443,16 @@ function sortTable() {
$(this).find(".combatant-ini").append($.parseHTML(PHYSICAL_BADGE_HTML));
$(this).find(".physical-badge").append(DAMAGE_NIVEAU[DAMAGE_PENALTY[$(this).attr("data-damage-physical")]]);
}
// K.O./dead -> don't add anything
// K.O./dead -> do nothing
if ($(this).hasClass("ko-or-dead")) {
return true;
}
// ini = zero
// ini = zero -> set contextual class
if (parseInt($(this).find(".combatant-ini").text()) == 0) {
$(this).addClass("zero-ini");
return true;
}
// ini = max and non-zero
// ini = max and non-zero -> enable act-button
if (parseInt($(this).find(".combatant-ini").text()) == iniMax && iniMax > 0) {
$(this).addClass("max-ini").find(".act-button").prop("disabled", false).removeAttr("aria-disabled");
return true;