Add Smogon Tiers to pokedex-stats

This commit is contained in:
Dragon Fire
2021-01-20 17:37:31 -05:00
parent e4073837b8
commit 1dca3ae20b
4 changed files with 27 additions and 1 deletions
+13
View File
@@ -60,6 +60,7 @@ module.exports = class Pokemon {
this.cry = data.id > store.pokemonCountWithCry
? null
: path.join(__dirname, '..', '..', 'assets', 'sounds', 'pokedex', `${data.id}.wav`);
this.smogonTiers = data.missingno ? data.smogonTiers : {};
}
baseStatTotal(variety) {
@@ -137,6 +138,18 @@ module.exports = class Pokemon {
return `https://www.serebii.net/pokedex-swsh/${this.displayID}.shtml`;
}
get smogonURL() {
if (this.missingno) return null;
return `https://www.smogon.com/dex/${this.id > 807 ? 'ss' : 'sm'}/pokemon/${this.slug}/`;
}
async fetchSmogonTiers(gen) {
if (!this.store.smogonData[gen.toLowerCase()]) await this.store.fetchSmogonData(gen.toLowerCase());
const pkmn = this.store.smogonData[gen.toLowerCase()].find(pkmn => pkmn.id === this.id);
this.smogonTiers[gen.toLowerCase()] = pkmn.formats;
return this.smogonTiers[gen.toLowerCase()];
}
async fetchGameData() {
if (this.gameDataCached) return this;
await this.fetchDefaultVariety();
+10
View File
@@ -9,6 +9,7 @@ module.exports = class PokemonStore extends Collection {
this.pokemonCount = 898;
this.pokemonCountWithCry = 893;
this.smogonData = {};
}
async fetch(query) {
@@ -34,6 +35,15 @@ module.exports = class PokemonStore extends Collection {
}
}
async fetchSmogonData(gen) {
if (this.smogonData[gen.toLowerCase()]) return this.smogonData[gen.toLowerCase()];
const { text } = await request.get(`https://www.smogon.com/dex/${gen}/pokemon/`);
this.smogonData[gen.toLowerCase()] = JSON.parse(text.match(/dexSettings = ({.+})/i)[1])
.injectRpcs[1][1]
.pokemon
.map(pkmn => ({ id: pkmn.oob.dex_number, formats: pkmn.formats }));
}
makeSlug(query) {
return encodeURIComponent(query.toLowerCase().replaceAll(' ', '-').replace(/[^a-zA-Z0-9-]/g, ''));
}