This commit is contained in:
b 2021-01-06 06:48:41 -06:00
parent e3dbc5e90a
commit e794b51fcf
12 changed files with 72171 additions and 71646 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
*.swp

20
build.js Normal file
View file

@ -0,0 +1,20 @@
//Turns the input amount of skill points into a 3-decimal precision percentage.
function skillPointsToPercentage(skp){
if (skp<=0){
return 0.0;
}else if(skp>=150){
return 0.808;
}else{
return(-0.0000000066695* Math.pow(Math.E, -0.00924033 * skp + 18.9) + 1.0771);
//return(-0.0000000066695* Math.pow(Math.E, -0.00924033 * skp + 18.9) + 1.0771).toFixed(3);
}
}
for (i = 0; i < 151; i++) {
console.log(i, ", ",skillPointsToPercentage(i));
}
class Build{
}

143256
clean.json

File diff suppressed because it is too large Load diff

File diff suppressed because one or more lines are too long

View file

@ -4,10 +4,22 @@ with open("dump.json", "r") as infile:
data = json.loads(infile.read()) data = json.loads(infile.read())
items = data["items"] items = data["items"]
del data["request"]
translate_mappings = { translate_mappings = {
#"name": "name",
#"displayName": "displayName",
#"tier": "tier",
#"set": "set",
"sockets": "slots", "sockets": "slots",
#"type": "type",
# UNUSED? "armorType": "armorType",
"armorColor": "color",
"addedLore": "lore", "addedLore": "lore",
#"material": "material",
"dropType": "drop",
#"quest": "quest",
"restrictions": "restrict",
"damage": "nDam", "damage": "nDam",
"fireDamage": "fDam", "fireDamage": "fDam",
"waterDamage": "wDam", "waterDamage": "wDam",
@ -30,8 +42,8 @@ translate_mappings = {
"defense": "defReq", "defense": "defReq",
"healthRegen": "hprPct", "healthRegen": "hprPct",
"manaRegen": "mr", "manaRegen": "mr",
"spellDamage": "spellPct", "spellDamage": "sdPct",
"damageBonus": "meleePct", "damageBonus": "mdPct",
"lifeSteal": "ls", "lifeSteal": "ls",
"manaSteal": "ms", "manaSteal": "ms",
"xpBonus": "xpb", "xpBonus": "xpb",
@ -45,14 +57,14 @@ translate_mappings = {
#"thorns": "thorns", #"thorns": "thorns",
#"exploding": "expoding", #"exploding": "expoding",
"speed": "spd", "speed": "spd",
"attackSpeedBonus": "attackTier", "attackSpeedBonus": "atkTier",
#"poison": "poison", #"poison": "poison",
"healthBonus": "hpBonus", "healthBonus": "hpBonus",
"soulPoints": "spRegen", "soulPoints": "spRegen",
"emeraldStealing": "stealing", "emeraldStealing": "eSteal",
"healthRegenRaw": "hprRaw", "healthRegenRaw": "hprRaw",
"spellDamageRaw": "spellRaw", "spellDamageRaw": "sdRaw",
"damageBonusRaw": "meleeRaw", "damageBonusRaw": "mdRaw",
"bonusFireDamage": "fDamPct", "bonusFireDamage": "fDamPct",
"bonusWaterDamage": "wDamPct", "bonusWaterDamage": "wDamPct",
"bonusAirDamage": "aDamPct", "bonusAirDamage": "aDamPct",
@ -63,22 +75,28 @@ translate_mappings = {
"bonusAirDefense": "aDefPct", "bonusAirDefense": "aDefPct",
"bonusThunderDefense": "tDefPct", "bonusThunderDefense": "tDefPct",
"bonusEarthDefense": "eDefPct", "bonusEarthDefense": "eDefPct",
"accessoryType": "type",
"identified": "fixID", "identified": "fixID",
#"skin": "skin",
#"category": "category",
"spellCostPct1": "spellPct1", "spellCostPct1": "spPct1",
"spellCostRaw1": "spellRaw1", "spellCostRaw1": "spRaw1",
"spellCostPct2": "spellPct2", "spellCostPct2": "spPct2",
"spellCostRaw2": "spellRaw2", "spellCostRaw2": "spRaw2",
"spellCostPct3": "spellPct3", "spellCostPct3": "spPct3",
"spellCostRaw3": "spellRaw3", "spellCostRaw3": "spRaw3",
"spellCostPct4": "spellPct4", "spellCostPct4": "spPct4",
"spellCostRaw4": "spellRaw4", "spellCostRaw4": "spRaw4",
"rainbowSpellDamageRaw": "rainbowSDRaw", "rainbowSpellDamageRaw": "rainbowRaw",
"sprint": "sprint", "sprint": "sprint",
"sprintRegen": "sprintReg", "sprintRegen": "sprintReg",
"jumpHeight": "jh", "jumpHeight": "jh",
"lootQuality": "lq", "lootQuality": "lq",
"gatherXpBonus": "gXp",
"gatherSpeed": "gSpd",
} }
delete_keys = [ delete_keys = [
@ -98,6 +116,8 @@ for item in items:
item[v] = item[k] item[v] = item[k]
del item[k] del item[k]
item["type"] = item["type"].lower()
with open("clean.json", "w") as outfile: with open("clean.json", "w") as outfile:
outfile.write(json.dumps(data, indent=2)) outfile.write(json.dumps(data, indent=2))
with open("compress.json", "w") as outfile: with open("compress.json", "w") as outfile:

View file

@ -4,4 +4,4 @@ import json
response = requests.get("https://api.wynncraft.com/public_api.php?action=itemDB&category=all") response = requests.get("https://api.wynncraft.com/public_api.php?action=itemDB&category=all")
with open("dump.json", "w") as outfile: with open("dump.json", "w") as outfile:
of.write(json.dumps(response.json())) outfile.write(json.dumps(response.json()))

145
index.html Normal file
View file

@ -0,0 +1,145 @@
<!DOCTYPE html>
<html scroll-behavior="smooth">
<head>
<link rel="stylesheet" href="styles.css">
<link rel="icon" href="favicon.png">
<link rel="manifest" href="manifest.json">
<title>Wynn Clientside</title>
</head>
<body>
<div class="header">
Wynn build calculator
</div>
<div class="equipment">
<div class="center" style="grid-column:1;grid-row:1">
<div>
<label for="helmet-choice">Helmet:</label>
<input list="helmet-items" id="helmet-choice" name="helmet-choice" />
<datalist id="helmet-items">
</datalist>
</div>
<div id="helmet-slots">
X slots
</div>
<div>
<label for="helmet-powder">Powdering:</label>
<input type="text" id="helmet-powder" name="helmet-powder" />
</div>
</div>
<div class="center" style="grid-column:2;grid-row:1">
<div>
<label for="chestplate-choice">Chestplate:</label>
<input list="chestplate-items" id="chestplate-choice" name="chestplate-choice" />
<datalist id="chestplate-items">
</datalist>
</div>
<div id="chestplate-slots">
X slots
</div>
<div>
<label for="chestplate-powder">Powdering:</label>
<input type="text" id="chestplate-powder" name="chestplate-powder" />
</div>
</div>
<div class="center" style="grid-column:3;grid-row:1">
<div>
<label for="leggings-choice">Leggings:</label>
<input list="leggings-items" id="leggings-choice" name="leggings-choice" />
<datalist id="leggings-items">
</datalist>
</div>
<div id="leggings-slots">
X slots
</div>
<div>
<label for="leggings-powder">Powdering:</label>
<input type="text" id="leggings-powder" name="leggings-powder" />
</div>
</div>
<div class="center" style="grid-column:4;grid-row:1">
<div id="boots">
<label for="boots-choice">Boots:</label>
<input list="boots-items" id="boots-choice" name="boots-choice" />
<datalist id="boots-items">
</datalist>
</div>
<div id="boots-slots">
X slots
</div>
<div>
<label for="boots-powder">Powdering:</label>
<input type="text" id="boots-powder" name="boots-powder" />
</div>
</div>
<div class="center" style="grid-column:1;grid-row:2">
<label for="ring1-choice">Ring 1:</label>
<input list="ring1-items" id="ring1-choice" name="ring1-choice" />
<datalist id="ring1-items">
</datalist>
</div>
<div class="center" style="grid-column:2;grid-row:2">
<label for="ring2-choice">Ring 2:</label>
<input list="ring2-items" id="ring2-choice" name="ring2-choice" />
<datalist id="ring2-items">
</datalist>
</div>
<div class="center" style="grid-column:3;grid-row:2">
<label for="bracelet-choice">Bracelet:</label>
<input list="bracelet-items" id="bracelet-choice" name="bracelet-choice" />
<datalist id="bracelet-items">
</datalist>
</div>
<div class="center" style="grid-column:4;grid-row:2">
<label for="necklace-choice">Necklace:</label>
<input list="necklace-items" id="necklace-choice" name="necklace-choice" />
<datalist id="necklace-items">
</datalist>
</div>
<div class="center" style="grid-column:1;grid-row:3">
<label for="weapon-choice">Weapon:</label>
<input list="weapon-items" id="weapon-choice" name="weapon-choice" />
<datalist id="weapon-items">
</datalist>
</div>
<div class="center" style="grid-column:2;grid-row:3">
<div id="weapon-slots">
X slots
</div>
<div>
<label for="weapon-powder">Weapon powder:</label>
<input type="text" id="weapon-powder" name="weapon-powder" />
</div>
</div>
<div class="center" style="grid-column:3;grid-row:3">
Calculate
</div>
<div class="center" style="grid-column:4;grid-row:3">
Reset
</div>
</div>
<div class="skillpoints">
<div class="center" style="grid-column:1;grid-row:1">
<label for="str-skp">Strength:</label>
<input type="text" id="str-skp" name="str-skp" />
</div>
<div class="center" style="grid-column:2;grid-row:1">
<label for="dex-skp">Dexterity:</label>
<input type="text" id="dex-skp" name="dex-skp" />
</div>
<div class="center" style="grid-column:3;grid-row:1">
<label for="int-skp">Intelligence:</label>
<input type="text" id="int-skp" name="int-skp" />
</div>
<div class="center" style="grid-column:4;grid-row:1">
<label for="def-skp">Defense:</label>
<input type="text" id="def-skp" name="def-skp" />
</div>
<div class="center" style="grid-column:5;grid-row:1">
<label for="agi-skp">Agility:</label>
<input type="text" id="agi-skp" name="agi-skp" />
</div>
</div>
<script src="test.js"></script>
</body>
</html>

4
manifest.json Normal file
View file

@ -0,0 +1,4 @@
{
"display": "standalone",
"orientation": "portrait"
}

4
script.py Normal file
View file

@ -0,0 +1,4 @@
#A workspace for processing info/one-time operations
import math
for i in range(151):
print(-0.0000000066695* math.exp(-0.00924033 * i + 18.9) + 1.0771)

152
skillpoints.csv Normal file
View file

@ -0,0 +1,152 @@
assigned,ingame,calculated
0,0.0,-7.338606692330885e-06
1,0.01,0.009899646251607663
2,0.02,0.019715508948295213
3,0.029,0.029441087603991223
4,0.039,0.03907721263048747
5,0.049,0.048624706801628115
6,0.058,0.05808438532357796
7,0.067,0.06745705590441875
8,0.077,0.0767435188231318
9,0.086,0.08594456699790476
10,0.095,0.09506098605385105
11,0.104,0.10409355439008561
12,0.113,0.11304304324618386
13,0.122,0.12191021676804825
14,0.131,0.13069583207313296
15,0.139,0.13940063931510382
16,0.148,0.1480253817478835
17,0.157,0.1565707957891258
18,0.165,0.16503761108307513
19,0.173,0.17342655056288003
20,0.182,0.18173833051231592
21,0.19,0.189973660626943
22,0.198,0.19813324407471433
23,0.206,0.20621777755599702
24,0.214,0.21422795136307204
25,0.222,0.222164449439068
26,0.23,0.23002794943637184
27,0.238,0.23781912277447081
28,0.246,0.24553863469729353
29,0.253,0.2531871443300058
30,0.261,0.26076530473530024
31,0.268,0.26827376296914185
32,0.276,0.27571316013602587
33,0.283,0.2830841314437169
34,0.29,0.2903873062574822
35,0.298,0.29762330815384075
36,0.305,0.3047927549737901
37,0.312,0.3118962588755717
38,0.319,0.3189344263869339
39,0.326,0.32590785845693104
40,0.333,0.3328171505072183
41,0.34,0.3396628924829026
42,0.346,0.34644566890291206
43,0.353,0.3531660589099016
44,0.36,0.3598246363197136
45,0.366,0.3664219696703567
46,0.373,0.37295862227056087
47,0.379,0.3794351522478696
48,0.386,0.3858521125963057
49,0.392,0.3922100512235729
50,0.399,0.3985095109978487
51,0.405,0.40475102979413424
52,0.411,0.41093514054017843
53,0.417,0.4170623712619905
54,0.423,0.42313324512891115
55,0.429,0.42914828049829257
56,0.435,0.4351079909597534
57,0.441,0.44101288537904015
58,0.447,0.4468634679414628
59,0.453,0.45266023819495316
60,0.458,0.45840369109271695
61,0.464,0.46409431703549175
62,0.47,0.469732601913429
63,0.475,0.47531902714756813
64,0.481,0.4808540697309509
65,0.486,0.4863382022693453
66,0.492,0.4917718930216064
67,0.497,0.49715560593964647
68,0.503,0.5024898007080566
69,0.508,0.5077749327833555
70,0.513,0.5130114534328759
71,0.518,0.5181998097733035
72,0.523,0.5233404448088418
73,0.528,0.528433797469046
74,0.534,0.5334803026462964
75,0.539,0.5384803912329396
76,0.543,0.5434344901580676
77,0.548,0.5483430224239791
78,0.553,0.5532064071422955
79,0.558,0.558025059569744
80,0.563,0.5627993911436221
81,0.568,0.5675298095169159
82,0.572,0.5722167185931156
83,0.577,0.5768605185606984
84,0.581,0.5814616059273056
85,0.586,0.5860203735535872
86,0.591,0.5905372106867532
87,0.595,0.5950125029938078
88,0.599,0.5994466325944774
89,0.604,0.6038399780938442
90,0.608,0.608192914614663
91,0.613,0.6125058138293982
92,0.617,0.6167790439919543
93,0.621,0.6210129699691267
94,0.625,0.6252079532717454
95,0.629,0.6293643520855481
96,0.633,0.6334825213017619
97,0.638,0.6375628125474104
98,0.642,0.6416055742153288
99,0.646,0.6456111514939162
100,0.65,0.6495798863966094
101,0.654,0.6535121177910819
102,0.657,0.6574081814281856
103,0.661,0.6612684099706092
104,0.665,0.6650931330212878
105,0.669,0.6688826771515435
106,0.673,0.6726373659289748
107,0.676,0.676357519945076
108,0.68,0.6800434568426164
109,0.684,0.6836954913427596
110,0.687,0.6873139352719362
111,0.691,0.6908990975884723
112,0.694,0.6944512844089634
113,0.698,0.697970799034416
114,0.701,0.7014579419761423
115,0.705,0.7049130109814256
116,0.708,0.7083363010589336
117,0.712,0.711728104503914
118,0.715,0.7150887109231503
119,0.718,0.7184184072596882
120,0.722,0.7217174778173412
121,0.725,0.724986204284958
122,0.728,0.72822486576048
123,0.731,0.7314337387747685
124,0.735,0.7346130973152214
125,0.738,0.73776321284916
126,0.741,0.7408843543470132
127,0.744,0.7439767883052819
128,0.747,0.7470407787692924
129,0.75,0.7500765873557466
130,0.753,0.7530844732750526
131,0.756,0.7560646933534624
132,0.759,0.7590175020549981
133,0.762,0.7619431515031838
134,0.765,0.7648418915025662
135,0.768,0.7677139695600486
136,0.771,0.7705596309060228
137,0.773,0.7733791185153069
138,0.776,0.7761726731278962
139,0.779,0.7789405332695114
140,0.782,0.78168293527197
141,0.784,0.7844001132933628
142,0.787,0.7870922993380516
143,0.79,0.7897597232764726
144,0.792,0.7924026128647677
145,0.795,0.7950211937642291
146,0.798,0.7976156895605719
147,0.8,0.8001863217830184
148,0.803,0.8027333099232168
149,0.805,0.8052568714539818
150,0.808,0.8077572218478628
1 assigned ingame calculated
2 0 0.0 -7.338606692330885e-06
3 1 0.01 0.009899646251607663
4 2 0.02 0.019715508948295213
5 3 0.029 0.029441087603991223
6 4 0.039 0.03907721263048747
7 5 0.049 0.048624706801628115
8 6 0.058 0.05808438532357796
9 7 0.067 0.06745705590441875
10 8 0.077 0.0767435188231318
11 9 0.086 0.08594456699790476
12 10 0.095 0.09506098605385105
13 11 0.104 0.10409355439008561
14 12 0.113 0.11304304324618386
15 13 0.122 0.12191021676804825
16 14 0.131 0.13069583207313296
17 15 0.139 0.13940063931510382
18 16 0.148 0.1480253817478835
19 17 0.157 0.1565707957891258
20 18 0.165 0.16503761108307513
21 19 0.173 0.17342655056288003
22 20 0.182 0.18173833051231592
23 21 0.19 0.189973660626943
24 22 0.198 0.19813324407471433
25 23 0.206 0.20621777755599702
26 24 0.214 0.21422795136307204
27 25 0.222 0.222164449439068
28 26 0.23 0.23002794943637184
29 27 0.238 0.23781912277447081
30 28 0.246 0.24553863469729353
31 29 0.253 0.2531871443300058
32 30 0.261 0.26076530473530024
33 31 0.268 0.26827376296914185
34 32 0.276 0.27571316013602587
35 33 0.283 0.2830841314437169
36 34 0.29 0.2903873062574822
37 35 0.298 0.29762330815384075
38 36 0.305 0.3047927549737901
39 37 0.312 0.3118962588755717
40 38 0.319 0.3189344263869339
41 39 0.326 0.32590785845693104
42 40 0.333 0.3328171505072183
43 41 0.34 0.3396628924829026
44 42 0.346 0.34644566890291206
45 43 0.353 0.3531660589099016
46 44 0.36 0.3598246363197136
47 45 0.366 0.3664219696703567
48 46 0.373 0.37295862227056087
49 47 0.379 0.3794351522478696
50 48 0.386 0.3858521125963057
51 49 0.392 0.3922100512235729
52 50 0.399 0.3985095109978487
53 51 0.405 0.40475102979413424
54 52 0.411 0.41093514054017843
55 53 0.417 0.4170623712619905
56 54 0.423 0.42313324512891115
57 55 0.429 0.42914828049829257
58 56 0.435 0.4351079909597534
59 57 0.441 0.44101288537904015
60 58 0.447 0.4468634679414628
61 59 0.453 0.45266023819495316
62 60 0.458 0.45840369109271695
63 61 0.464 0.46409431703549175
64 62 0.47 0.469732601913429
65 63 0.475 0.47531902714756813
66 64 0.481 0.4808540697309509
67 65 0.486 0.4863382022693453
68 66 0.492 0.4917718930216064
69 67 0.497 0.49715560593964647
70 68 0.503 0.5024898007080566
71 69 0.508 0.5077749327833555
72 70 0.513 0.5130114534328759
73 71 0.518 0.5181998097733035
74 72 0.523 0.5233404448088418
75 73 0.528 0.528433797469046
76 74 0.534 0.5334803026462964
77 75 0.539 0.5384803912329396
78 76 0.543 0.5434344901580676
79 77 0.548 0.5483430224239791
80 78 0.553 0.5532064071422955
81 79 0.558 0.558025059569744
82 80 0.563 0.5627993911436221
83 81 0.568 0.5675298095169159
84 82 0.572 0.5722167185931156
85 83 0.577 0.5768605185606984
86 84 0.581 0.5814616059273056
87 85 0.586 0.5860203735535872
88 86 0.591 0.5905372106867532
89 87 0.595 0.5950125029938078
90 88 0.599 0.5994466325944774
91 89 0.604 0.6038399780938442
92 90 0.608 0.608192914614663
93 91 0.613 0.6125058138293982
94 92 0.617 0.6167790439919543
95 93 0.621 0.6210129699691267
96 94 0.625 0.6252079532717454
97 95 0.629 0.6293643520855481
98 96 0.633 0.6334825213017619
99 97 0.638 0.6375628125474104
100 98 0.642 0.6416055742153288
101 99 0.646 0.6456111514939162
102 100 0.65 0.6495798863966094
103 101 0.654 0.6535121177910819
104 102 0.657 0.6574081814281856
105 103 0.661 0.6612684099706092
106 104 0.665 0.6650931330212878
107 105 0.669 0.6688826771515435
108 106 0.673 0.6726373659289748
109 107 0.676 0.676357519945076
110 108 0.68 0.6800434568426164
111 109 0.684 0.6836954913427596
112 110 0.687 0.6873139352719362
113 111 0.691 0.6908990975884723
114 112 0.694 0.6944512844089634
115 113 0.698 0.697970799034416
116 114 0.701 0.7014579419761423
117 115 0.705 0.7049130109814256
118 116 0.708 0.7083363010589336
119 117 0.712 0.711728104503914
120 118 0.715 0.7150887109231503
121 119 0.718 0.7184184072596882
122 120 0.722 0.7217174778173412
123 121 0.725 0.724986204284958
124 122 0.728 0.72822486576048
125 123 0.731 0.7314337387747685
126 124 0.735 0.7346130973152214
127 125 0.738 0.73776321284916
128 126 0.741 0.7408843543470132
129 127 0.744 0.7439767883052819
130 128 0.747 0.7470407787692924
131 129 0.75 0.7500765873557466
132 130 0.753 0.7530844732750526
133 131 0.756 0.7560646933534624
134 132 0.759 0.7590175020549981
135 133 0.762 0.7619431515031838
136 134 0.765 0.7648418915025662
137 135 0.768 0.7677139695600486
138 136 0.771 0.7705596309060228
139 137 0.773 0.7733791185153069
140 138 0.776 0.7761726731278962
141 139 0.779 0.7789405332695114
142 140 0.782 0.78168293527197
143 141 0.784 0.7844001132933628
144 142 0.787 0.7870922993380516
145 143 0.79 0.7897597232764726
146 144 0.792 0.7924026128647677
147 145 0.795 0.7950211937642291
148 146 0.798 0.7976156895605719
149 147 0.8 0.8001863217830184
150 148 0.803 0.8027333099232168
151 149 0.805 0.8052568714539818
152 150 0.808 0.8077572218478628

24
styles.css Normal file
View file

@ -0,0 +1,24 @@
.header {
padding: 2%;
text-align: center;
}
.equipment {
padding: 4%;
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 25px;
grid-auto-rows: minmax(60px, auto);
}
.skillpoints {
padding: 4%;
display: grid;
grid-template-columns: repeat(5, 1fr);
gap: 5px;
grid-auto-rows: minmax(60px, auto);
}
.center {
text-align: center;
}

157
test.js Normal file
View file

@ -0,0 +1,157 @@
const DB_VERSION = 1;
// @See https://github.com/mdn/learning-area/blob/master/javascript/apis/client-side-storage/indexeddb/video-store/index.js
//const item_fields = [ "name", "displayName", "tier", "set", "slots", "type", "armorType", "color", "lore", "material", "drop", "quest", "restrict", "nDam", "fDam", "wDam", "aDam", "tDam", "eDam", "atkSpd", "hp", "fDef", "wDef", "aDef", "tDef", "eDef", "lvl", "classReq", "strReq", "dexReq", "intReq", "agiReq", "defReq", "hprPct", "mr", "sdPct", "mdPct", "ls", "ms", "xpb", "lb", "ref", "str", "dex", "int", "agi", "def", "thorns", "expoding", "spd", "atkTier", "poison", "hpBonus", "spRegen", "eSteal", "hprRaw", "sdRaw", "mdRaw", "fDamPct", "wDamPct", "aDamPct", "tDamPct", "eDamPct", "fDefPct", "wDefPct", "aDefPct", "tDefPct", "eDefPct", "accessoryType", "fixID", "skin", "category", "spPct1", "spRaw1", "spPct2", "spRaw2", "spPct3", "spRaw3", "spPct4", "spRaw4", "rainbowRaw", "sprint", "sprintReg", "jh", "lq", "gXp", "gSpd" ]
let db;
let items;
let reload = false;
let armorTypes = [ "helmet", "chestplate", "leggings", "boots" ];
let accessoryTypes = [ "ring", "bracelet", "necklace" ];
let weaponTypes = [ "wand", "spear", "bow", "dagger", "relik" ];
let itemTypes = armorTypes.concat(accessoryTypes).concat(weaponTypes);
let itemLists = new Map();
for (const it of itemTypes) {
itemLists.set(it, []);
}
let itemMap = new Map();
function populateItemList(type) {
let item_list = document.getElementById(type+"-items");
for (const item of itemLists.get(type)) {
let el = document.createElement("option");
el.value = item;
item_list.appendChild(el);
}
}
function init() {
console.log(items);
for (const item of items) {
itemLists.get(item.type).push(item.name);
itemMap.set(item.name, item);
}
for (const armorType of armorTypes) {
populateItemList(armorType);
document.getElementById(armorType+"-choice").addEventListener("change", (event) => {
let item = itemMap.get(event.target.value);
if (item !== undefined) {
document.getElementById(armorType+"-slots").textContent = item.slots + " slots";
}
else {
document.getElementById(armorType+"-slots").textContent = "X slots";
}
});
}
let ring1_list = document.getElementById("ring1-items");
let ring2_list = document.getElementById("ring2-items");
for (const ring of itemLists.get("ring")) {
let el1 = document.createElement("option");
let el2 = document.createElement("option");
el1.value = ring;
el2.value = ring;
ring1_list.appendChild(el1);
ring2_list.appendChild(el2);
}
populateItemList("bracelet");
populateItemList("necklace");
let weapon_list = document.getElementById("weapon-items");
for (const weaponType of weaponTypes) {
for (const weapon of itemLists.get(weaponType)) {
let el = document.createElement("option");
el.value = weapon;
weapon_list.appendChild(el);
}
}
document.getElementById("weapon-choice").addEventListener("change", (event) => {
let item = itemMap.get(event.target.value);
if (item !== undefined) {
document.getElementById("weapon-slots").textContent = item.slots + " slots";
}
else {
document.getElementById("weapon-slots").textContent = "X slots";
}
});
}
async function load_local() {
let get_tx = db.transaction('item_db', 'readonly');
let get_store = get_tx.objectStore('item_db');
let request = get_store.getAll();
request.onerror = function(event) {
console.log("Could not read local db...");
}
request.onsuccess = function(event) {
console.log("Successfully read local db.");
items = request.result;
init();
}
await get_tx.complete;
db.close();
}
function clean_item(item) {
if (item.displayName === null) {
item.displayName = item.name;
}
}
async function load() {
let url = "https://hppeng-wynn.github.io/compress.json";
let result = await (await fetch(url)).json();
items = result.items;
// https://developer.mozilla.org/en-US/docs/Web/API/IDBObjectStore/clear
let clear_tx = db.transaction('item_db', 'readwrite');
let clear_store = clear_tx.objectStore('item_db');
await clear_store.clear();
await clear_tx.complete;
let add_tx = db.transaction('item_db', 'readwrite');
let add_store = add_tx.objectStore('item_db');
let add_promises = [];
for (const item of items) {
add_promises.push(add_store.add(item, item.name));
}
add_promises.push(add_tx.complete);
Promise.all(add_promises).then((values) => {
db.close();
init();
});
}
let request = window.indexedDB.open('item_db', DB_VERSION);
request.onerror = function() {
console.log("DB failed to open...");
};
request.onsuccess = function() {
db = request.result;
if (!reload) {
console.log("Using stored data...")
load_local();
}
else {
console.log("Using new data...")
load();
}
}
request.onupgradeneeded = function(e) {
reload = true;
let db = e.target.result;
let objectStore = db.createObjectStore('item_db');
objectStore.createIndex('item', 'item', {unique: false});
console.log("DB setup complete...");
}