Skip to content

Commit

Permalink
some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Katarni committed Aug 2, 2024
1 parent fc85a5a commit c01450d
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 7 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
+ import from JSON
+ day and night themes
33 changes: 32 additions & 1 deletion js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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");

Expand Down
2 changes: 1 addition & 1 deletion styles/add-char.css
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,6 @@
width: 10%;
}

input:focus {
.input-field:focus {
outline: none;
}
15 changes: 12 additions & 3 deletions styles/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit c01450d

Please sign in to comment.