feat: add new sprites field to type

via adding `TypeSprites` to db containing type name icons from all games
(excluding tera types, for now)
This commit is contained in:
gabe 2024-07-28 20:04:30 -04:00
parent dc8e651cd7
commit e885e3fa62
No known key found for this signature in database
5 changed files with 97 additions and 1 deletions

View file

@ -629,6 +629,45 @@ def _build_types():
build_generic((TypeEfficacyPast,), "type_efficacy_past.csv", csv_record_to_objects)
def csv_record_to_objects(info):
game_map = {
"generation-iii": [
"colosseum",
"emerald",
"firered-leafgreen",
"ruby-saphire",
"xd",
],
"generation-iv": ["diamond-pearl", "heartgold-soulsilver", "platinum"],
"generation-v": ["black-2-white-2", "black-white"],
"generation-vi": ["omega-ruby-alpha-sapphire", "x-y"],
"generation-vii": [
"lets-go-pikachu-lets-go-eevee",
"sun-moon",
"ultra-sun-ultra-moon",
],
"generation-viii": [
"brilliant-diamond-and-shining-pearl",
"legends-arceus",
"sword-shield",
],
"generation-ix": ["scarlet-violet"],
}
sprites = {}
for generation in game_map.keys():
for game in game_map[generation]:
if generation not in sprites:
sprites[generation] = {}
sprites[generation][game] = {
"name_icon": file_path_or_none(
f"types/{generation}/{game}/{info[0]}.png"
)
}
yield TypeSprites(type_id=int(info[0]), sprites=sprites)
build_generic((TypeSprites,), "types.csv", csv_record_to_objects)
#############
# CONTEST #

@ -1 +1 @@
Subproject commit ca5a7886c10753144e6fae3b69d45a4d42a449b4
Subproject commit d607f0df04218c564167f654802262ef23a3cac1

View file

@ -0,0 +1,41 @@
# Generated by Django 3.2.23 on 2024-07-29 02:09
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
("pokemon_v2", "0015_pokemoncries"),
]
operations = [
migrations.CreateModel(
name="TypeSprites",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("sprites", models.JSONField()),
(
"type",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.CASCADE,
related_name="typesprites",
to="pokemon_v2.type",
),
),
],
options={
"abstract": False,
},
),
]

View file

@ -773,6 +773,10 @@ class TypeEfficacyPast(HasTypeEfficacy, HasGeneration):
pass
class TypeSprites(HasType):
sprites = models.JSONField()
#################
# STAT MODELS #
#################

View file

@ -2340,6 +2340,12 @@ class TypeNameSerializer(serializers.ModelSerializer):
fields = ("name", "language")
class TypeSpriteSerializer(serializers.ModelSerializer):
class Meta:
model = TypeSprites
fields = ("sprites",)
class TypeDetailSerializer(serializers.ModelSerializer):
"""
Serializer for the Type resource
@ -2357,6 +2363,7 @@ class TypeDetailSerializer(serializers.ModelSerializer):
)
pokemon = serializers.SerializerMethodField("get_type_pokemon")
moves = MoveSummarySerializer(many=True, read_only=True, source="move")
sprites = serializers.SerializerMethodField("get_type_sprites")
class Meta:
model = Type
@ -2371,8 +2378,13 @@ class TypeDetailSerializer(serializers.ModelSerializer):
"names",
"pokemon",
"moves",
"sprites",
)
def get_type_sprites(self, obj):
sprites_object = TypeSprites.objects.get(type_id=obj)
return sprites_object.sprites
# adds an entry for the given type with the given damage
# factor in the given direction to the set of relations