From c01450d20872a27ec74696a6a9a8403a714e63fa 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: Fri, 2 Aug 2024 21:15:35 +0500 Subject: [PATCH] some fixes --- README.md | 5 +++-- js/main.js | 33 ++++++++++++++++++++++++++++++++- styles/add-char.css | 2 +- styles/style.css | 15 ++++++++++++--- 4 files changed, 48 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index af29e8a..6b08693 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ It's util for manage battles in DnD ## Now you can + add character -+ check hp of character ++ check character's HP + clear characters list ## TODO @@ -14,4 +14,5 @@ It's util for manage battles in DnD + remove character for characters list + storing battles + export to JSON -+ import from JSON \ No newline at end of file ++ import from JSON ++ day and night themes \ No newline at end of file diff --git a/js/main.js b/js/main.js index b09f8b3..ebbd3e2 100644 --- a/js/main.js +++ b/js/main.js @@ -49,6 +49,33 @@ function setHealthColor(id) { } function addCharacter() { + if (document.querySelector("[name='char-name']").value == "") { + alert("Field 'Name' is empty"); + return; + } + + if (document.querySelector("[name='hp']").value == "") { + alert("Field 'HP' is empty"); + return; + } + + if (document.querySelector("[name='max-hp']").value == "") { + alert("Field 'Max HP' is empty"); + return; + } + + if (parseInt(document.querySelector("[name='hp']").value) > parseInt(document.querySelector("[name='max-hp']").value)) { + alert("HP value bigger than max HP"); + return; + } + + for (let i = 0; i < parseInt(localStorage.getItem("counting")); ++i) { + if (document.querySelector("[name='char-name']").value == getVal(i.toString(), "name")) { + alert("Character with name: '" + document.querySelector("[name='char-name']").value + "' already exists"); + return; + } + } + const character = document.createElement('div'); character.classList.add("character-box"); character.id = "char-" + localStorage.getItem("counting"); @@ -76,10 +103,14 @@ function addCharacter() { localStorage.setItem("char-" + localStorage.getItem("counting") + "-max-hp", document.querySelector("[name='max-hp']").value); - localStorage.setItem("counting", (parseInt(localStorage.getItem("counting")) + 1).toString()); + document.querySelector("[name='char-name']").value = ""; + document.querySelector("[name='hp']").value = ""; + document.querySelector("[name='max-hp']").value = ""; setHealthColor(localStorage.getItem("counting")); + localStorage.setItem("counting", (parseInt(localStorage.getItem("counting")) + 1).toString()); + document.querySelector(".add-char-btn").classList.add("add-char-btn-closed"); document.querySelector(".add-char-btn").classList.remove("add-char-btn-opened"); diff --git a/styles/add-char.css b/styles/add-char.css index 3295c67..f17dab7 100644 --- a/styles/add-char.css +++ b/styles/add-char.css @@ -84,6 +84,6 @@ width: 10%; } -input:focus { +.input-field:focus { outline: none; } diff --git a/styles/style.css b/styles/style.css index 4ef33e4..1d729aa 100644 --- a/styles/style.css +++ b/styles/style.css @@ -55,9 +55,18 @@ main { border-radius: 10px; } -.remove-btn:hover { - color: #fffaf3; - background: #b4637a; +@media (hover: hover) { + .remove-btn:hover { + color: #fffaf3; + background: #b4637a; + } +} + +@media (hover: none) { + .remove-btn:active { + color: #fffaf3; + background: #b4637a; + } } .bi-trash {