Skip to content

Commit

Permalink
reordering characters
Browse files Browse the repository at this point in the history
  • Loading branch information
Katarni committed Aug 3, 2024
1 parent 074d9d6 commit 22b7f73
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
18 changes: 18 additions & 0 deletions js/battle.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ function addCharacter() {
document.querySelector("[name='char-name']").value = "";
document.querySelector("[name='hp']").value = "";
document.querySelector("[name='max-hp']").value = "";
document.querySelector("[name='initiative']").value = "";

document.querySelector('.add-char-box').insertAdjacentElement("afterend", getCharElm(localStorage.getItem("counting")));

Expand Down Expand Up @@ -347,6 +348,23 @@ function healChar(mul) {
document.querySelector("[name='hp-delta']").value = "";
}

function cmpForInitiative(a, b) {
if (parseInt(getVal(a, "initiative")) >= parseInt(getVal(b, "initiative"))) {
return -1;
}
return 1;
}

function reorderCharacters() {
const elms = [];
for (let i = 0; i < parseInt(localStorage.getItem("counting")); ++i) {
elms.push(i.toString());
}
elms.sort(cmpForInitiative);

const main = document.querySelector("main");

for (let i = elms.length - 1; i >= 0; --i) {
main.insertBefore(document.querySelector("#char-" + elms[i]), document.querySelector("#char-" + elms[i + 1]));
}
}
2 changes: 2 additions & 0 deletions styles/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ footer {
.footer-text {
color: #575279;
font-size: 15px;

font-family: "Old Standard TT";
}

.footer-link {
Expand Down

0 comments on commit 22b7f73

Please sign in to comment.