Skip to content

Commit

Permalink
Abstract PokemonID operations
Browse files Browse the repository at this point in the history
  • Loading branch information
Glazelf committed May 13, 2024
1 parent 6ecf522 commit 278ee18
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 38 deletions.
40 changes: 40 additions & 0 deletions util/pokemon/getCleanPokemonID.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
module.exports = (pokemon) => {
let pokemonID = pokemon.num;
let pokemonName = pokemon.name;
let pokemonTypes = pokemon.types;
const leadingZeros = require('../leadingZeros');
const correctionID = require('../../objects/pokemon/correctionID.json');
pokemonID = leadingZeros(pokemonID.toString(), 3); // Turn this number into 4 when Showdown and Serebii switch to 4 digit IDs consistently
// Forms
const primalString = "-Primal";
const totemString = "-Totem";
const gmaxString = "-Gmax";
const eternamaxString = "-Eternamax";
const primalBool = pokemonName.endsWith(primalString);
const totemBool = pokemonName.endsWith(totemString);
const gmaxBool = pokemonName.endsWith(gmaxString);
const eternamaxBool = pokemonName.endsWith(eternamaxString);
const dynamaxBool = Boolean(gmaxBool || eternamaxBool);
const totemAlolaBool = totemBool && pokemonName.split("-")[1] == "Alola";
let formChar;

if (primalBool || gmaxBool) {
if (primalBool) formChar = "-m";
if (gmaxBool) formChar = "-gi";
pokemonID = `${pokemonID}${formChar}`;
} else if (!totemBool || totemAlolaBool) {
// Catches all forms where the form extension on Serebii is just the first letter of the form name
if (pokemonName.split("-")[1]) pokemonID = `${pokemonID}-${pokemonName.split("-")[1].split("", 1)[0].toLowerCase()}`;
};
// Edgecase ID corrections
// TODO: add a bunch of meaningless forms like Unown and Vivillon
pokemonID = correctValue(correctionID, pokemonName, pokemonID);
if (pokemonName.startsWith("Arceus-") || pokemonName.startsWith("Silvally-")) pokemonID = `${pokemonID.split("-")[0]}-${pokemonTypes[0].toLowerCase()}`;
return pokemonID;

function correctValue(object, key, input) {
key = key.toLowerCase();
if (object[key]) return object[key];
return input;
};
};
44 changes: 6 additions & 38 deletions util/pokemon/getPokemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = async ({ client, interaction, pokemon, learnsetBool = false, sh
const isAdmin = require('../isAdmin');
const convertMeterFeet = require('../convertMeterFeet');
const leadingZeros = require('../leadingZeros');
const correctionID = require('../../objects/pokemon/correctionID.json');
const getCleanPokemonID = require('./getCleanPokemonID.js');
const colorHexes = require('../../objects/colorHexes.json');
const typechart = require('../../node_modules/pokemon-showdown/dist/data/typechart.js').TypeChart;
let learnsets = require('../../node_modules/pokemon-showdown/dist/data/learnsets.js').Learnsets;
Expand Down Expand Up @@ -89,47 +89,19 @@ module.exports = async ({ client, interaction, pokemon, learnsetBool = false, sh
resistances = resistances.join(", ");
immunities = immunities.join(", ");

let pokemonID = leadingZeros(pokemon.num.toString(), 4);
// Forms
const primalString = "-Primal";
const totemString = "-Totem";
const gmaxString = "-Gmax";
const eternamaxString = "-Eternamax";
const primalBool = pokemon.name.endsWith(primalString);
const totemBool = pokemon.name.endsWith(totemString);
const gmaxBool = pokemon.name.endsWith(gmaxString);
const eternamaxBool = pokemon.name.endsWith(eternamaxString);
const dynamaxBool = Boolean(gmaxBool || eternamaxBool);
const totemAlolaBool = totemBool && pokemon.name.split("-")[1] == "Alola";
let formChar;

if (primalBool || gmaxBool) {
if (primalBool) formChar = "-m";
if (gmaxBool) formChar = "-gi";
pokemonID = `${pokemonID}${formChar}`;
} else if (!totemBool || totemAlolaBool) {
// Catches all forms where the form extension on Serebii is just the first letter of the form name
if (pokemon.name.split("-")[1]) pokemonID = `${pokemonID}-${pokemon.name.split("-")[1].split("", 1)[0].toLowerCase()}`;
};
// Edgecase ID corrections
// TODO: add a bunch of meaningless forms like Unown and Vivillon
pokemonID = correctValue(correctionID, pokemon.name, pokemonID);
if (pokemon.name.startsWith("Arceus-") || pokemon.name.startsWith("Silvally-")) pokemonID = `${pokemonID.split("-")[0]}-${pokemon.types[0].toLowerCase()}`;
// 3 digit IDs for now
pokemonIDPMD = pokemonID;
if (pokemonID[0] == "0") pokemonID = pokemonID.substring(1); // Remove this when Showdown and Serebii switch to 4 digit IDs consistently
let pokemonID = getCleanPokemonID(pokemon);
pokemonIDPMD = leadingZeros(pokemonID, 4); // Remove this when Showdown and Serebii switch to 4 digit IDs consistently as well
// Metrics
let metricsString = "";
let weightAmerican = Math.round(pokemon.weightkg * 2.20462 * 10) / 10;
let heightAmerican = convertMeterFeet(pokemon.heightm);
if (pokemon.weightkg) {
if (pokemon.weightkg && pokemon.weightkg > 0) {
metricsString += `**Weight:**\n${pokemon.weightkg}kg | ${weightAmerican}lbs`;
} else if (dynamaxBool) {
} else {
metricsString += `**Weight:**\n???`;
};
if (pokemon.heightm) {
metricsString += `\n**Height:**\n${pokemon.heightm}m | ${heightAmerican}ft`;
if (dynamaxBool) metricsString = metricsString.replace("m", "m+").replace("ft", "ft+");
};
let urlName = encodeURIComponent(pokemon.name.toLowerCase().replace(" ", "-"));
// Official art
Expand Down Expand Up @@ -463,11 +435,7 @@ module.exports = async ({ client, interaction, pokemon, learnsetBool = false, sh
let StatText = `(${min50}-${max50}) (${min100}-${max100})`;
return StatText;
};
function correctValue(object, key, input) {
key = key.toLowerCase();
if (object[key]) return object[key];
return input;
};

function getEvoMethod(pokemon) {
let evoMethod;
switch (pokemon.evoType) {
Expand Down

0 comments on commit 278ee18

Please sign in to comment.