Save CIs in a JSON file

This commit is contained in:
ferricles 2021-04-20 22:28:16 -07:00
parent b9cb72b635
commit 6ec18fa4b0
5 changed files with 69 additions and 31 deletions

View file

@ -1810,42 +1810,44 @@
<div class = "container button-container"> <div class = "container button-container">
<p></p> <p></p>
<p class = "center smalltitle">Options</p> <p class = "center smalltitle">Options</p>
<p></p> <p class = "">Fixed IDs:</p>
<div class = "button create-button" style = "grid-item-1"> <div class = "button create-button">
<button class = "create-button" id = "create-button" onclick = "calculateCustom()"> <button class = "create-button" id = "create-button" onclick = "calculateCustom()">
Create Create
</button> </button>
</div> </div>
<div class = "button copy-button" style = "grid-item-3"> <div class = "button copy-button">
<button class = "copy-button" id = "copy-button" onclick = "copyCustom()"> <button class = "copy-button" id = "copy-button" onclick = "copyCustom()">
Copy Link Copy Link
</button> </button>
</div> </div>
<div class = "button set-button center" style = "grid-item-4"> <div class="button set-button center" id = "fixID">
<div class = "">Fixed IDs:</div> <button class = "fixID-choice" id = "fixID-choice" onclick = "toggleButton('fixID-choice'); toggleYN('fixID-choice'); toggleFixed({textContent})" tabindex="">no</button>
<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 class = "button reset-button" style = "grid-item-2"> <div class = "button reset-button">
<button class = "reset-button" id = "reset-button" onclick = "resetFields()"> <button class = "reset-button" id = "reset-button" onclick = "resetFields()">
Reset Reset
</button> </button>
</div> </div>
<div class = "button copy-button-hash" style = "grid-item-6"> <div class = "button copy-button-hash">
<button class = "copy-button-hash" id = "copy-button-hash" onclick = "copyHash()"> <button class = "copy-button-hash" id = "copy-button-hash" onclick = "copyHash()">
Copy Hash Copy Hash
</button> </button>
</div> </div>
<div class="button set-button center" id = "fixID" style = "grid-item-5"> <div class = "button save-button">
<button class = "fixID-choice" id = "fixID-choice" onclick = "toggleButton('fixID-choice'); toggleYN('fixID-choice'); toggleFixed({textContent})" tabindex="">no</button> <button class = "save-button" id = "save-button" onclick = "saveAsJSON()">
<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> JSON
</button>
</div> </div>
<div class = "button set-button" style = "grid-item-7"> <div class = "button set-button">
<div class = "">Base Item: </div> <div class = "">Base Item: </div>
</div> </div>
<div class = "button set-button" style = "grid-item-8"> <div class = "button set-button">
<input class = "input" list = "base-list" id = "base-input" value = ""></input> <input class = "input" list = "base-list" id = "base-input" value = ""></input>
<datalist id = "base-list"></datalist> <datalist id = "base-list"></datalist>
</div> </div>
<div class = "button set-button" style = "grid-item-9"> <div class = "button set-button">
<button class = "set-button" id = "set-button" onclick = "useBaseItem('base-input')"> <button class = "set-button" id = "set-button" onclick = "useBaseItem('base-input')">
Use Use
</button> </button>

View file

@ -708,4 +708,39 @@ function _init_customizer() {
load_ing_init(init_customizer); load_ing_init(init_customizer);
} }
/** Saves the current user's item as a JSON file.
* Starts a JSON download.
*/
function saveAsJSON() {
let CI = {};
for (const [id, val] of player_custom_item.statMap) {
if (id === "minRolls" || id === "maxRolls") {
continue;
} else {
val ? CI[reversetranslations.get(id) ? reversetranslations.get(id) : id] = val : "" ;
}
}
if (player_custom_item.statMap.get("minRolls")) {
for (const [id, min] of player_custom_item.statMap.get("minRolls")) {
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];
}
}
}
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");
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
load_init(_init_customizer); load_init(_init_customizer);

View file

@ -1,14 +1,9 @@
from PIL import Image import requests
import json
response = requests.get("https://api.wynncraft.com/public_api.php?action=itemDB&search=atlas").json()
atlas = response['items'][0]
#imgs = ["Content_Dungeon.png", "Content_CorruptedDungeon.png", "Content_Quest.png", "Merchant_Emerald.png", "NPC_Blacksmith.png", "NPC_ItemIdentifier.png", "NPC_PowderMaster.png", "Merchant_Potion.png", "Merchant_Armour.png", "Merchant_Weapon.png", "Merchant_Liquid.png", "Merchant_Other.png", "Merchant_Scroll.png", "Merchant_Accessory.png", "Merchant_Tool.png", "painting.png", "Profession_Weaponsmithing.png", "Profession_Armouring.png", "Profession_Alchemism.png", "Profession_Jeweling.png", "Profession_Tailoring.png", "Profession_Scribing.png", "Profession_Cooking.png", "Profession_Woodworking.png", "Content_Miniquest.png", "Special_RootsOfCorruption.png", "Special_FastTravel.png", "Special_LightRealm.png", "Special_Rune.png", "Content_UltimateDiscovery.png", "Merchant_KeyForge.png", "NPC_GuildMaster.png", "Content_GrindSpot.png", "Content_Cave.png", "NPC_TradeMarket.png", "Content_BossAltar.png", "Content_Raid.png", "Merchant_Dungeon.png", "tnt.png", "Merchant_Seasail.png", "Merchant_Horse.png"] with open('test.json',"w") as outfile:
imgs = ["Merchant_Emerald.png", "NPC_Blacksmith.png", "NPC_ItemIdentifier.png", "NPC_PowderMaster.png", "Merchant_Potion.png", "Merchant_Armour.png", "Merchant_Weapon.png", "Merchant_Liquid.png", "Merchant_Other.png", "Merchant_Scroll.png", "Merchant_Accessory.png", "Merchant_Tool.png", "painting.png", "Profession_Weaponsmithing.png", "Profession_Armouring.png", "Profession_Alchemism.png", "Profession_Jeweling.png", "Profession_Tailoring.png", "Profession_Scribing.png", "Profession_Cooking.png", "Profession_Woodworking.png", "Special_RootsOfCorruption.png", "Special_LightRealm.png", "Content_UltimateDiscovery.png", "Merchant_KeyForge.png", "NPC_GuildMaster.png", "Content_GrindSpot.png", "NPC_TradeMarket.png", "Content_Raid.png", "Merchant_Dungeon.png", "tnt.png", "Merchant_Seasail.png", "Merchant_Horse.png"] json.dump(atlas, outfile, indent = 2)
im1 = Image.open("./media/icons/maplocstemp/Content_GrindSpot.png") print(atlas)
for name in imgs:
img = im1.copy()
img.save("./media/icons/maplocstemp/" + name, "PNG")
# img = Image.new(mode = "RGB", size = (32,32))
# img.putalpha(0)
# for name in imgs:
# img.save("./media/icons/maplocstemp/" + name, "PNG")

View file

@ -1,5 +1,3 @@
Mapping from API name to shortened names
"name": "name", "name": "name",
"displayName": "displayName", "displayName": "displayName",
"tier": "tier", "tier": "tier",
@ -68,7 +66,6 @@ Mapping from API name to shortened names
"identified": "fixID", "identified": "fixID",
"skin": "skin", "skin": "skin",
"category": "category", "category": "category",
"spellCostPct1": "spPct1", "spellCostPct1": "spPct1",
"spellCostRaw1": "spRaw1", "spellCostRaw1": "spRaw1",
"spellCostPct2": "spPct2", "spellCostPct2": "spPct2",
@ -77,12 +74,10 @@ Mapping from API name to shortened names
"spellCostRaw3": "spRaw3", "spellCostRaw3": "spRaw3",
"spellCostPct4": "spPct4", "spellCostPct4": "spPct4",
"spellCostRaw4": "spRaw4", "spellCostRaw4": "spRaw4",
"rainbowSpellDamageRaw": "rainbowRaw", "rainbowSpellDamageRaw": "rainbowRaw",
"sprint": "sprint", "sprint": "sprint",
"sprintRegen": "sprintReg", "sprintRegen": "sprintReg",
"jumpHeight": "jh", "jumpHeight": "jh",
"lootQuality": "lq", "lootQuality": "lq",
"gatherXpBonus": "gXp", "gatherXpBonus": "gXp",
"gatherSpeed": "gSpd", "gatherSpeed": "gSpd",

View file

@ -22,7 +22,18 @@ let itemTypes = armorTypes.concat(accessoryTypes).concat(weaponTypes);
let elementIcons = ["\u2724","\u2726", "\u2749", "\u2739", "\u274b" ]; let elementIcons = ["\u2724","\u2726", "\u2749", "\u2739", "\u274b" ];
let skpReqs = skp_order.map(x => x + "Req"); 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);
function clamp(num, low, high){ function clamp(num, low, high){
return Math.min(Math.max(num, low), high); return Math.min(Math.max(num, low), high);