small /4s -> /3 and /5 s on customizer, correct save order for reversed IDs on customs

This commit is contained in:
ferricles 2021-04-12 14:30:16 -07:00
parent 8a7efea3a1
commit 43afa93185
4 changed files with 77 additions and 18 deletions

View file

@ -997,7 +997,7 @@
<p class="error" style="color: red; top: 30px; font-size: 10px; padding: 0; margin: 0; height: 5px; font-family: 'Nunito', sans-serif; word-break:break-word;"></p> <p class="error" style="color: red; top: 30px; font-size: 10px; padding: 0; margin: 0; height: 5px; font-family: 'Nunito', sans-serif; word-break:break-word;"></p>
</div> </div>
<div id="mr-choice-container"> <div id="mr-choice-container">
<label for = "mr-choice">Mana Regen ( /3s):</label><br/> <label for = "mr-choice">Mana Regen ( /5s):</label><br/>
<table id = "mr-choice"> <table id = "mr-choice">
<tr> <tr>
<td> <td>
@ -1024,12 +1024,12 @@
<tr> <tr>
<td class="left" id = "ms"> <td class="left" id = "ms">
<div id="ms-choice-fixed-container" style = "display:none" > <div id="ms-choice-fixed-container" style = "display:none" >
<label for="ms-choice-fixed">Mana Steal ( /4s):</label><br/> <label for="ms-choice-fixed">Mana Steal ( /3s):</label><br/>
<input class="number-input" id="ms-choice-fixed" name="ms-choice-fixed" value="" tabindex=""/> <input class="number-input" id="ms-choice-fixed" name="ms-choice-fixed" value="" tabindex=""/>
<p class="error" style="color: red; top: 30px; font-size: 10px; padding: 0; margin: 0; height: 5px; font-family: 'Nunito', sans-serif; word-break:break-word;"></p> <p class="error" style="color: red; top: 30px; font-size: 10px; padding: 0; margin: 0; height: 5px; font-family: 'Nunito', sans-serif; word-break:break-word;"></p>
</div> </div>
<div id="ms-choice-container"> <div id="ms-choice-container">
<label for = "ms-choice">Mana Steal ( /4s):</label><br/> <label for = "ms-choice">Mana Steal ( /3s):</label><br/>
<table id = "ms-choice"> <table id = "ms-choice">
<tr> <tr>
<td> <td>
@ -1056,12 +1056,12 @@
<tr> <tr>
<td class="left" id = "ls"> <td class="left" id = "ls">
<div id="ls-choice-fixed-container" style = "display:none" > <div id="ls-choice-fixed-container" style = "display:none" >
<label for="ls-choice-fixed">Life Steal ( /4s):</label><br/> <label for="ls-choice-fixed">Life Steal ( /3s):</label><br/>
<input class="number-input" id="ls-choice-fixed" name="ls-choice-fixed" value="" tabindex=""/> <input class="number-input" id="ls-choice-fixed" name="ls-choice-fixed" value="" tabindex=""/>
<p class="error" style="color: red; top: 30px; font-size: 10px; padding: 0; margin: 0; height: 5px; font-family: 'Nunito', sans-serif; word-break:break-word;"></p> <p class="error" style="color: red; top: 30px; font-size: 10px; padding: 0; margin: 0; height: 5px; font-family: 'Nunito', sans-serif; word-break:break-word;"></p>
</div> </div>
<div id="ls-choice-container"> <div id="ls-choice-container">
<label for = "ls-choice">Life Steal ( /4s):</label><br/> <label for = "ls-choice">Life Steal ( /3s):</label><br/>
<table id = "ls-choice"> <table id = "ls-choice">
<tr> <tr>
<td> <td>

View file

@ -134,14 +134,14 @@ function calculateCustom() {
} }
statMap.set("fixID", true); statMap.set("fixID", true);
} else { //rolled IDs! } else { //not fixed
for (const input of inputs) { for (const input of inputs) {
if (input.id.includes("-fixed")) { if (input.id.includes("-fixed")) {
continue; continue;
} }
//FIXs
let id = input.id.replace("-choice", ""); let id = input.id.replace("-choice", "");
let rollMap = ""; let rollMap = "";
let oppMap = "";
//If it's a minimum, it's -min //If it's a minimum, it's -min
if(id.includes("-min")) { if(id.includes("-min")) {
@ -570,16 +570,31 @@ function base_to_range(id) {
let base = parseFloat(getValue(id+"-choice-base")); let base = parseFloat(getValue(id+"-choice-base"));
if(base) { if(base) {
//This version allows overriding of min and max. //This version allows overriding of min and max.
if (base < 0) { if (reversedIDs.includes(id)) {
setValue(id+"-choice-min", Math.min(Math.round(neg_range[0]*base),-1)); if (base < 0) {
setValue(id+"-choice-min", Math.min(Math.round(neg_range[1]*base),-1));
} else {
setValue(id+"-choice-min", Math.max(Math.round(pos_range[1]*base),1));
}
if (base < 0) {
setValue(id+"-choice-max", Math.min(Math.round(neg_range[0]*base),-1));
} else {
setValue(id+"-choice-max", Math.max(Math.round(pos_range[0]*base),1));
}
} else { } else {
setValue(id+"-choice-min", Math.max(Math.round(pos_range[0]*base),1)); if (base < 0) {
} setValue(id+"-choice-min", Math.min(Math.round(neg_range[0]*base),-1));
if (base < 0) { } else {
setValue(id+"-choice-max", Math.min(Math.round(neg_range[1]*base),-1)); setValue(id+"-choice-min", Math.max(Math.round(pos_range[0]*base),1));
} else { }
setValue(id+"-choice-max", Math.max(Math.round(pos_range[1]*base),1)); if (base < 0) {
setValue(id+"-choice-max", Math.min(Math.round(neg_range[1]*base),-1));
} else {
setValue(id+"-choice-max", Math.max(Math.round(pos_range[1]*base),1));
}
} }
/* No overiding min/max version /* No overiding min/max version
if (!getValue(id+"-choice-min")) { if (!getValue(id+"-choice-min")) {
if (base < 0) { if (base < 0) {

View file

@ -66,6 +66,7 @@ async function load_map(init_func) {
result = await (await fetch(url)).json(); result = await (await fetch(url)).json();
maplocs = result.locations; maplocs = result.locations;
refreshData();
console.log(terrdata); console.log(terrdata);
console.log(maplocs); console.log(maplocs);
@ -154,9 +155,38 @@ function load_map_init(init_func) {
console.log("DB setup complete..."); console.log("DB setup complete...");
} }
} }
/** Saves map data. Meant to be called after territories and guilds are refreshed.
*
*/
function save_map_data() {
let add_promises = [];
let add_tx2 = mdb.transaction(['map_db'], 'readwrite');
let map_store = add_tx2.objectStore('map_db');
for (const terr of Object.entries(terrdata)) {
add_promises.push(map_store.add(terr[1],terr[0])); //WHY? WHY WOULD YOU STORE AS VALUE, KEY? WHY NOT KEEP THE NORMAL KEY, VALUE CONVENTION?
}
let add_tx3 = mdb.transaction(['maploc_db'], 'readwrite');
let maploc_store = add_tx3.objectStore('maploc_db');
for (const i in maplocs) {
add_promises.push(maploc_store.add(maplocs[i],i));
}
add_promises.push(add_tx2.complete);
add_promises.push(add_tx3.complete);
Promise.all(add_promises).then((values) => {
mdb.close();
init_map_maps();
init_func();
});
}
function init_map_maps() { function init_map_maps() {
for (const [terr,data] of Object.entries(terrdata)) { for (const [terr,data] of Object.entries(terrdata)) {
terrs.set(data.territory,data.location); terrs.set(data.territory,data.location);

18
map.js
View file

@ -1,3 +1,9 @@
/**TODO:
* Fix Claims (broken)
* Guild pull fails to update actual guilds on the map, which also do not save properly.
* Fix custom items saving reversed IDs in the wrong order.
*/
/* /*
* TESTING SECTION * TESTING SECTION
*/ */
@ -110,10 +116,12 @@ function init_map(){ //async just in case we need async stuff
map_elem.style.background = "#121516"; map_elem.style.background = "#121516";
try { try {
//refreshData();
pullguilds(); pullguilds();
//save_map_data();
} catch (error) { } catch (error) {
console.log(error); console.log(error);
let header = document.getElementsById("header"); let header = document.getElementById("header");
let warning = document.createElement("p"); let warning = document.createElement("p");
warning.classList.add("center"); warning.classList.add("center");
warning.style.color = "red"; warning.style.color = "red";
@ -195,7 +203,7 @@ function toggleButton(elemID) {
/** Pulls data from the API and overrides all of the current stuff with it. Do NOT call this too often. Called once, upon initialization. /** Pulls data from the API and overrides all of the current stuff with it. Do NOT call this too often. Called once, upon initialization.
* *
*/ */
async function refreshData() { //async just in case we need async stuff async function refreshData() {
terrs = new Map(); terrs = new Map();
claims = new Map(); claims = new Map();
guilds = []; guilds = [];
@ -207,6 +215,7 @@ async function refreshData() { //async just in case we need async stuff
.then(res => { //success .then(res => { //success
terrdata = Object.entries(res['territories']); terrdata = Object.entries(res['territories']);
console.log(terrdata); console.log(terrdata);
guilds = [];
for (const terr of terrdata) { for (const terr of terrdata) {
//terrs.set(terr[0], terr[1].location) //bounds shouldnt change //terrs.set(terr[0], terr[1].location) //bounds shouldnt change
claims.set(terr[0], terr[1].guild) claims.set(terr[0], terr[1].guild)
@ -214,8 +223,13 @@ async function refreshData() { //async just in case we need async stuff
guilds.push(terr[1].guild); guilds.push(terr[1].guild);
} }
} }
console.log("terrdata \n", terrdata);
console.log("claims \n", claims);
console.log("guilds \n", guilds);
pullguilds(); pullguilds();
console.log("Succesfully pulled and loaded territory data.") console.log("Succesfully pulled and loaded territory data.")
//save_guild_data();
console.log("Succesfully saved territory data.")
}) })
.catch(error => { //failure .catch(error => { //failure
console.log(error) console.log(error)