translations moved to in-code arrays, copy/paste json

This commit is contained in:
ferricles 2021-04-29 18:30:59 -07:00
parent fd05469c8c
commit 767381cccf
3 changed files with 81 additions and 24 deletions

View file

@ -1835,8 +1835,8 @@
Copy Hash
</button>
</div>
<div class = "button save-button">
<button class = "save-button" id = "save-button" onclick = "saveAsJSON()">
<div class = "button json-button">
<button class = "json-button" id = "json-button" onclick = "saveAsJSON()">
JSON
</button>
</div>

View file

@ -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);

View file

@ -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);