mirror of
https://github.com/PokeAPI/pokeapi
synced 2024-11-22 03:13:06 +00:00
Merge pull request #978 from FallenDeity/add-showdown-field-to-pokemon
feat: Add showdown field to pokemon api resource
This commit is contained in:
commit
724f9bbe0f
2 changed files with 65 additions and 1 deletions
|
@ -1388,6 +1388,7 @@ def _build_pokemons():
|
|||
dream_world = "other/dream-world/"
|
||||
home = "other/home/"
|
||||
official_art = "other/official-artwork/"
|
||||
showdown = "other/showdown/"
|
||||
gen_i = "versions/generation-i/"
|
||||
gen_ii = "versions/generation-ii/"
|
||||
gen_iii = "versions/generation-iii/"
|
||||
|
@ -1438,6 +1439,32 @@ def _build_pokemons():
|
|||
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": {
|
||||
"generation-i": {
|
||||
|
|
|
@ -1675,6 +1675,32 @@ class APIData:
|
|||
back_shiny_female=False,
|
||||
):
|
||||
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 = {
|
||||
"front_default": sprite_path % pokemon.id if front_default else None,
|
||||
|
@ -1692,7 +1718,8 @@ class APIData:
|
|||
}
|
||||
|
||||
pokemon_sprites = PokemonSprites.objects.create(
|
||||
pokemon=pokemon, sprites=json.dumps(sprites)
|
||||
pokemon=pokemon,
|
||||
sprites=json.dumps(sprites | {"other": {"showdown": showdown}}),
|
||||
)
|
||||
pokemon_sprites.save()
|
||||
|
||||
|
@ -5025,6 +5052,7 @@ class APITests(APIData, APITestCase):
|
|||
)
|
||||
|
||||
sprites_data = json.loads(pokemon_sprites.sprites)
|
||||
response_sprites_data = json.loads(response.data["sprites"])
|
||||
|
||||
# sprite params
|
||||
self.assertEqual(
|
||||
|
@ -5033,6 +5061,15 @@ class APITests(APIData, APITestCase):
|
|||
)
|
||||
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):
|
||||
pokemon_species = self.setup_pokemon_species_data()
|
||||
pokemon = self.setup_pokemon_data(pokemon_species=pokemon_species)
|
||||
|
|
Loading…
Reference in a new issue