diff --git a/pokedex/tests/test_media.py b/pokedex/tests/test_media.py index ddbc778..f06ddcf 100644 --- a/pokedex/tests/test_media.py +++ b/pokedex/tests/test_media.py @@ -39,15 +39,15 @@ def if_available(func): @if_available def test_totodile(): """Totodile's female sprite -- same as male""" - totodile = session.query(tables.Pokemon).filter_by(identifier=u'totodile').one() - accessor = media.PokemonMedia(root, totodile) + totodile = session.query(tables.PokemonSpecies).filter_by(identifier=u'totodile').one() + accessor = media.PokemonSpeciesMedia(root, totodile) assert accessor.sprite() == accessor.sprite(female=True) @if_available def test_chimecho(): """Chimecho's Platinum female backsprite -- diffeent from male""" - chimecho = session.query(tables.Pokemon).filter_by(identifier=u'chimecho').one() - accessor = media.PokemonMedia(root, chimecho) + chimecho = session.query(tables.PokemonSpecies).filter_by(identifier=u'chimecho').one() + accessor = media.PokemonSpeciesMedia(root, chimecho) male = accessor.sprite('platinum', back=True, frame=2) female = accessor.sprite('platinum', back=True, female=True, frame=2) assert male != female @@ -55,16 +55,16 @@ def test_chimecho(): @if_available def test_venonat(): """Venonat's shiny Yellow sprite -- same as non-shiny""" - venonat = session.query(tables.Pokemon).filter_by(identifier=u'venonat').one() - accessor = media.PokemonMedia(root, venonat) + venonat = session.query(tables.PokemonSpecies).filter_by(identifier=u'venonat').one() + accessor = media.PokemonSpeciesMedia(root, venonat) assert accessor.sprite('yellow') == accessor.sprite('yellow', shiny=True) @if_available def test_arceus_icon(): """Arceus fire-form icon -- same as base icon""" - arceus = session.query(tables.Pokemon).filter_by(identifier=u'arceus').one() - accessor = media.PokemonMedia(root, arceus) - fire_arceus = [f for f in arceus.forms if f.identifier == 'fire'][0] + arceus = session.query(tables.PokemonSpecies).filter_by(identifier=u'arceus').one() + accessor = media.PokemonSpeciesMedia(root, arceus) + fire_arceus = [f for f in arceus.forms if f.form_identifier == 'fire'][0] fire_accessor = media.PokemonFormMedia(root, fire_arceus) assert accessor.icon() == fire_accessor.icon() @@ -72,8 +72,9 @@ def test_arceus_icon(): @raises(ValueError) def test_strict_castform(): """Castform rainy form overworld with strict -- unavailable""" - castform = session.query(tables.Pokemon).filter_by(identifier=u'castform').first() - rainy_castform = [f for f in castform.forms if f.identifier == 'rainy'][0] + castform = session.query(tables.PokemonSpecies).filter_by(identifier=u'castform').first() + rainy_castform = [f for f in castform.forms if f.form_identifier == 'rainy'][0] + print rainy_castform rainy_castform = media.PokemonFormMedia(root, rainy_castform) rainy_castform.overworld('up', strict=True) @@ -81,8 +82,8 @@ def test_strict_castform(): @raises(ValueError) def test_strict_exeggcute(): """Exeggcutes's female backsprite, with strict -- unavailable""" - exeggcute = session.query(tables.Pokemon).filter_by(identifier=u'exeggcute').one() - accessor = media.PokemonMedia(root, exeggcute) + exeggcute = session.query(tables.PokemonSpecies).filter_by(identifier=u'exeggcute').one() + accessor = media.PokemonSpeciesMedia(root, exeggcute) accessor.sprite(female=True, strict=True) @@ -194,26 +195,26 @@ def check_get_everything(): accessors.append(media.UnknownPokemonMedia(root)) accessors.append(media.EggMedia(root)) - manaphy = session.query(tables.Pokemon).filter_by(identifier=u'manaphy').one() + manaphy = session.query(tables.PokemonSpecies).filter_by(identifier=u'manaphy').one() accessors.append(media.EggMedia(root, manaphy)) accessors.append(media.SubstituteMedia(root)) - for form in session.query(tables.PokemonForm).filter(tables.PokemonForm.identifier != '').all(): + for form in session.query(tables.PokemonForm).all(): accessors.append(media.PokemonFormMedia(root, form)) - for pokemon in session.query(tables.Pokemon).all(): - accessors.append(media.PokemonMedia(root, pokemon)) + for pokemon in session.query(tables.PokemonSpecies).all(): + accessors.append(media.PokemonSpeciesMedia(root, pokemon)) for accessor in accessors: - assert hit(filenames, accessor.footprint) or not accessor.form - assert hit(filenames, accessor.trozei) or not accessor.form or ( - accessor.form.pokemon.generation.id > 3) - assert hit(filenames, accessor.cry) or not accessor.form - assert hit(filenames, accessor.cropped_sprite) or not accessor.form + assert hit(filenames, accessor.footprint) or not accessor.is_proper + assert hit(filenames, accessor.trozei) or not accessor.is_proper or ( + accessor.introduced_in > 3) + assert hit(filenames, accessor.cry) or not accessor.is_proper + assert hit(filenames, accessor.cropped_sprite) or not accessor.is_proper for female in (True, False): - assert hit(filenames, accessor.icon, female=female) or not accessor.form + assert hit(filenames, accessor.icon, female=female) or not accessor.is_proper assert hit(filenames, accessor.sugimori, female=female) or ( - not accessor.form or accessor.form.pokemon.id >= 647) + not accessor.is_proper or int(accessor.species_id) >= 647) for shiny in (True, False): for frame in (1, 2): for direction in 'up down left right'.split(): @@ -222,8 +223,8 @@ def check_get_everything(): shiny=shiny, female=female, frame=frame, - ) or not accessor.form or ( - accessor.form.pokemon.generation.id > 4) + ) or not accessor.is_proper or ( + accessor.introduced_in > 4) for version in versions: for animated in (True, False): for back in (True, False): @@ -243,8 +244,8 @@ def check_get_everything(): shiny and not female and frame == 1): # All pokemon are in Black - assert success or not accessor.form - if (str(accessor.pokemon_id) == '1' + assert success or not accessor.is_proper + if (str(accessor.species_id) == '1' and not animated and not color and frame == 1): # Bulbasaur is in all versions diff --git a/pokedex/util/media.py b/pokedex/util/media.py index 98964b3..7b672b3 100644 --- a/pokedex/util/media.py +++ b/pokedex/util/media.py @@ -105,7 +105,8 @@ class BaseMedia(object): class _BasePokemonMedia(BaseMedia): toplevel_dir = 'pokemon' has_gender_differences = False - form = None + is_species = False + is_proper = False introduced_in = 0 # Info about of what's inside the pokemon main sprite directories, so we @@ -126,13 +127,13 @@ class _BasePokemonMedia(BaseMedia): 'black-white': (5, set('back shiny female'.split())), } - def __init__(self, root, pokemon_id, form_postfix=None): + def __init__(self, root, species_id, form_postfix=None): BaseMedia.__init__(self, root) - self.pokemon_id = str(pokemon_id) + self.species_id = str(species_id) self.form_postfix = form_postfix def _get_file(self, path_elements, extension, strict, surely_exists=False): - basename = str(self.pokemon_id) + basename = str(self.species_id) if self.form_postfix: fullname = basename + self.form_postfix try: @@ -195,7 +196,7 @@ class _BasePokemonMedia(BaseMedia): generation, info = self._pokemon_sprite_info[version_dir] if generation < self.introduced_in: raise ValueError("Pokemon %s didn't exist in %s" % ( - self.pokemon_id, version_dir)) + self.species_id, version_dir)) path_elements = ['main-sprites', version_dir] if animated: if 'animated' not in info: @@ -235,7 +236,7 @@ class _BasePokemonMedia(BaseMedia): # Chimecho's female back frame 2 sprite has one hand in # a slightly different pose, in Platinum and HGSS # (we have duplicate sprites frame 1, for convenience) - if self.pokemon_id == '358' and back and version_dir in ( + if self.species_id == '358' and back and version_dir in ( 'platinum', 'heartgold-soulsilver'): female_sprite = True female_sprite = female_sprite and 'female' in info @@ -243,7 +244,7 @@ class _BasePokemonMedia(BaseMedia): path_elements.append('female') elif strict: raise ValueError( - 'Pokemon %s has no gender differences' % self.pokemon_id) + 'Pokemon %s has no gender differences' % self.species_id) if not frame or frame == 1: pass elif frame == 2: @@ -255,9 +256,8 @@ class _BasePokemonMedia(BaseMedia): raise ValueError("Bad frame %s" % frame) return self._get_file(path_elements, extension, strict=strict, # Avoid a stat in the common case - surely_exists=(self.form and version_dir == 'black-white' - and not back and not female - and not self.form_postfix)) + surely_exists=(self.is_species and version_dir == 'black-white' + and not back and not female)) def _maybe_female(self, path_elements, female, strict): if female: @@ -270,7 +270,7 @@ class _BasePokemonMedia(BaseMedia): raise elif strict: raise ValueError( - 'Pokemon %s has no gender differences' % self.pokemon_id) + 'Pokemon %s has no gender differences' % self.species_id) return self._get_file(path_elements, '.png', strict=strict) def icon(self, female=False, strict=False): @@ -336,28 +336,32 @@ class _BasePokemonMedia(BaseMedia): return self._get_file(['cropped'], '.png', strict=strict) class PokemonFormMedia(_BasePokemonMedia): - """Media related to a Pokemon form + """Media related to a PokemonForm """ + is_proper = True + def __init__(self, root, pokemon_form): - pokemon_id = pokemon_form.form_base_pokemon_id - if pokemon_form.identifier: - form_postfix = '-' + pokemon_form.identifier + species_id = pokemon_form.species.id + if pokemon_form.form_identifier: + form_postfix = '-' + pokemon_form.form_identifier else: form_postfix = None - _BasePokemonMedia.__init__(self, root, pokemon_id, form_postfix) + _BasePokemonMedia.__init__(self, root, species_id, form_postfix) self.form = pokemon_form - pokemon = pokemon_form.form_base_pokemon - self.has_gender_differences = pokemon.has_gender_differences - self.introduced_in = pokemon.generation_id + species = pokemon_form.species + self.has_gender_differences = species.has_gender_differences + self.introduced_in = pokemon_form.version_group.generation_id -class PokemonMedia(_BasePokemonMedia): - """Media related to a Pokemon +class PokemonSpeciesMedia(_BasePokemonMedia): + """Media related to a PokemonSpecies """ - def __init__(self, root, pokemon): - _BasePokemonMedia.__init__(self, root, pokemon.id) - self.form = pokemon.default_form - self.has_gender_differences = (pokemon.has_gender_differences) - self.introduced_in = pokemon.generation_id + is_species = True + is_proper = True + + def __init__(self, root, species): + _BasePokemonMedia.__init__(self, root, species.id) + self.has_gender_differences = species.has_gender_differences + self.introduced_in = species.generation_id class UnknownPokemonMedia(_BasePokemonMedia): """Media related to the unknown Pokemon ("?") @@ -372,10 +376,10 @@ class EggMedia(_BasePokemonMedia): Note that not a lot of files are available for these. - Give a Manaphy as `pokemon` to get the Manaphy egg. + Give a Manaphy as `species` to get the Manaphy egg. """ - def __init__(self, root, pokemon=None): - if pokemon and pokemon.identifier == 'manaphy': + def __init__(self, root, species=None): + if species and species.identifier == 'manaphy': postfix = '-manaphy' else: postfix = None