From 5c2b9a8f4432127670000bb615097d6b51f65541 Mon Sep 17 00:00:00 2001 From: thechillcheetah <94395488+thechillcheetah@users.noreply.github.com> Date: Thu, 16 May 2024 08:12:58 -0400 Subject: [PATCH 1/3] Update background.js --- background.js | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/background.js b/background.js index d19d831..c082925 100644 --- a/background.js +++ b/background.js @@ -387,7 +387,20 @@ async function getTypeEffectiveness(type) { return null; } } - +// i don't know how to do javascript please fix this if it's broken +// it's supposed to get the pokemon's ability based on its index +async function getAbility(pokeID, abilityIndex) +{ + try { + const response = await fetch(`https://pokeapi.co/api/v2/pokemon/${pokeID}`); + const data = await response.json(); + const ability = data.abilities.map(ability => ability.ability.name); + return ability; + } catch (error) { + console.error('Error fetching Pokémon's ability:', error); + return null; + } +} // Function to calculate weaknesses, resistances, and immunities async function calculateTypeEffectiveness(types) { const typeEffectiveness = await Promise.all(types.map(getTypeEffectiveness)); @@ -551,6 +564,7 @@ function appendPokemonArrayToDiv(pokemonArray, arena, message) { let frontendPokemonArray = [] pokemonArray.forEach((pokemon) => { const pokemonId = convertPokemonId(pokemon.species) + const ability = getAbility(pokemonId, pokemon.abilityIndex) let weather = {} if (arena.weather && arena.weather.weatherType) { weather = { @@ -559,6 +573,7 @@ function appendPokemonArrayToDiv(pokemonArray, arena, message) { } } getPokemonTypeEffectiveness(pokemonId).then((typeEffectiveness) => { + console.log("Got pokemon", pokemonId, "type effectiveness", typeEffectiveness) frontendPokemonArray.push({ 'id': pokemon.species, @@ -568,7 +583,7 @@ function appendPokemonArrayToDiv(pokemonArray, arena, message) { 'immunities': Array.from(typeEffectiveness.immunities) }, 'ivs': pokemon.ivs, - 'ability': Abilities[pokemon.abilityIndex], + 'ability': ability, 'nature': Nature[pokemon.nature] }) updateDiv(frontendPokemonArray, weather, message) @@ -604,4 +619,4 @@ browserApi.webRequest.onBeforeRequest.addListener( urls: ['https://api.pokerogue.net/savedata/update?datatype=1*', 'https://api.pokerogue.net/savedata/updateall'] }, ["requestBody"] -) \ No newline at end of file +) From 369d2f5096ebb47a09430442365fbc2abfbdc2f7 Mon Sep 17 00:00:00 2001 From: thechillcheetah <94395488+thechillcheetah@users.noreply.github.com> Date: Thu, 16 May 2024 08:16:21 -0400 Subject: [PATCH 2/3] Update background.js --- background.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/background.js b/background.js index c082925..0332a5a 100644 --- a/background.js +++ b/background.js @@ -397,7 +397,7 @@ async function getAbility(pokeID, abilityIndex) const ability = data.abilities.map(ability => ability.ability.name); return ability; } catch (error) { - console.error('Error fetching Pokémon's ability:', error); + console.error('Error fetching Pokémons ability:', error); return null; } } From e5a1250c7c03ca38316c132a154ca32fecfa750c Mon Sep 17 00:00:00 2001 From: thechillcheetah <94395488+thechillcheetah@users.noreply.github.com> Date: Thu, 16 May 2024 17:02:19 -0400 Subject: [PATCH 3/3] Update background.js quick hotfix for proper ability names --- background.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/background.js b/background.js index 0332a5a..b1ee6f7 100644 --- a/background.js +++ b/background.js @@ -388,14 +388,13 @@ async function getTypeEffectiveness(type) { } } // i don't know how to do javascript please fix this if it's broken -// it's supposed to get the pokemon's ability based on its index +// gets ability from pokeapi using the pokemon's ability index async function getAbility(pokeID, abilityIndex) { try { const response = await fetch(`https://pokeapi.co/api/v2/pokemon/${pokeID}`); const data = await response.json(); - const ability = data.abilities.map(ability => ability.ability.name); - return ability; + return data.abilities[abilityIndex].ability.name; } catch (error) { console.error('Error fetching Pokémons ability:', error); return null; @@ -564,7 +563,9 @@ function appendPokemonArrayToDiv(pokemonArray, arena, message) { let frontendPokemonArray = [] pokemonArray.forEach((pokemon) => { const pokemonId = convertPokemonId(pokemon.species) - const ability = getAbility(pokemonId, pokemon.abilityIndex) + let ability = getAbility(pokemonId, pokemon.abilityIndex).then((value) => { + ability = value +}) let weather = {} if (arena.weather && arena.weather.weatherType) { weather = { @@ -574,7 +575,7 @@ function appendPokemonArrayToDiv(pokemonArray, arena, message) { } getPokemonTypeEffectiveness(pokemonId).then((typeEffectiveness) => { - console.log("Got pokemon", pokemonId, "type effectiveness", typeEffectiveness) + console.log("Got pokemon", pokemonId, "ability", ability, "type effectiveness", typeEffectiveness) frontendPokemonArray.push({ 'id': pokemon.species, 'typeEffectiveness': {