67 lines
1.4 KiB
JavaScript
67 lines
1.4 KiB
JavaScript
const CODES_STORAGE_NAME = "kh3/pro-codes-sim/codes/";
|
|
const MERIT_STORAGE_NAME = "kh3/pro-codes-sim/merit/";
|
|
const STAR_MULTIPLIER = 1.25;
|
|
|
|
let selectionAllState = false;
|
|
let stars = 0;
|
|
let totalMerit = 0;
|
|
|
|
document.addEventListener("DOMContentLoaded", (event) => {});
|
|
|
|
function toggleCode(code) {
|
|
let codeStars = Number(code.dataset["stars"]);
|
|
|
|
if (code.checked) {
|
|
stars += codeStars;
|
|
} else {
|
|
stars -= codeStars;
|
|
selectionAllState = false;
|
|
updateAllButton();
|
|
}
|
|
updateStarsCounter();
|
|
}
|
|
|
|
function toggleAllCodes() {
|
|
const codes = document.querySelectorAll("#codes .slot input");
|
|
|
|
if (!selectionAllState) {
|
|
selectionAllState = true;
|
|
updateAllButton();
|
|
for (let code of codes) {
|
|
if (code.checked) {
|
|
continue;
|
|
}
|
|
code.checked = true;
|
|
stars += Number(code.dataset["stars"]);
|
|
}
|
|
} else {
|
|
selectionAllState = false;
|
|
updateAllButton();
|
|
for (let code of codes) {
|
|
if (!code.checked) {
|
|
continue;
|
|
}
|
|
code.checked = false;
|
|
stars -= Number(code.dataset["stars"]);
|
|
}
|
|
}
|
|
|
|
updateStarsCounter();
|
|
}
|
|
|
|
function updateStarsCounter() {
|
|
let counter = document.getElementById("totalStars");
|
|
counter.innerText = "Stars: " + stars;
|
|
}
|
|
|
|
function updateAllButton() {
|
|
const btn = document.querySelector("#codes .slot button");
|
|
if (selectionAllState) {
|
|
btn.classList.add("danger");
|
|
} else {
|
|
btn.classList.remove("danger");
|
|
}
|
|
}
|
|
|
|
Object.assign(window, { toggleCode, toggleAllCodes });
|