wynnbuilder-forked-for-changes/sq2bs.js

277 lines
8.9 KiB
JavaScript
Raw Normal View History

2021-10-26 11:43:51 +00:00
let equipment_keys = ['helmet', 'chestplate', 'leggings', 'boots', 'ring1', 'ring2', 'bracelet', 'necklace', 'weapon'];
2021-10-23 13:51:54 +00:00
let weapon_keys = ['dagger', 'wand', 'bow', 'relik', 'spear']
2021-10-22 09:03:50 +00:00
let skp_keys = ['str', 'dex', 'int', 'def', 'agi'];
2021-10-26 13:21:06 +00:00
let spell_disp = ['spell0-info', 'spell1-info', 'spell2-info', 'spell3-info']
2021-10-22 09:03:50 +00:00
document.addEventListener('DOMContentLoaded', function() {
2021-10-23 13:51:54 +00:00
2021-10-26 11:43:51 +00:00
for (const eq of equipment_keys) {
document.querySelector("#"+eq+"-choice").setAttribute("oninput", "update_field('"+ eq +"'); calcBuildSchedule();");
document.querySelector("#"+eq+"-powder").setAttribute("oninput", "calcBuildSchedule();");
document.querySelector("#"+eq+"-tooltip").setAttribute("onclick", "collapse_element('"+ eq +"')");
2021-10-22 09:03:50 +00:00
}
2021-10-26 13:21:06 +00:00
for (const i of spell_disp) {
document.querySelector("#"+i+"Avg").setAttribute("onclick", "toggle_spell_tab('"+i+"')");
}
2021-10-23 13:51:54 +00:00
document.querySelector("#level-choice").setAttribute("oninput", "calcBuildSchedule()")
2021-10-21 14:11:04 +00:00
2021-10-22 09:03:50 +00:00
let skp_fields = document.getElementsByClassName("skp-update");
for (i = 0; i < skp_fields.length; i++) {
skp_fields[i].setAttribute("oninput", "updateStatSchedule()");
}
2021-10-26 11:43:51 +00:00
let masonry = Macy({
container: "#masonry-container",
columns: 1,
mobileFirst: true,
breakAt: {
1200: 4,
},
margin: {
x: 20,
y: 20,
}
});
2021-10-20 15:52:33 +00:00
});
2021-10-22 09:03:50 +00:00
// phanta scheduler
2021-10-21 14:11:04 +00:00
let calcBuildTask = null;
let updateStatTask = null;
let doSearchTask = null;
function calcBuildSchedule(){
if (calcBuildTask !== null) {
clearTimeout(calcBuildTask);
}
calcBuildTask = setTimeout(function(){
calcBuildTask = null;
calculateBuild();
2021-10-26 11:43:51 +00:00
}, 500);
2021-10-21 14:11:04 +00:00
}
function updateStatSchedule(){
if (updateStatTask !== null) {
clearTimeout(updateStatTask);
}
updateStatTask = setTimeout(function(){
updateStatTask = null;
updateStats();
}, 500);
}
function doSearchSchedule(){
if (doSearchTask !== null) {
clearTimeout(doSearchTask);
}
doSearchTask = setTimeout(function(){
doSearchTask = null;
doItemSearch();
}, 500);
}
2021-10-22 09:03:50 +00:00
// equipment field dynamic styling
2021-10-26 11:43:51 +00:00
function update_field(field) {
// built on the assumption of no one will type in CI/CR letter by letter
// resets
document.querySelector("#"+field+"-choice").classList.remove("text-light", "is-invalid", 'Normal', 'Unique', 'Rare', 'Legendary', 'Fabled', 'Mythic', 'Set');
item = document.querySelector("#"+field+"-choice").value
let powder_slots;
let tier;
let category;
let type;
// get item info
if (item.slice(0, 3) == "CI-") {
item = getCustomFromHash(item);
powder_slots = item.statMap.get("slots");
tier = item.statMap.get("tier");
category = item.statMap.get("category");
type = item.statMap.get("type");
}
else if (item.slice(0, 3) == "CR-") {
item = getCraftFromHash(item);
powder_slots = item.statMap.get("slots");
tier = item.statMap.get("tier");
category = item.statMap.get("category");
type = item.statMap.get("type");
}
else if (itemMap.get(item)) {
item = itemMap.get(item);
if (!item) {return false;}
powder_slots = item.slots;
tier = item.tier;
category = item.category;
type = item.type;
}
else {
// item not found
document.querySelector("#"+field+"-choice").classList.add("text-light");
if (item) { document.querySelector("#"+field+"-choice").classList.add("is-invalid"); }
document.querySelector("#"+equipment_keys[i]+"-powder").disabled = true;
return false;
}
2021-10-23 15:34:47 +00:00
2021-10-26 11:43:51 +00:00
// set item color
document.querySelector("#"+field+"-choice").classList.add(tier);
2021-10-23 15:34:47 +00:00
2021-10-26 11:43:51 +00:00
// set powder slots
document.querySelector("#"+field+"-powder").setAttribute("placeholder", powder_slots+" slots");
2021-10-23 15:43:50 +00:00
2021-10-26 11:43:51 +00:00
if (powder_slots == 0) {
document.querySelector("#"+field+"-powder").disabled = true;
} else {
document.querySelector("#"+field+"-powder").disabled = false;
}
2021-10-23 13:51:54 +00:00
2021-10-26 11:43:51 +00:00
// set weapon img
if (category == 'weapon') {
document.querySelector("#weapon-img").setAttribute('src', 'media/items/new/generic-'+type+'.png');
2021-10-21 14:11:04 +00:00
}
2021-10-26 11:43:51 +00:00
// call calc build
2021-10-21 14:11:04 +00:00
}
2021-10-26 12:48:56 +00:00
/* tabulars */
2021-10-26 11:43:51 +00:00
2021-10-23 13:51:54 +00:00
let tabs = ['all-stats', 'minimal-offensive-stats', 'minimal-defensive-stats'];
2021-10-22 09:03:50 +00:00
function show_tab(tab) {
for (const i in tabs) {
document.querySelector("#"+tabs[i]).style.display = "none";
}
document.querySelector("#"+tab).style.display = "";
2021-10-23 13:51:54 +00:00
}
2021-10-26 13:21:06 +00:00
function toggle_spell_tab(tab) {
if (document.querySelector("#"+tab).style.display == "none") {
document.querySelector("#"+tab).style.display = "";
} else {
document.querySelector("#"+tab).style.display = "none";
}
}
2021-10-26 11:43:51 +00:00
function toggle_boost_tab(tab) {
for (const i of skp_keys) {
document.querySelector("#"+i+"-boost").style.display = "none";
}
document.querySelector("#"+tab+"-boost").style.display = "";
}
function collapse_element(eq) {
elem_list = document.querySelector("#"+eq+"-tooltip").children
for (elem of elem_list) {
if (elem.classList.contains("no-collapse")) { continue; }
if (elem.style.display == "none") {
elem.style.display = "";
} else {
elem.style.display = "none";
}
}
// macy quirk
window.dispatchEvent(new Event('resize'));
// weird bug where display: none overrides??
document.querySelector("#"+eq+"-tooltip").style.display = "";
}
2021-10-26 12:48:56 +00:00
// disable boosts
function reset_powder_specials() {
let specials = ["Quake", "Chain_Lightning", "Curse", "Courage", "Wind_Prison"]
for (const special of specials) {
for (i = 1; i < 6; i++) {
if (document.querySelector("#"+special+"-"+i).classList.contains("toggleOn")) {
document.querySelector("#"+special+"-"+i).classList.remove("toggleOn");
}
}
}
}
2021-10-23 13:51:54 +00:00
// autocomplete initialize
function init_autocomplete() {
let dropdowns = new Map()
2021-10-26 11:43:51 +00:00
for (const eq of equipment_keys) {
2021-10-23 13:51:54 +00:00
// build dropdown
2021-10-26 11:43:51 +00:00
console.log('init dropdown for '+ eq)
2021-10-23 13:51:54 +00:00
let item_arr = [];
2021-10-26 11:43:51 +00:00
if (eq == 'weapon') {
2021-10-23 13:51:54 +00:00
for (const weaponType of weapon_keys) {
for (const weapon of itemLists.get(weaponType)) {
let item_obj = itemMap.get(weapon);
if (item_obj["restrict"] && item_obj["restrict"] === "DEPRECATED") {
continue;
}
2021-10-26 11:43:51 +00:00
if (item_obj["name"] == 'No '+ eq.charAt(0).toUpperCase() + eq.slice(1)) {
2021-10-23 15:34:47 +00:00
continue;
}
2021-10-23 13:51:54 +00:00
item_arr.push(weapon);
}
}
} else {
2021-10-26 11:43:51 +00:00
for (const item of itemLists.get(eq.replace(/[0-9]/g, ''))) {
2021-10-23 13:51:54 +00:00
let item_obj = itemMap.get(item);
if (item_obj["restrict"] && item_obj["restrict"] === "DEPRECATED") {
continue;
}
2021-10-26 11:43:51 +00:00
if (item_obj["name"] == 'No '+ eq.charAt(0).toUpperCase() + eq.slice(1)) {
2021-10-23 15:34:47 +00:00
continue;
}
2021-10-23 13:51:54 +00:00
item_arr.push(item)
}
}
// create dropdown
2021-10-26 11:43:51 +00:00
dropdowns.set(eq, new autoComplete({
2021-10-23 13:51:54 +00:00
data: {
src: item_arr
},
2021-10-26 11:43:51 +00:00
selector: "#"+ eq +"-choice",
2021-10-23 13:51:54 +00:00
wrapper: false,
resultsList: {
tabSelect: true,
2021-10-23 15:34:47 +00:00
noResults: true,
2021-10-23 13:51:54 +00:00
class: "search-box dark-7 rounded-bottom px-2 fw-bold dark-shadow-sm",
element: (list, data) => {
// dynamic result loc
2021-10-26 11:43:51 +00:00
let position = document.getElementById(eq+'-dropdown').getBoundingClientRect();
2021-10-23 13:51:54 +00:00
list.style.top = position.bottom + window.scrollY +"px";
list.style.left = position.x+"px";
list.style.width = position.width+"px";
2021-10-23 15:34:47 +00:00
if (!data.results.length) {
message = document.createElement('li');
2021-10-23 15:58:53 +00:00
message.classList.add('scaled-font');
2021-10-26 11:43:51 +00:00
message.textContent = "No results found!";
2021-10-23 15:34:47 +00:00
list.prepend(message);
}
2021-10-23 13:51:54 +00:00
},
},
resultItem: {
class: "scaled-font search-item",
selected: "dark-5",
element: (item, data) => {
2021-10-23 15:58:53 +00:00
item.classList.add(itemMap.get(data.value).tier);
2021-10-23 13:51:54 +00:00
},
},
events: {
input: {
selection: (event) => {
2021-10-23 15:34:47 +00:00
if (event.detail.selection.value) {
event.target.value = event.detail.selection.value;
}
2021-10-26 11:43:51 +00:00
update_field(eq);
2021-10-23 13:51:54 +00:00
calcBuildSchedule();
},
},
}
}));
}
2021-10-26 11:43:51 +00:00
}