Added some Pokémon methods to hide form weirdness. #5
[zzz-pokedex.git] / pokedex / db / tables.py
index 2f49bd9..49d9c17 100644 (file)
@@ -1,3 +1,5 @@
+# encoding: utf8
+
 from sqlalchemy import Column, ForeignKey, MetaData, Table
 from sqlalchemy.ext.declarative import declarative_base
 from sqlalchemy.orm import backref, relation
@@ -203,6 +205,26 @@ class Pokemon(TableBase):
     has_gen4_fem_sprite = Column(Boolean, nullable=False)
     has_gen4_fem_back_sprite = Column(Boolean, nullable=False)
 
+    ### Stuff to handle alternate Pokémon forms
+
+    @property
+    def national_id(self):
+        """Returns the National Pokédex number for this Pokémon.  Use this
+        instead of the id directly; alternate formes may make the id incorrect.
+        """
+
+        if self.forme_base_pokemon_id:
+            return self.forme_base_pokemon_id
+        return self.id
+
+    @property
+    def full_name(self):
+        """Returns the name of this Pokémon, including its Forme, if any."""
+
+        if self.forme_name:
+            return "%s %s" % (self.forme_name.capitalize(), self.name)
+        return self.name
+
 class PokemonAbility(TableBase):
     __tablename__ = 'pokemon_abilities'
     pokemon_id = Column(Integer, ForeignKey('pokemon.id'), primary_key=True, nullable=False, autoincrement=False)
@@ -226,6 +248,17 @@ class PokemonFlavorText(TableBase):
     version_id = Column(Integer, ForeignKey('versions.id'), primary_key=True, nullable=False, autoincrement=False)
     flavor_text = Column(Unicode(255), nullable=False)
 
+class PokemonFormGroup(TableBase):
+    __tablename__ = 'pokemon_form_groups'
+    pokemon_id = Column(Integer, ForeignKey('pokemon.id'), primary_key=True, nullable=False, autoincrement=False)
+    description = Column(Unicode(255), nullable=False)
+
+class PokemonFormSprite(TableBase):
+    __tablename__ = 'pokemon_form_sprites'
+    id = Column(Integer, primary_key=True, nullable=False)
+    pokemon_id = Column(Integer, ForeignKey('pokemon.id'), primary_key=True, nullable=False, autoincrement=False)
+    name = Column(Unicode(16), nullable=True)
+
 class PokemonName(TableBase):
     __tablename__ = 'pokemon_names'
     pokemon_id = Column(Integer, ForeignKey('pokemon.id'), primary_key=True, nullable=False, autoincrement=False)
@@ -319,6 +352,10 @@ PokemonDexNumber.generation = relation(Generation)
 
 PokemonFlavorText.version = relation(Version)
 
+PokemonFormGroup.pokemon = relation(Pokemon, backref=backref('form_group',
+                                                             uselist=False))
+PokemonFormSprite.pokemon = relation(Pokemon, backref='form_sprites')
+
 PokemonName.language = relation(Language)
 
 PokemonStat.stat = relation(Stat)