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");
if ( $dice.text() == "" ) {
$ini.text(1);
$ini.text(1);
} else {
$ini.text(rollForInitiative($dice.text(), $(this).find(".combatantRea").text()));
}
@ -322,35 +321,14 @@ function newRound() {
// add test combatant for testing purposes (duh)
function addTestCombatant() {
// construct jQuery object for table row
let $tr = $($.parseHTML( [
'<tr class="combatantRow align-middle">\n',
'<td class="combatantName" title="Combatant\'s name">Test-Goon</td>\n',
'<td class="combatantIni text-center" title="Initiative">12</td>\n',
'<td class="text-center combatantDiceAndRea" title="Iniative dice and reaction"><span class="combatantDice">2</span>D+<span class="combatantRea">6</span></td>\n',
'<td class="text-end">\n',
'<div class="btn-group">\n',
'<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();
$("#addCombatantButton").click();
$("#combatantModalName").val("Goon1");
$("#combatantModalDice").val(2);
$("#combatantModalRea").val(6);
$("#combatantModalIni").val(12);
setTimeout(function(){
$("#combatantModalAddOkButton").click();
},500);
}
@ -377,6 +355,6 @@ $(document).ready(function(){
$("#combatantModal input[id*='combatantModal']").val("");
})
// addTestCombatant();
addTestCombatant();
});