From 074d9d6e7d58da60f377a350431b4ba725a75ed5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A2=D0=B8=D0=BC=D1=83=D1=80=20=D0=90=D1=85=D0=BC=D0=B5?= =?UTF-8?q?=D1=82=D0=B7=D1=8F=D0=BD=D0=BE=D0=B2?= Date: Sat, 3 Aug 2024 19:15:37 +0500 Subject: [PATCH] save initiative --- index.html | 2 +- js/battle.js | 16 +++++++++++++++- styles/add-char.css | 4 ++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index 5edd1c1..427f248 100644 --- a/index.html +++ b/index.html @@ -62,7 +62,7 @@

DnD battles

diff --git a/js/battle.js b/js/battle.js index 4fc1d89..60b7097 100644 --- a/js/battle.js +++ b/js/battle.js @@ -7,7 +7,8 @@ function getVal(id, name) { } document.querySelector(".add-char-btn").onclick = openInputFields; -document.querySelector(".remove-btn").onclick = clearCharacters; +document.querySelector("#remove-all-btn").onclick = clearCharacters; +document.querySelector("#reorder-btn").onclick = reorderCharacters; for (let i = 0; i < parseInt(localStorage.getItem("counting")); ++i) { document.querySelector('.add-char-box').insertAdjacentElement("afterend", getCharElm(i.toString())); @@ -55,6 +56,10 @@ function addCharacter() { document.querySelector("[name='max-hp']").classList.remove("input-box-incorrect") } + if (document.querySelector("[name='initiative']").value == "") { + document.querySelector("[name='initiative']").value = "0"; + } + if (parseInt(document.querySelector("[name='hp']").value) > parseInt(document.querySelector("[name='max-hp']").value)) { document.querySelector("[name='hp']").value = document.querySelector("[name='max-hp']").value; } @@ -65,6 +70,8 @@ function addCharacter() { document.querySelector("[name='hp']").value); localStorage.setItem("char-" + localStorage.getItem("counting") + "-max-hp", document.querySelector("[name='max-hp']").value); + localStorage.setItem("char-" + localStorage.getItem("counting") + "-initiative", + document.querySelector("[name='initiative']").value); document.querySelector("[name='char-name']").value = ""; document.querySelector("[name='hp']").value = ""; @@ -120,6 +127,7 @@ function clearCharacters() { localStorage.removeItem("char-" + i.toString() + "-name"); localStorage.removeItem("char-" + i.toString() + "-hp"); localStorage.removeItem("char-" + i.toString() + "-max-hp"); + localStorage.removeItem("char-" + i.toString() + "-initiative"); document.querySelector("main").removeChild(document.querySelector("#char-" + i.toString())); } @@ -240,6 +248,7 @@ function deleteChar(id) { localStorage.setItem("char-" + (i-1).toString() + "-name", getVal(i.toString(), "name")); localStorage.setItem("char-" + (i-1).toString() + "-hp", getVal(i.toString(), "hp")); localStorage.setItem("char-" + (i-1).toString() + "-max-hp", getVal(i.toString(), "max-hp")); + localStorage.setItem("char-" + (i-1).toString() + "-initiative", getVal(i.toString(), "initiative")); document.querySelector("#char-" + i.toString()).id = "char-" + (i-1).toString(); } @@ -248,6 +257,7 @@ function deleteChar(id) { localStorage.removeItem("char-" + localStorage.getItem("counting") + "-name"); localStorage.removeItem("char-" + localStorage.getItem("counting") + "-hp"); localStorage.removeItem("char-" + localStorage.getItem("counting") + "-max-hp"); + localStorage.removeItem("char-" + localStorage.getItem("counting") + "-initiative"); } function openHealthCalc() { @@ -336,3 +346,7 @@ function healChar(mul) { document.querySelector("[name='hp-delta']").value = ""; } + +function reorderCharacters() { + +} diff --git a/styles/add-char.css b/styles/add-char.css index 972350f..aa76205 100644 --- a/styles/add-char.css +++ b/styles/add-char.css @@ -81,6 +81,10 @@ padding-right: 5px; } +.input-field::placeholder { + color: #9893a5; +} + .input-field-text { width: 30%; }