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">
<p></p>
<p class = "center smalltitle">Options</p>
<p></p>
<div class = "button create-button" style = "grid-item-1">
<p class = "">Fixed IDs:</p>
<div class = "button create-button">
<button class = "create-button" id = "create-button" onclick = "calculateCustom()">
Create
</button>
</div>
<div class = "button copy-button" style = "grid-item-3">
<div class = "button copy-button">
<button class = "copy-button" id = "copy-button" onclick = "copyCustom()">
Copy Link
</button>
</div>
<div class = "button set-button center" style = "grid-item-4">
<div class = "">Fixed IDs:</div>
<div class="button set-button center" id = "fixID">
<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 class = "button reset-button" style = "grid-item-2">
<div class = "button reset-button">
<button class = "reset-button" id = "reset-button" onclick = "resetFields()">
Reset
</button>
</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()">
Copy Hash
</button>
</div>
<div class="button set-button center" id = "fixID" style = "grid-item-5">
<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 class = "button save-button">
<button class = "save-button" id = "save-button" onclick = "saveAsJSON()">
JSON
</button>
</div>
<div class = "button set-button" style = "grid-item-7">
<div class = "button set-button">
<div class = "">Base Item: </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>
<datalist id = "base-list"></datalist>
</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')">
Use
</button>

View file

@ -708,4 +708,39 @@ function _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);

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"]
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"]
with open('test.json',"w") as outfile:
json.dump(atlas, outfile, indent = 2)
im1 = Image.open("./media/icons/maplocstemp/Content_GrindSpot.png")
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")
print(atlas)

View file

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

View file

@ -22,7 +22,18 @@ 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);
function clamp(num, low, high){
return Math.min(Math.max(num, low), high);