diff --git a/customizer.html b/customizer.html index a7d7269..ca7f339 100644 --- a/customizer.html +++ b/customizer.html @@ -997,7 +997,7 @@

-
+
@@ -1024,12 +1024,12 @@
-
+
@@ -1056,12 +1056,12 @@
-
+
diff --git a/customizer.js b/customizer.js index 052244b..aa49e58 100644 --- a/customizer.js +++ b/customizer.js @@ -134,14 +134,14 @@ function calculateCustom() { } statMap.set("fixID", true); - } else { //rolled IDs! + } else { //not fixed for (const input of inputs) { if (input.id.includes("-fixed")) { continue; } - //FIXs let id = input.id.replace("-choice", ""); let rollMap = ""; + let oppMap = ""; //If it's a minimum, it's -min if(id.includes("-min")) { @@ -570,16 +570,31 @@ function base_to_range(id) { let base = parseFloat(getValue(id+"-choice-base")); if(base) { //This version allows overriding of min and max. - if (base < 0) { - setValue(id+"-choice-min", Math.min(Math.round(neg_range[0]*base),-1)); + if (reversedIDs.includes(id)) { + 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 { - setValue(id+"-choice-min", Math.max(Math.round(pos_range[0]*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)); + if (base < 0) { + setValue(id+"-choice-min", Math.min(Math.round(neg_range[0]*base),-1)); + } else { + setValue(id+"-choice-min", Math.max(Math.round(pos_range[0]*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 if (!getValue(id+"-choice-min")) { if (base < 0) { diff --git a/load_map.js b/load_map.js index b69c69c..877b878 100644 --- a/load_map.js +++ b/load_map.js @@ -66,6 +66,7 @@ async function load_map(init_func) { result = await (await fetch(url)).json(); maplocs = result.locations; + refreshData(); console.log(terrdata); console.log(maplocs); @@ -154,9 +155,38 @@ function load_map_init(init_func) { 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() { for (const [terr,data] of Object.entries(terrdata)) { terrs.set(data.territory,data.location); diff --git a/map.js b/map.js index da43827..3857d57 100644 --- a/map.js +++ b/map.js @@ -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 */ @@ -110,10 +116,12 @@ function init_map(){ //async just in case we need async stuff map_elem.style.background = "#121516"; try { + //refreshData(); pullguilds(); + //save_map_data(); } catch (error) { console.log(error); - let header = document.getElementsById("header"); + let header = document.getElementById("header"); let warning = document.createElement("p"); warning.classList.add("center"); 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. * */ -async function refreshData() { //async just in case we need async stuff +async function refreshData() { terrs = new Map(); claims = new Map(); guilds = []; @@ -207,6 +215,7 @@ async function refreshData() { //async just in case we need async stuff .then(res => { //success terrdata = Object.entries(res['territories']); console.log(terrdata); + guilds = []; for (const terr of terrdata) { //terrs.set(terr[0], terr[1].location) //bounds shouldnt change 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); } } + console.log("terrdata \n", terrdata); + console.log("claims \n", claims); + console.log("guilds \n", guilds); pullguilds(); console.log("Succesfully pulled and loaded territory data.") + //save_guild_data(); + console.log("Succesfully saved territory data.") }) .catch(error => { //failure console.log(error)