improved a function to add a test combatant

This commit is contained in:
Tobias 2023-02-05 19:20:20 +01:00
parent 516cffb3a3
commit 380f98fa4d

View File

@ -309,7 +309,6 @@ function newRound() {
let $dice = $(this).find(".combatantDice"); let $dice = $(this).find(".combatantDice");
if ( $dice.text() == "" ) { if ( $dice.text() == "" ) {
$ini.text(1); $ini.text(1);
$ini.text(1);
} else { } else {
$ini.text(rollForInitiative($dice.text(), $(this).find(".combatantRea").text())); $ini.text(rollForInitiative($dice.text(), $(this).find(".combatantRea").text()));
} }
@ -322,35 +321,14 @@ function newRound() {
// add test combatant for testing purposes (duh) // add test combatant for testing purposes (duh)
function addTestCombatant() { function addTestCombatant() {
// construct jQuery object for table row $("#addCombatantButton").click();
let $tr = $($.parseHTML( [ $("#combatantModalName").val("Goon1");
'<tr class="combatantRow align-middle">\n', $("#combatantModalDice").val(2);
'<td class="combatantName" title="Combatant\'s name">Test-Goon</td>\n', $("#combatantModalRea").val(6);
'<td class="combatantIni text-center" title="Initiative">12</td>\n', $("#combatantModalIni").val(12);
'<td class="text-center combatantDiceAndRea" title="Iniative dice and reaction"><span class="combatantDice">2</span>D+<span class="combatantRea">6</span></td>\n', setTimeout(function(){
'<td class="text-end">\n', $("#combatantModalAddOkButton").click();
'<div class="btn-group">\n', },500);
'<button type="button" class="btn btn-light btn-rounded mx-1 p-1 edit-button" title="Edit combatant\'s values"><img src="img/004-edit-button.png" /></button>\n',
'<button type="button" class="btn btn-light btn-rounded mx-1 p-1 act-button" title="Act and reduce ini by 10"><img src="img/003-explosion.png" /></button>\n',
'<button type="button" class="btn btn-light btn-rounded mx-1 p-1 remove-button" title="Take damage">\n',
'<img src="img/002-band-aid.png" />\n',
'</button>\n',
'</div>\n',
'</td>\n',
'</tr>'].join("")
));
// add handlers to table row buttons
$tr.find("button.edit-button").on("click", handleEditButtonClick);
$tr.find("button.act-button").on("click", handleActButtonClick);
$tr.find("button.remove-button").on("click", handleRemoveButtonClick);
// add handlers to table cells (click to edit)
$tr.find(".combatantName, .combatantIni, .combatantDiceAndRea").on("click", handleEditButtonClick);
// add row to table and sort
$("#combatantsTable").append($tr);
sortTable();
} }
@ -377,6 +355,6 @@ $(document).ready(function(){
$("#combatantModal input[id*='combatantModal']").val(""); $("#combatantModal input[id*='combatantModal']").val("");
}) })
// addTestCombatant(); addTestCombatant();
}); });