-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #846 from Glazelf/whos-that-pokemon
Who's That Pokémon?
- Loading branch information
Showing
6 changed files
with
188 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = (objectList) => { | ||
let listKeys = Object.keys(objectList); | ||
return objectList[listKeys[listKeys.length * Math.random() << 0]]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
module.exports = (pokemon) => { | ||
let pokemonID = pokemon.num.toString(); | ||
let pokemonName = pokemon.name; | ||
let pokemonTypes = pokemon.types; | ||
const leadingZeros = require('../leadingZeros'); | ||
const correctionID = require('../../objects/pokemon/correctionID.json'); | ||
// Turn this number into 4 when Showdown and Serebii switch to 4 digit IDs consistently. This approach doesn't change 4-digit IDs. | ||
pokemonID = leadingZeros(pokemonID, 3); | ||
// 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; | ||
}; | ||
}; |
Oops, something went wrong.