From 664f3031f072252af525a5bcaa3358783fef7205 Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Wed, 25 Mar 2020 20:57:17 -0400 Subject: [PATCH] Fix MissingNo. --- assets/json/missingno.json | 1 + structures/pokemon/Pokemon.js | 34 +++++++++++++++------------------- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/assets/json/missingno.json b/assets/json/missingno.json index f1d83c70..3c5b61d8 100644 --- a/assets/json/missingno.json +++ b/assets/json/missingno.json @@ -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", diff --git a/structures/pokemon/Pokemon.js b/structures/pokemon/Pokemon.js index b70bac12..d9a8f14f 100644 --- a/structures/pokemon/Pokemon.js +++ b/structures/pokemon/Pokemon.js @@ -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;