-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
266 lines (253 loc) · 8.67 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
let BASEURL = "./";
async function raidsFetch(base, endpoint, method, message) {
await fetch(base + endpoint, {
method: method,
headers: {
"Content-Type": "Application/JSON",
},
body: method !== "GET" ? JSON.stringify(message) : undefined,
})
.then((res) => {
if (res.ok) {
return res.json();
} else throw new Error("Not 2xx response", { cause: res });
})
.then((data) => (cloning(data.characters), buildData(data.characters)))
.catch((e) => console.log(e));
}
raidsFetch(BASEURL, "data.json", "GET");
const cloning = (data) => {
for (let iteration of data) {
let gruntName = iteration.character.name.split("_")[2];
if (gruntName === "ARLO" || gruntName === "CLIFF" || gruntName === "SIERRA")
continue;
let temp = document.getElementsByTagName("template")[0];
let clone = temp.content.cloneNode(true);
document.querySelector(".chart-container").appendChild(clone);
}
};
const typeObj = {
grass: "Don't tangle with us.",
fire: "Do you know how hot Pokémon fire breath can get!",
water: "These waters are treacherous.",
electric: "Get ready to shocked",
ground: "You'll be defeated into the ground.",
ice: "You're gonna be frozen in your tracks.",
rock: "Let's rock and roll!",
steel: "You're no match for my iron will.",
metal: "You're no match for my iron will.",
fighting: "This buff physique isn't just for show.",
psychic: "Are you scared of psychics that use unseen power.",
ghost: "Ke... ke... ke... ke... ke... ke!",
dark: "Wherever there is light, there is also shadow.",
fairy: "Check out my cute Pokémon",
poison: "Coiled and ready to strike.",
bug: "Go, my super bug Pokémon.",
flying: "Battle against my Flying-type Pokémon.",
dragon: "ROAR! ...How'd that sound!",
normal: "Normal does not mean weak",
grunt: "...",
decoy: "...",
};
const buildData = (data) => {
// let chartNodes = document.querySelector(".chart-container").children;
let sortedTypes = [...Object.keys(typeObj)];
let sortedData = data.sort(
(a, b) =>
sortedTypes.indexOf(a.character.name.split("_")[1].toLowerCase()) -
sortedTypes.indexOf(b.character.name.split("_")[1].toLowerCase())
);
let gruntNodes = document.querySelectorAll(".grunt-container");
let headline = document.querySelectorAll(".headline");
let typeIcon = document.querySelectorAll(".grunt-type img.type");
let grunts = document.querySelectorAll(".grunt");
let i = 0;
for (let datum of sortedData) {
// CHARACTER
// console.log(datum.character.name);
let gruntName = datum.character.name.split("_")[2];
if (gruntName === "ARLO" || gruntName === "CLIFF" || gruntName === "SIERRA")
continue;
let type = datum.character.name.split("_")[1].toLowerCase();
let grunt =
datum.character.name.split("_")[3]?.toLowerCase() ??
datum.character.name.split("_")[2]?.toLowerCase();
switch (type) {
case "grunt": {
typeIcon[i].src = `./icons/ace.png`;
typeIcon[i].classList.add("ace");
additionalContext("ace", grunt, headline[i]);
break;
}
case "decoy": {
typeIcon[i].src = `./icons/ace.png`;
typeIcon[i].classList.add("ace");
additionalContext("decoy", grunt, headline[i]);
break;
}
case "metal": {
typeIcon[i].src = `./icons/steel.svg`;
typeIcon[i].classList.add("steel");
headline[i].textContent = typeObj.steel;
break;
}
default: {
typeIcon[i].src = `./icons/${type}.svg`;
typeIcon[i].classList.add(type);
headline[i].textContent = typeObj[type];
}
}
grunts[i].src = `./icons/grunts/${grunt}.png`;
grunts[i].classList.add(grunt);
// REWARDED POKEMON
let shinyMap = new Map();
for (let reward of datum.rewards)
shinyMap.set(reward.pokemon.name, !!reward.shinies);
// TEAM OF POKEMONS TO FIGHT WITH
let stage1 = gruntNodes[i].querySelectorAll(".stage-1 span img");
let stage2 = gruntNodes[i].querySelectorAll(".stage-2 span img");
let stage3 = gruntNodes[i].querySelectorAll(".stage-3 span img");
let a = 0;
let b = 0;
let c = 0;
for (let team of datum.team)
switch (team.slot) {
case 0: {
let pokemonName =
team.form.name !== "FORM_UNSET" &&
team.form.name !== team.pokemon.name + "_NORMAL"
? team.form.name
.replace(/_ALOLAN?/, "-alolan")
.replace(/_GALARI?A?N?/, "-galarian")
.replace(/_HISUIA?N?/, "-hisuian")
.replace(/_PALDEAN?/, "-paldean")
.replace(/_STANDARD/, "")
: team.pokemon.name;
stage1[
a
].src = `https://img.pokemondb.net/sprites/home/normal/${pokemonName
.replace(/_NORMAL/i, "")
.toLowerCase()}.png`;
shinyMap.get(team.pokemon.name) && stage1[a].classList.add("shiny");
!shinyMap.has(team.pokemon.name) &&
stage1[a]?.closest("div").classList.remove("encounterable");
a++;
break;
}
case 1: {
let pokemonName =
team.form.name !== "FORM_UNSET" &&
team.form.name !== team.pokemon.name + "_NORMAL"
? team.form.name
.replace(/_ALOLAN?/, "-alolan")
.replace(/_GALARI?A?N?/, "-galarian")
.replace(/_HISUIA?N?/, "-hisuian")
.replace(/_PALDEAN?/, "-paldean")
.replace(/_STANDARD/, "")
: team.pokemon.name;
stage2[
b
].src = `https://img.pokemondb.net/sprites/home/normal/${pokemonName
.replace(/_NORMAL/i, "")
.toLowerCase()}.png`;
shinyMap.get(team.pokemon.name) && stage2[b].classList.add("shiny");
!shinyMap.has(team.pokemon.name) &&
stage2[b]?.closest("div").classList.remove("encounterable");
b++;
break;
}
case 2: {
let pokemonName =
team.form.name !== "FORM_UNSET" &&
team.form.name !== team.pokemon.name + "_NORMAL"
? team.form.name
.replace(/_ALOLAN?/, "-alolan")
.replace(/_GALARI?A?N?/, "-galarian")
.replace(/_HISUIA?N?/, "-hisuian")
.replace(/_PALDEAN?/, "-paldean")
.replace(/_STANDARD/, "")
: team.pokemon.name;
stage3[
c
].src = `https://img.pokemondb.net/sprites/home/normal/${pokemonName
.replace(/_NORMAL/i, "")
.toLowerCase()}.png`;
shinyMap.get(team.pokemon.name) && stage3[c].classList.add("shiny");
!shinyMap.has(team.pokemon.name) &&
stage3[c]?.closest("div").classList.remove("encounterable");
c++;
break;
}
}
// SEPARATION
// console.warn("AAAAAAAAAAA");
i++;
}
};
const additionalContext = (type, gender, headline) => {
let heading =
(type === "ace" ? gender.toUpperCase() : type.toUpperCase()) + " GRUNT";
let span = document.createElement("span");
span.textContent = heading;
headline.appendChild(span);
let aceLabelData = [
"Don't bother--I've already won.",
"Get ready to be defeated!",
"Winning is for winners.",
];
let decoyLabelData = ["It feels good to see you disappointed."];
switch (type) {
case "ace": {
let ul = document.createElement("ul");
for (label of aceLabelData) {
let li = document.createElement("li");
li.textContent = label;
ul.appendChild(li);
}
headline.appendChild(ul);
break;
}
case "decoy": {
let p = document.createElement("p");
p.textContent = decoyLabelData[0];
headline.appendChild(p);
break;
}
}
kanban();
};
const kanban = () => {
let selectors = document.querySelectorAll(".stage");
selectors.forEach((selector) => {
Sortable.create(selector, {
animation: 150,
ghostClass: "sorting",
easing: "cubic-bezier(1, 0, 0, 1)",
});
});
};
// File System Access API
// used to store data as JSON
/*
async function writetoajsonfile(data) {
try {
const fileHandle = await window.showSaveFilePicker({
suggestedName: "data.json",
types: [
{
description: "JSON file",
accept: {
"application/json": [".json"],
},
},
],
});
const writable = await fileHandle.createWritable();
await writable.write(JSON.stringify(data, null, 2)); // Write JSON data with indentation
await writable.close();
console.log("Data saved to file successfully!");
} catch (e) {
console.error("Failed to save file", e);
}
}
*/