Merge pull request #978 from FallenDeity/add-showdown-field-to-pokemon

feat: Add showdown field to pokemon api resource
This commit is contained in:
Alessandro Pezzè 2023-12-21 05:17:30 +09:00 committed by GitHub
commit 724f9bbe0f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 65 additions and 1 deletions

View file

@ -1388,6 +1388,7 @@ def _build_pokemons():
dream_world = "other/dream-world/" dream_world = "other/dream-world/"
home = "other/home/" home = "other/home/"
official_art = "other/official-artwork/" official_art = "other/official-artwork/"
showdown = "other/showdown/"
gen_i = "versions/generation-i/" gen_i = "versions/generation-i/"
gen_ii = "versions/generation-ii/" gen_ii = "versions/generation-ii/"
gen_iii = "versions/generation-iii/" gen_iii = "versions/generation-iii/"
@ -1438,6 +1439,32 @@ def _build_pokemons():
poke_sprites + official_art + "shiny/", info, "png" poke_sprites + official_art + "shiny/", info, "png"
), ),
}, },
"showdown": {
"front_default": try_image_names(
poke_sprites + showdown, info, "gif"
),
"front_shiny": try_image_names(
poke_sprites + showdown + "shiny/", info, "gif"
),
"front_female": try_image_names(
poke_sprites + showdown + "female/", info, "gif"
),
"front_shiny_female": try_image_names(
poke_sprites + showdown + "shiny/female/", info, "gif"
),
"back_default": try_image_names(
poke_sprites + showdown + "back/", info, "gif"
),
"back_shiny": try_image_names(
poke_sprites + showdown + "back/shiny/", info, "gif"
),
"back_female": try_image_names(
poke_sprites + showdown + "back/female/", info, "gif"
),
"back_shiny_female": try_image_names(
poke_sprites + showdown + "back/shiny/female", info, "gif"
),
},
}, },
"versions": { "versions": {
"generation-i": { "generation-i": {

View file

@ -1675,6 +1675,32 @@ class APIData:
back_shiny_female=False, back_shiny_female=False,
): ):
sprite_path = "https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/%s.png" sprite_path = "https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/%s.png"
showdown_path = "https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/other/showdown/%s.png"
showdown = {
"front_default": showdown_path % pokemon.id if front_default else None,
"front_female": showdown_path % f"female/{pokemon.id}"
if front_female
else None,
"front_shiny": showdown_path % f"shiny/{pokemon.id}"
if front_shiny
else None,
"front_shiny_female": showdown_path % f"shiny/female/{pokemon.id}"
if front_shiny_female
else None,
"back_default": showdown_path % f"back/{pokemon.id}"
if back_default
else None,
"back_female": showdown_path % f"back/female/{pokemon.id}"
if back_female
else None,
"back_shiny": showdown_path % f"back/shiny/{pokemon.id}"
if back_shiny
else None,
"back_shiny_female": showdown_path % f"back/shiny/female/{pokemon.id}"
if back_shiny_female
else None,
}
sprites = { sprites = {
"front_default": sprite_path % pokemon.id if front_default else None, "front_default": sprite_path % pokemon.id if front_default else None,
@ -1692,7 +1718,8 @@ class APIData:
} }
pokemon_sprites = PokemonSprites.objects.create( pokemon_sprites = PokemonSprites.objects.create(
pokemon=pokemon, sprites=json.dumps(sprites) pokemon=pokemon,
sprites=json.dumps(sprites | {"other": {"showdown": showdown}}),
) )
pokemon_sprites.save() pokemon_sprites.save()
@ -5025,6 +5052,7 @@ class APITests(APIData, APITestCase):
) )
sprites_data = json.loads(pokemon_sprites.sprites) sprites_data = json.loads(pokemon_sprites.sprites)
response_sprites_data = json.loads(response.data["sprites"])
# sprite params # sprite params
self.assertEqual( self.assertEqual(
@ -5033,6 +5061,15 @@ class APITests(APIData, APITestCase):
) )
self.assertEqual(sprites_data["back_default"], None) self.assertEqual(sprites_data["back_default"], None)
self.assertEqual(
sprites_data["other"]["showdown"]["front_default"],
response_sprites_data["other"]["showdown"]["front_default"],
)
self.assertEqual(
sprites_data["other"]["showdown"]["back_default"],
response_sprites_data["other"]["showdown"]["back_default"],
)
def test_pokemon_form_api(self): def test_pokemon_form_api(self):
pokemon_species = self.setup_pokemon_species_data() pokemon_species = self.setup_pokemon_species_data()
pokemon = self.setup_pokemon_data(pokemon_species=pokemon_species) pokemon = self.setup_pokemon_data(pokemon_species=pokemon_species)