-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat: fallback front_female sprite to front_default for female-only p… #1573
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4418,7 +4418,34 @@ class Meta: | |
| ) | ||
| def get_pokemon_sprites(self, obj): | ||
| sprites_object = PokemonSprites.objects.get(pokemon_id=obj) | ||
| return sprites_object.sprites | ||
| sprites = sprites_object.sprites | ||
| if obj.pokemon_species.gender_rate == 8: | ||
| if isinstance(sprites, str): | ||
| parsed = json.loads(sprites) | ||
| self._fill_female_sprites(parsed) | ||
| return json.dumps(parsed) | ||
| self._fill_female_sprites(sprites) | ||
| return sprites | ||
|
|
||
| _FEMALE_FALLBACKS = { | ||
| "front_female": "front_default", | ||
| "back_female": "back_default", | ||
| "front_shiny_female": "front_shiny", | ||
| "back_shiny_female": "back_shiny", | ||
| } | ||
|
|
||
| def _fill_female_sprites(self, node): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm strongly of the opinion that the data should just be shared with PokeAPI and consumers should handle this themselves.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Among the years we always pulled data from veekun which in turn got it from decompilations. The data was sometimes pretty cryptic to use. I can mention the use of rare Unicode characters, having braces in strings that acted as templates, having hidden characters and so on. In the beginning we were reluctant to change these pieces of data turning to the users to implement custom strategies. Eventually we cleaned the garbage that we were serving and everyone was happier. Maybe valuing user-friendliness over strict data rules was the key to it. That said I'm in favour of these kind of changes. If a pokemon has a 100% female rate then the female_sprite can be inferred to be the same as the default_sprite. In this case default_sprite and female_sprite coincide. By having the female_sprite filled in (by this custom logic or any other method) is ok with me. |
||
| if not isinstance(node, dict): | ||
| return | ||
| for female_key, default_key in self._FEMALE_FALLBACKS.items(): | ||
| if ( | ||
| female_key in node | ||
| and node[female_key] is None | ||
| and node.get(default_key) is not None | ||
| ): | ||
| node[female_key] = node[default_key] | ||
| for value in node.values(): | ||
| self._fill_female_sprites(value) | ||
|
|
||
| @extend_schema_field( | ||
| field={ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very interesting implementation. Can I ask what's the purpose of this function? It's for having ready at hand some data later on in the serializer.py part?