- went back to store true-ini in HTML data attribute via .attr(); .data() did not update the HTML attribute value reliably
This commit is contained in:
parent
615a67cc5f
commit
26a9c216ab
36
js/sr2ini.js
36
js/sr2ini.js
@ -93,7 +93,7 @@ function getEffectiveIni(tr) {
|
||||
}
|
||||
|
||||
// otherwise compute effective ini (true ini minus wound penalties)
|
||||
let effectiveIni = parseInt($(tr).data("true-ini")) - DAMAGE_PENALTY[parseInt($(tr).data("damage-stun")) || 0] - DAMAGE_PENALTY[parseInt($(tr).data("damage-physical")) || 0];
|
||||
let effectiveIni = parseInt($(tr).attr("data-true-ini")) - DAMAGE_PENALTY[parseInt($(tr).attr("data-damage-stun")) || 0] - DAMAGE_PENALTY[parseInt($(tr).attr("data-damage-physical")) || 0];
|
||||
return Math.max(effectiveIni, 0);
|
||||
}
|
||||
|
||||
@ -120,10 +120,10 @@ function addTestCombatant() {
|
||||
function handleActButtonClick (e) {
|
||||
|
||||
// reduce ini by 10 but not lower than 0
|
||||
let ini = Math.max(parseInt($(e.target).parents(".combatantRow").data("true-ini")) - 10, 0);
|
||||
let ini = Math.max(parseInt($(e.target).parents(".combatantRow").attr("data-true-ini")) - 10, 0);
|
||||
|
||||
// set new ini value
|
||||
$(e.target).parents(".combatantRow").data("true-ini", ini);
|
||||
$(e.target).parents(".combatantRow").attr("data-true-ini", ini);
|
||||
|
||||
// resort table
|
||||
sortTable();
|
||||
@ -182,14 +182,14 @@ function handleEditButtonClick (e) {
|
||||
$("#combatantModalName").val($tr.find(".combatantName").text());
|
||||
$("#combatantModalDice").val($tr.find(".combatantDice").text());
|
||||
$("#combatantModalRea").val($tr.find(".combatantRea").text());
|
||||
$("#combatantModalIni").val($tr.data("true-ini"));
|
||||
$("#combatantModalIni").val($tr.attr("data-true-ini"));
|
||||
|
||||
// show effective ini in modal
|
||||
$("#penalty-stun").text(DAMAGE_PENALTY[parseInt($tr.data("damage-stun")) || 0]);
|
||||
$("#penalty-physical").text(DAMAGE_PENALTY[parseInt($tr.data("damage-physical")) || 0]);
|
||||
$("#penalty-stun").text(DAMAGE_PENALTY[parseInt($tr.attr("data-damage-stun")) || 0]);
|
||||
$("#penalty-physical").text(DAMAGE_PENALTY[parseInt($tr.attr("data-damage-physical")) || 0]);
|
||||
|
||||
// mark which row is being edited
|
||||
$("#combatantModal").data("row", $(".combatantRow").index($tr));
|
||||
$("#combatantModal").data("row", $(".combatantRow").index($tr)); // here it's okay to use .data() b/c HTML/CSS does not care about this value
|
||||
|
||||
// add handler for enter key
|
||||
$("#combatantModal input[id*='combatantModal']").off("keydown");
|
||||
@ -223,7 +223,7 @@ function handleRemoveButtonClick (e) {
|
||||
$("#confirmModalNewRoundOkButton").addClass("d-none");
|
||||
|
||||
// mark which row is being removed
|
||||
$("#confirmModal").data("row", $(".combatantRow").index($(e.target).parents(".combatantRow")));
|
||||
$("#confirmModal").data("row", $(".combatantRow").index($(e.target).parents(".combatantRow"))); // here it's okay to use .data() b/c HTML/CSS does not care about this value
|
||||
|
||||
// show modal
|
||||
$("#comfirmModal").modal("show");
|
||||
@ -257,7 +257,7 @@ function addCombatant (e) {
|
||||
$tr.find(".damage-dropdown").append($.parseHTML(DAMAGE_MONITOR_HTML));
|
||||
|
||||
// populate table row with values from modal
|
||||
$tr.data("true-ini", ini);
|
||||
$tr.attr("data-true-ini", ini);
|
||||
$tr.find(".combatantName").text($("#combatantModalName").val().trim());
|
||||
$tr.find(".combatantDice").text($("#combatantModalDice").val().trim());
|
||||
$tr.find(".combatantRea").text($("#combatantModalRea").val().trim());
|
||||
@ -294,7 +294,7 @@ function applyDamage (e) {
|
||||
}).toString().substr(7);
|
||||
|
||||
// add damage level to table row as as data attribute
|
||||
$btn.parents("tr.combatantRow").data("damage-" + damageType, damageLevel);
|
||||
$btn.parents("tr.combatantRow").attr("data-damage-" + damageType, damageLevel);
|
||||
|
||||
// select/unselect damage buttons above/below
|
||||
$btn.addClass("active");
|
||||
@ -335,7 +335,7 @@ function editCombatant (e) {
|
||||
$tr.find(".combatantName").text(name);
|
||||
$tr.find(".combatantDice").text(dice);
|
||||
$tr.find(".combatantRea").text(rea);
|
||||
$tr.data("true-ini", ini);
|
||||
$tr.attr("data-true-ini", ini);
|
||||
|
||||
// sort table
|
||||
sortTable();
|
||||
@ -375,9 +375,9 @@ function startNewRound (e) {
|
||||
// reset ini values
|
||||
$(".combatantRow").each( function() {
|
||||
if ( $(this).find(".combatantDice").text() == "" ) {
|
||||
$(this).data("true-ini", 1);
|
||||
$(this).attr("data-true-ini", 1);
|
||||
} else {
|
||||
$(this).data("true-ini", rollForInitiative(parseInt($(this).find(".combatantDice").text()), parseInt($(this).find(".combatantRea").text())));
|
||||
$(this).attr("data-true-ini", rollForInitiative(parseInt($(this).find(".combatantDice").text()), parseInt($(this).find(".combatantRea").text())));
|
||||
}
|
||||
});
|
||||
|
||||
@ -395,7 +395,7 @@ function sortTable() {
|
||||
|
||||
// mark KO or death with class
|
||||
$(".combatantRow").each(function() {
|
||||
if ( parseInt($(this).data("damage-stun")) == 10 || parseInt($(this).data("damage-physical")) == 10 ) {
|
||||
if ( parseInt($(this).attr("data-damage-stun")) == 10 || parseInt($(this).attr("data-damage-physical")) == 10 ) {
|
||||
$(this).addClass(CONTEXTUAL_CLASSES["KO_OR_DEAD"]);
|
||||
}
|
||||
});
|
||||
@ -410,13 +410,13 @@ function sortTable() {
|
||||
// add damage badges and contextual classes
|
||||
$(".combatantRow").each(function() {
|
||||
// damage badges
|
||||
if ( $(this).data("damage-stun") && $(this).data("damage-stun") != "0" ) {
|
||||
if ( $(this).attr("data-damage-stun") && $(this).attr("data-damage-stun") != "0" ) {
|
||||
$(this).find(".combatantIni").append($.parseHTML(STUN_BADGE_HTML));
|
||||
$(this).find(".stun-badge").append(DAMAGE_NIVEAU[DAMAGE_PENALTY[$(this).data("damage-stun")]]);
|
||||
$(this).find(".stun-badge").append(DAMAGE_NIVEAU[DAMAGE_PENALTY[$(this).attr("data-damage-stun")]]);
|
||||
}
|
||||
if ( $(this).data("damage-physical") && $(this).data("damage-physical") != "0" ) {
|
||||
if ( $(this).attr("data-damage-physical") && $(this).attr("data-damage-physical") != "0" ) {
|
||||
$(this).find(".combatantIni").append($.parseHTML(PHYSICAL_BADGE_HTML));
|
||||
$(this).find(".physical-badge").append(DAMAGE_NIVEAU[DAMAGE_PENALTY[$(this).data("damage-physical")]]);
|
||||
$(this).find(".physical-badge").append(DAMAGE_NIVEAU[DAMAGE_PENALTY[$(this).attr("data-damage-physical")]]);
|
||||
}
|
||||
|
||||
// K.O./dead -> don't add anything
|
||||
|
||||
Loading…
Reference in New Issue
Block a user