From 767381cccfc621b6f44c15abddc49a85408557db Mon Sep 17 00:00:00 2001 From: ferricles Date: Thu, 29 Apr 2021 18:30:59 -0700 Subject: [PATCH] translations moved to in-code arrays, copy/paste json --- customizer.html | 4 +-- customizer.js | 74 ++++++++++++++++++++++++++++++++++++++++++------- utils.js | 27 ++++++++++-------- 3 files changed, 81 insertions(+), 24 deletions(-) diff --git a/customizer.html b/customizer.html index 17eb6ef..910e230 100644 --- a/customizer.html +++ b/customizer.html @@ -1835,8 +1835,8 @@ Copy Hash -
-
diff --git a/customizer.js b/customizer.js index 411cce9..797dd44 100644 --- a/customizer.js +++ b/customizer.js @@ -714,7 +714,9 @@ function _init_customizer() { function saveAsJSON() { let CI = {}; for (const [id, val] of player_custom_item.statMap) { - if (id === "minRolls" || id === "maxRolls") { + console.log(id); + let skipIds = ["minRolls", "maxRolls", "skillpoints", "reqs", "custom", "crafted", "restrict", "hash", "nDam_", "tDam_", "eDam_", "wDam_", "fDam_", "aDam_"] + if (skipIds.includes(id)) { continue; } else { val ? CI[reversetranslations.get(id) ? reversetranslations.get(id) : id] = val : "" ; @@ -725,22 +727,74 @@ function saveAsJSON() { const max = player_custom_item.statMap.get("maxRolls").get(id); if (min && max) { console.log(reversetranslations); - CI[reversetranslations.get(id) ? reversetranslations.get(id) : id] = [min,max]; + let base = full_range_to_base(min, max); + if (base === null) { + CI[reversetranslations.get(id) ? reversetranslations.get(id) : id] = [min,max]; + } else if (base) { + CI[reversetranslations.get(id) ? reversetranslations.get(id) : id] = base; + } } } } console.log(CI); //yuck - let filename = player_custom_item.statMap.get("displayName"); - var element = document.createElement('a'); - element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(JSON.stringify(CI, null, 2))); - element.setAttribute('download', filename + ".json"); + copyTextToClipboard(JSON.stringify(CI, null, 0)); + document.getElementById("json-button").textContent = "Copied!"; + // let filename = player_custom_item.statMap.get("displayName"); + // var element = document.createElement('a'); + // element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(JSON.stringify(CI, null, 0))); + // element.setAttribute('download', filename + ".json"); - element.style.display = 'none'; - document.body.appendChild(element); - element.click(); - document.body.removeChild(element); + // element.style.display = 'none'; + // document.body.appendChild(element); + // element.click(); + // document.body.removeChild(element); } +/**Helper function + * Takes min, max, attempts to get the correct base. Returns null if no possible base or no base found. + */ +function full_range_to_base(min, max) { + //checks against the range + function checkBase(b, min, max) { + if ( b > 0 ) { + if (Math.round(pos_range[0] * b) == min && Math.round(pos_range[1] * b ) == max) { + return true; + } else { + return false; + } + } else { + if (Math.round(neg_range[0] * b) == min && Math.round(neg_range[1] * b ) == max) { + return true; + } else { + return false; + } + } + } + if (min && max && min/max < 0) { + return null; + } else if (min == max) { + //0 shouldn't save but this is for -1 and 1 + return min; + } else { + //both should be same sign - now do math + if (min < 0) { + + } else { + let minPossible = (max - 0.5) / pos_range[1]; + let maxPossible = (max + 0.5) / pos_range[1]; + for (let i = Math.floor(minPossible); i < Math.ceil(maxPossible); i++) { + if (checkBase(i, min, max)) { + return i; + } + } + + return null; + } + + } +} + + load_init(_init_customizer); diff --git a/utils.js b/utils.js index abfaa89..2cb3e53 100644 --- a/utils.js +++ b/utils.js @@ -22,18 +22,21 @@ let itemTypes = armorTypes.concat(accessoryTypes).concat(weaponTypes); let elementIcons = ["\u2724","\u2726", "\u2749", "\u2739", "\u274b" ]; let skpReqs = skp_order.map(x => x + "Req"); -//File reading for ID translations for JSON purposes -let reversetranslations; -let translations; -function setRevTrans(revTransText) { - reversetranslations = new Map(revTransText.replaceAll(" ", "").replaceAll("\"", "").replaceAll("\n","").replaceAll("\r","").split(",").map(x => x.split(":").reverse())) -} -function setTrans(transText) { - translations = new Map(transText.replaceAll(" ", "").replaceAll("\"", "").replaceAll("\n","").replaceAll("\r","").split(",").map(x => x.split(":"))) -} -fetch('translations.txt').then(response => response.text()).then(data => {setRevTrans(data)}); -fetch('translations.txt').then(response => response.text()).then(data => {setTrans(data);}); -console.log(translations); +// //File reading for ID translations for JSON purposes +// let reversetranslations; +// let translations; +// function setRevTrans(revTransText) { +// reversetranslations = new Map(revTransText.replaceAll(" ", "").replaceAll("\"", "").replaceAll("\n","").replaceAll("\r","").split(",").map(x => x.split(":").reverse())) +// } +// function setTrans(transText) { +// translations = new Map(transText.replaceAll(" ", "").replaceAll("\"", "").replaceAll("\n","").replaceAll("\r","").split(",").map(x => x.split(":"))) +// } +// fetch('translations.txt').then(response => response.text()).then(data => {setRevTrans(data)}); +// fetch('translations.txt').then(response => response.text()).then(data => {setTrans(data);}); +// console.log(translations); +let translationsArray = [["name", "name"],["displayName", "displayName"],["tier", "tier"],["set", "set"],["sockets", "slots"],["type", "type"],["dropType", "drop"],["quest", "quest"],["restrictions", "restrict"],["damage", "nDam"],["fireDamage", "fDam"],["waterDamage", "wDam"],["airDamage", "aDam"],["thunderDamage", "tDam"],["earthDamage", "eDam"],["attackSpeed", "atkSpd"],["health", "hp"],["fireDefense", "fDef"],["waterDefense", "wDef"],["airDefense", "aDef"],["thunderDefense", "tDef"],["earthDefense", "eDef"],["level", "lvl"],["classRequirement", "classReq"],["strength", "strReq"],["dexterity", "dexReq"],["intelligence", "intReq"],["agility", "agiReq"],["defense", "defReq"],["healthRegen", "hprPct"],["manaRegen", "mr"],["spellDamage", "sdPct"],["damageBonus", "mdPct"],["lifeSteal", "ls"],["manaSteal", "ms"],["xpBonus", "xpb"],["lootBonus", "lb"],["reflection", "ref"],["strengthPoints", "str"],["dexterityPoints", "dex"],["intelligencePoints", "int"],["agilityPoints", "agi"],["defensePoints", "def"],["thorns", "thorns"],["exploding", "expd"],["speed", "spd"],["attackSpeedBonus", "atkTier"],["poison", "poison"],["healthBonus", "hpBonus"],["soulPoints", "spRegen"],["emeraldStealing", "eSteal"],["healthRegenRaw", "hprRaw"],["spellDamageRaw", "sdRaw"],["damageBonusRaw", "mdRaw"],["bonusFireDamage", "fDamPct"],["bonusWaterDamage", "wDamPct"],["bonusAirDamage", "aDamPct"],["bonusThunderDamage", "tDamPct"],["bonusEarthDamage", "eDamPct"],["bonusFireDefense", "fDefPct"],["bonusWaterDefense", "wDefPct"],["bonusAirDefense", "aDefPct"],["bonusThunderDefense", "tDefPct"],["bonusEarthDefense", "eDefPct"],["accessoryType", "type"],["identified", "fixID"],["skin", "skin"],["category", "category"],["spellCostPct1", "spPct1"],["spellCostRaw1", "spRaw1"],["spellCostPct2", "spPct2"],["spellCostRaw2", "spRaw2"],["spellCostPct3", "spPct3"],["spellCostRaw3", "spRaw3"],["spellCostPct4", "spPct4"],["spellCostRaw4", "spRaw4"],["rainbowSpellDamageRaw", "rainbowRaw"],["sprint", "sprint"],["sprintRegen", "sprintReg"],["jumpHeight", "jh"],["lootQuality", "lq"],["gatherXpBonus", "gXp"],["gatherSpeed", "gSpd"]]; +const translations = new Map(translationsArray) +const reversetranslations = new Map(translationsArray.map(x => x.reverse())); function clamp(num, low, high){ return Math.min(Math.max(num, low), high);