2025-11-02 23:26:28 +02:00
|
|
|
import * as storage from "../common/storage.js";
|
|
|
|
|
|
|
|
|
|
const CODES_STORAGE_NAME = "/pro-codes-sim/codes/";
|
|
|
|
|
const MERIT_STORAGE_NAME = "/pro-codes-sim/merit/";
|
2025-10-28 12:40:48 +02:00
|
|
|
const STAR_MULTIPLIER = 1.25;
|
|
|
|
|
|
|
|
|
|
let selectionAllState = false;
|
|
|
|
|
let stars = 0;
|
|
|
|
|
let totalMerit = 0;
|
2025-10-28 23:38:15 +02:00
|
|
|
let fightMerit = [];
|
2025-10-28 12:40:48 +02:00
|
|
|
|
2025-10-28 23:38:15 +02:00
|
|
|
document.addEventListener("DOMContentLoaded", (event) => {
|
|
|
|
|
const codes = document.querySelectorAll("#codes .slot input");
|
|
|
|
|
const fights = document.querySelectorAll("#fights .slot button");
|
|
|
|
|
|
|
|
|
|
// Loading enabled codes
|
|
|
|
|
for (let code of codes) {
|
|
|
|
|
const hasCodeToggled =
|
2025-11-02 23:26:28 +02:00
|
|
|
storage.get(CODES_STORAGE_NAME + code.id) === "true" ? true : false;
|
2025-10-28 23:38:15 +02:00
|
|
|
if (hasCodeToggled) {
|
|
|
|
|
// Normally the toggleCode gets called after the checkbox is checked,
|
|
|
|
|
// since we don't interact with it at this point we mark it as checked manually here
|
|
|
|
|
code.checked = true;
|
|
|
|
|
toggleCode(code);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Loading marked fights and their merit
|
|
|
|
|
for (let fight of fights) {
|
|
|
|
|
const source = fight.dataset["meritSource"];
|
2025-11-02 23:26:28 +02:00
|
|
|
const merit = Number(storage.get(MERIT_STORAGE_NAME + source)) ?? 0;
|
2025-10-28 23:38:15 +02:00
|
|
|
if (merit > 0) {
|
2025-10-28 23:55:16 +02:00
|
|
|
markFight(fight, merit);
|
2025-10-28 23:38:15 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2025-10-28 23:55:16 +02:00
|
|
|
function markFight(data, loadedMerit = 0) {
|
2025-10-28 23:38:15 +02:00
|
|
|
const source = data.dataset["meritSource"];
|
2025-10-28 23:55:16 +02:00
|
|
|
const enemyName = data.dataset["enemy"];
|
2025-10-28 23:38:15 +02:00
|
|
|
const baseMerit = data.dataset["baseMerit"];
|
|
|
|
|
const isMarked = data.dataset["marked"] === "true" ? true : false;
|
|
|
|
|
const fightLabel = data.parentNode.querySelector("span");
|
2025-10-28 23:55:16 +02:00
|
|
|
const isLoading = loadedMerit > 0;
|
2025-10-28 23:38:15 +02:00
|
|
|
|
|
|
|
|
if (isMarked) {
|
|
|
|
|
data.dataset["marked"] = false;
|
|
|
|
|
totalMerit -= fightMerit[source];
|
|
|
|
|
updateMeritCounter();
|
|
|
|
|
fightMerit[source] = 0;
|
|
|
|
|
|
2025-11-02 23:26:28 +02:00
|
|
|
storage.remove(MERIT_STORAGE_NAME + source);
|
2025-10-28 23:38:15 +02:00
|
|
|
|
|
|
|
|
data.innerText = "Mark";
|
|
|
|
|
data.classList.remove("danger");
|
2025-10-28 23:55:16 +02:00
|
|
|
fightLabel.innerText = enemyName;
|
2025-10-28 23:38:15 +02:00
|
|
|
} else {
|
2025-10-28 23:55:16 +02:00
|
|
|
let merit = isLoading
|
|
|
|
|
? loadedMerit
|
|
|
|
|
: baseMerit * (stars * STAR_MULTIPLIER);
|
2025-10-28 23:38:15 +02:00
|
|
|
data.dataset["marked"] = true;
|
|
|
|
|
totalMerit += merit;
|
|
|
|
|
updateMeritCounter();
|
|
|
|
|
fightMerit[source] = merit;
|
|
|
|
|
|
2025-11-02 23:26:28 +02:00
|
|
|
storage.set(MERIT_STORAGE_NAME + source, merit);
|
2025-10-28 23:38:15 +02:00
|
|
|
|
|
|
|
|
data.innerText = "Unmark";
|
|
|
|
|
data.classList.add("danger");
|
2025-10-28 23:55:16 +02:00
|
|
|
fightLabel.innerText = enemyName + " | " + merit + " Merit";
|
2025-10-28 23:38:15 +02:00
|
|
|
}
|
|
|
|
|
}
|
2025-10-28 12:40:48 +02:00
|
|
|
|
|
|
|
|
function toggleCode(code) {
|
|
|
|
|
let codeStars = Number(code.dataset["stars"]);
|
|
|
|
|
|
|
|
|
|
if (code.checked) {
|
|
|
|
|
stars += codeStars;
|
2025-11-02 23:26:28 +02:00
|
|
|
storage.set(CODES_STORAGE_NAME + code.id, true);
|
2025-10-28 12:40:48 +02:00
|
|
|
} else {
|
|
|
|
|
stars -= codeStars;
|
|
|
|
|
selectionAllState = false;
|
|
|
|
|
updateAllButton();
|
2025-11-02 23:26:28 +02:00
|
|
|
storage.remove(CODES_STORAGE_NAME + code.id);
|
2025-10-28 12:40:48 +02:00
|
|
|
}
|
|
|
|
|
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"]);
|
2025-11-02 23:26:28 +02:00
|
|
|
storage.set(CODES_STORAGE_NAME + code.id, true);
|
2025-10-28 12:40:48 +02:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
selectionAllState = false;
|
|
|
|
|
updateAllButton();
|
|
|
|
|
for (let code of codes) {
|
|
|
|
|
if (!code.checked) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
code.checked = false;
|
|
|
|
|
stars -= Number(code.dataset["stars"]);
|
2025-11-02 23:26:28 +02:00
|
|
|
storage.remove(CODES_STORAGE_NAME + code.id);
|
2025-10-28 12:40:48 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
updateStarsCounter();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function updateStarsCounter() {
|
|
|
|
|
let counter = document.getElementById("totalStars");
|
|
|
|
|
counter.innerText = "Stars: " + stars;
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-28 23:38:15 +02:00
|
|
|
function updateMeritCounter() {
|
|
|
|
|
let counter = document.getElementById("totalMerit");
|
|
|
|
|
counter.innerText = "Merit: " + totalMerit;
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-28 12:40:48 +02:00
|
|
|
function updateAllButton() {
|
|
|
|
|
const btn = document.querySelector("#codes .slot button");
|
|
|
|
|
if (selectionAllState) {
|
|
|
|
|
btn.classList.add("danger");
|
|
|
|
|
} else {
|
|
|
|
|
btn.classList.remove("danger");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-28 23:38:15 +02:00
|
|
|
Object.assign(window, { markFight, toggleCode, toggleAllCodes });
|