Fix MissingNo.

This commit is contained in:
Dragon Fire
2020-03-25 20:57:17 -04:00
parent c36056d114
commit 664f3031f0
2 changed files with 16 additions and 19 deletions
+1
View File
@@ -42,6 +42,7 @@
"Bird",
"Normal"
],
"chain": [0],
"missingno": true,
"sprite": "https://cdn.bulbagarden.net/upload/9/98/Missingno_RB.png",
"box": "https://cdn.bulbagarden.net/upload/1/1f/AniMS_Missingno_I.png",
+15 -19
View File
@@ -21,11 +21,11 @@ module.exports = class Pokemon {
name: name || null,
default: variety.is_default,
display: data.missingno ? true : null,
types: []
types: data.missingno ? missingno.types : []
};
});
this.chain = { url: data.evolution_chain.url, data: [] };
this.typesCached = false;
this.chain = { url: data.evolution_chain.url, data: data.missingno ? [0] : [] };
this.typesCached = data.missingno || false;
this.missingno = data.missingno || false;
}
@@ -54,22 +54,18 @@ module.exports = class Pokemon {
async fetchTypes() {
if (this.typesCached) return this;
if (this.missingno) {
this.varieties[0].types.push(...missingno.types);
} else {
const defaultVariety = this.varieties.find(variety => variety.default);
const { body: defaultBody } = await request.get(`https://pokeapi.co/api/v2/pokemon/${defaultVariety.id}`);
defaultVariety.types.push(...defaultBody.types.map(type => firstUpperCase(type.type.name)));
defaultVariety.display = true;
for (const variety of this.varieties) {
if (variety.id === defaultVariety.id) continue;
const { body } = await request.get(`https://pokeapi.co/api/v2/pokemon/${variety.id}`);
variety.types.push(...body.types.map(type => firstUpperCase(type.type.name)));
if (variety.types[0] === defaultVariety.types[0] && variety.types[1] === defaultVariety.types[1]) {
variety.display = false;
} else {
variety.display = true;
}
const defaultVariety = this.varieties.find(variety => variety.default);
const { body: defaultBody } = await request.get(`https://pokeapi.co/api/v2/pokemon/${defaultVariety.id}`);
defaultVariety.types.push(...defaultBody.types.map(type => firstUpperCase(type.type.name)));
defaultVariety.display = true;
for (const variety of this.varieties) {
if (variety.id === defaultVariety.id) continue;
const { body } = await request.get(`https://pokeapi.co/api/v2/pokemon/${variety.id}`);
variety.types.push(...body.types.map(type => firstUpperCase(type.type.name)));
if (variety.types[0] === defaultVariety.types[0] && variety.types[1] === defaultVariety.types[1]) {
variety.display = false;
} else {
variety.display = true;
}
}
this.typesCached = true;