diff --git a/css/custom.css b/css/custom.css index ee0eaf6..e0c6c04 100644 --- a/css/custom.css +++ b/css/custom.css @@ -1,7 +1,10 @@ -/*input { - opacity: 0.65; -} -*/ +#dummy-row { + display: none; +} +#dummy-row:only-child { + display: block; +} + input:invalid { border: 2px solid red; } diff --git a/index.html b/index.html index 92c3115..0ca19fc 100644 --- a/index.html +++ b/index.html @@ -24,13 +24,11 @@
-
diff --git a/js/sr2ini.js b/js/sr2ini.js index 98ccedb..2e01ec9 100644 --- a/js/sr2ini.js +++ b/js/sr2ini.js @@ -12,19 +12,33 @@ function rollForInitiative(dice, rea) { return ini + parseInt(rea); } + +// figure out whose action comes first out of two combatants a and b +function whoGoesFirst(a, b) { + let comparer = parseInt($(b).find(".combatantIni").text()) - parseInt($(a).find(".combatantIni").text()); + if (comparer != 0) { + return comparer; + } else { + let reaA = parseInt($(a).find(".combatantRea").text()); + let reaB = parseInt($(b).find(".combatantRea").text()); + reaA = isNaN(reaA) ? 0 : reaA; + if (isNaN(reaB)) { reaB = 0; } +console.log(reaA, reaB); + return reaB - reaA; + } +} + + // sorts the combatants by ini value function sortTable() { - // sort rows - let $rows = $(".combatantRow").toArray().sort(function(a, b) { - return parseInt($(b).find(".combatantIni").text()) - parseInt($(a).find(".combatantIni").text()); - }); - - // append rows in sorted order + // sort rows and append them in new order + let $rows = $(".combatantRow").toArray().sort(whoGoesFirst); for ( var i = 0; i < $rows.length; i++ ) { $("#combatantsTable").append($rows[i]); } - // compute highest ini + // add contectual classes to rows – currently for highest ini and ini = 0 + // compute highest ini let iniValues = $.map( $(".combatantIni"), function(td, i) { return parseInt($(td).text()); }); @@ -32,13 +46,13 @@ function sortTable() { // add contextual classes to rows $(".combatantRow").each( function() { - // default: remove previous classes, disable act button + // always remove previous classes, disable act button $(this).removeClass("table-primary table-secondary").find(".act-button").prop("disabled", true).attr("aria-disabled", "true"); - // ini is zero: add class + // add class if ini is zero if ( parseInt($(this).find(".combatantIni").text()) == 0 ) { $(this).addClass("table-secondary"); } - // ini is max and non-zero: add class, enable act button + // add class, enable act button if ini is max and non-zero else if ( parseInt($(this).find(".combatantIni").text()) == iniMax && iniMax > 0 ) { $(this).addClass("table-primary").find(".act-button").prop("disabled", false).removeAttr("aria-disabled"); } @@ -215,7 +229,7 @@ function addCombatant (e) { '', ini, '\n', '\n', '
\n', - '\n', + '
\n', '\n', '\n', '\n', @@ -224,11 +238,11 @@ function addCombatant (e) { '
', dice, '+
\n', '
\n', '\n', - '\n', + '\n', '
\n', - ' \n', - ' \n', - '\n', + '\n', + '\n', + '\n', '
\n', '\n', ''].join("") @@ -240,7 +254,7 @@ function addCombatant (e) { $tr.find("button.remove-button").on("click", handleRemoveButtonClick); // add handlers to table cells (click to edit) - $tr.find("[class*='combatant']").on("click", handleEditButtonClick); + $tr.find(".combatantName, .combatantIni, .combatantDiceAndRea").on("click", handleEditButtonClick); // add row to table and sort $("#combatantsTable").append($tr);