2021-01-23 10:53:24 +00:00
|
|
|
function getItemNameFromID(id) {
|
|
|
|
if (redirectMap.has(id)) {
|
|
|
|
return getItemNameFromID(redirectMap.get(id));
|
|
|
|
}
|
|
|
|
return idMap.get(id);
|
|
|
|
}
|
|
|
|
|
2022-05-22 07:57:47 +00:00
|
|
|
function getTomeNameFromID(id) {
|
|
|
|
if (tomeRedirectMap.has(id)) {
|
|
|
|
return getTomeNameFromID(tomeRedirectMap.get(id));
|
|
|
|
}
|
|
|
|
return tomeIDMap.get(id);
|
|
|
|
}
|
|
|
|
|
2021-10-01 02:00:11 +00:00
|
|
|
function populateBuildList() {
|
|
|
|
const buildList = document.getElementById("build-choice");
|
|
|
|
const savedBuilds = window.localStorage.getItem("builds") === null ? {} : JSON.parse(window.localStorage.getItem("builds"));
|
|
|
|
|
|
|
|
for (const buildName of Object.keys(savedBuilds).sort()) {
|
|
|
|
const buildOption = document.createElement("option");
|
|
|
|
buildOption.setAttribute("value", buildName);
|
|
|
|
buildList.appendChild(buildOption);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-12 06:18:20 +00:00
|
|
|
function saveBuild() {
|
|
|
|
if (player_build) {
|
2021-10-01 02:00:11 +00:00
|
|
|
const savedBuilds = window.localStorage.getItem("builds") === null ? {} : JSON.parse(window.localStorage.getItem("builds"));
|
|
|
|
const saveName = document.getElementById("build-name").value;
|
2022-06-19 07:42:49 +00:00
|
|
|
const encodedBuild = encodeBuild(player_build);
|
2021-09-25 17:22:04 +00:00
|
|
|
if ((!Object.keys(savedBuilds).includes(saveName)
|
|
|
|
|| document.getElementById("saved-error").textContent !== "") && encodedBuild !== "") {
|
2021-09-17 20:56:29 +00:00
|
|
|
savedBuilds[saveName] = encodedBuild.replace("#", "");
|
2021-09-12 06:18:20 +00:00
|
|
|
window.localStorage.setItem("builds", JSON.stringify(savedBuilds));
|
|
|
|
|
|
|
|
document.getElementById("saved-error").textContent = "";
|
2021-10-01 02:00:11 +00:00
|
|
|
document.getElementById("saved-build").textContent = "Build saved locally";
|
|
|
|
|
|
|
|
const buildList = document.getElementById("build-choice");
|
|
|
|
const buildOption = document.createElement("option");
|
|
|
|
buildOption.setAttribute("value", saveName);
|
|
|
|
buildList.appendChild(buildOption);
|
2021-09-12 06:18:20 +00:00
|
|
|
} else {
|
2021-09-25 17:22:04 +00:00
|
|
|
document.getElementById("saved-build").textContent = "";
|
|
|
|
if (encodedBuild === "") {
|
2021-09-12 06:18:20 +00:00
|
|
|
document.getElementById("saved-error").textContent = "Empty build";
|
2021-09-25 17:22:04 +00:00
|
|
|
}
|
|
|
|
else {
|
2021-09-12 06:18:20 +00:00
|
|
|
document.getElementById("saved-error").textContent = "Exists. Overwrite?";
|
2021-09-25 17:22:04 +00:00
|
|
|
}
|
2021-09-12 06:18:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function loadBuild() {
|
|
|
|
let savedBuilds = window.localStorage.getItem("builds") === null ? {} : JSON.parse(window.localStorage.getItem("builds"));
|
|
|
|
let saveName = document.getElementById("build-name").value;
|
|
|
|
|
|
|
|
if (Object.keys(savedBuilds).includes(saveName)) {
|
|
|
|
decodeBuild(savedBuilds[saveName])
|
2021-09-25 17:22:04 +00:00
|
|
|
document.getElementById("loaded-error").textContent = "";
|
2021-09-12 06:18:20 +00:00
|
|
|
document.getElementById("loaded-build").textContent = "Build loaded";
|
2021-09-25 17:22:04 +00:00
|
|
|
} else {
|
|
|
|
document.getElementById("loaded-build").textContent = "";
|
2021-09-12 06:18:20 +00:00
|
|
|
document.getElementById("loaded-error").textContent = "Build doesn't exist";
|
2021-09-25 17:22:04 +00:00
|
|
|
}
|
2021-09-12 06:18:20 +00:00
|
|
|
}
|
|
|
|
|
2021-01-06 20:54:15 +00:00
|
|
|
function resetFields(){
|
2021-01-09 03:53:57 +00:00
|
|
|
for (let i in powderInputs) {
|
|
|
|
setValue(powderInputs[i], "");
|
|
|
|
}
|
2021-01-09 08:52:58 +00:00
|
|
|
for (let i in equipmentInputs) {
|
2021-01-09 03:53:57 +00:00
|
|
|
setValue(equipmentInputs[i], "");
|
|
|
|
}
|
2021-01-07 10:23:54 +00:00
|
|
|
setValue("str-skp", "0");
|
|
|
|
setValue("dex-skp", "0");
|
|
|
|
setValue("int-skp", "0");
|
|
|
|
setValue("def-skp", "0");
|
|
|
|
setValue("agi-skp", "0");
|
2021-01-29 22:13:52 +00:00
|
|
|
setValue("level-choice", "106");
|
2021-01-08 01:16:06 +00:00
|
|
|
location.hash = "";
|
2021-01-14 03:17:01 +00:00
|
|
|
calculateBuild();
|
2021-01-06 22:46:00 +00:00
|
|
|
}
|
|
|
|
|
2021-01-18 14:18:14 +00:00
|
|
|
function toggleID() {
|
|
|
|
let button = document.getElementById("show-id-button");
|
|
|
|
let targetDiv = document.getElementById("id-edit");
|
|
|
|
if (button.classList.contains("toggleOn")) { //toggle the pressed button off
|
|
|
|
targetDiv.style.display = "none";
|
|
|
|
button.classList.remove("toggleOn");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
targetDiv.style.display = "block";
|
|
|
|
button.classList.add("toggleOn");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-22 07:57:47 +00:00
|
|
|
function toggleButton(button_id) {
|
|
|
|
let button = document.getElementById(button_id);
|
|
|
|
if (button) {
|
|
|
|
if (button.classList.contains("toggleOn")) {
|
|
|
|
button.classList.remove("toggleOn");
|
|
|
|
} else {
|
|
|
|
button.classList.add("toggleOn");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-19 07:42:49 +00:00
|
|
|
// toggle tab
|
|
|
|
function toggle_tab(tab) {
|
|
|
|
if (document.querySelector("#"+tab).style.display == "none") {
|
|
|
|
document.querySelector("#"+tab).style.display = "";
|
|
|
|
} else {
|
|
|
|
document.querySelector("#"+tab).style.display = "none";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-19 16:49:04 +00:00
|
|
|
|
|
|
|
let tabs = ['overall-stats', 'offensive-stats', 'defensive-stats'];
|
|
|
|
function show_tab(tab) {
|
|
|
|
//console.log(itemFilters)
|
|
|
|
|
|
|
|
//hide all tabs, then show the tab of the div clicked and highlight the correct button
|
|
|
|
for (const i in tabs) {
|
|
|
|
document.querySelector("#" + tabs[i]).style.display = "none";
|
|
|
|
document.getElementById("tab-" + tabs[i].split("-")[0] + "-btn").classList.remove("selected-btn");
|
|
|
|
}
|
|
|
|
document.querySelector("#" + tab).style.display = "";
|
|
|
|
document.getElementById("tab-" + tab.split("-")[0] + "-btn").classList.add("selected-btn");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-04-30 10:36:25 +00:00
|
|
|
// TODO: Learn and use await
|
2022-05-22 07:57:47 +00:00
|
|
|
function init() {
|
|
|
|
console.log("builder.js init");
|
|
|
|
init_autocomplete();
|
|
|
|
decodeBuild(url_tag);
|
|
|
|
}
|
|
|
|
|
2022-06-12 14:45:48 +00:00
|
|
|
//load_init(init3);
|
|
|
|
(async function() {
|
|
|
|
let load_promises = [ load_init(), load_ing_init(), load_tome_init() ];
|
|
|
|
await Promise.all(load_promises);
|
|
|
|
init();
|
|
|
|
})();
|