From 1f0d231daf5b121dce85da6658b36d5ead980104 Mon Sep 17 00:00:00 2001 From: Eevee Date: Mon, 14 Sep 2009 08:29:05 -0700 Subject: [PATCH] Balls. Last commit was only data. Here's move flag code. --- pokedex/data/csv/move_effects.csv | 2 +- pokedex/db/rst.py | 18 +++++++++++++++++- pokedex/db/tables.py | 15 +++++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/pokedex/data/csv/move_effects.csv b/pokedex/data/csv/move_effects.csv index 80eb88c..89a87f7 100644 --- a/pokedex/data/csv/move_effects.csv +++ b/pokedex/data/csv/move_effects.csv @@ -578,7 +578,7 @@ The user may still use :move:`U-Turn` to leave the :mechanic:`field`. This effect can be passed with :move:`Baton Pass`." 183,0,Lowers the user's Attack and Defense by one level after inflicting damage.,"Inflicts :mechanic:`regular damage`, then :mechanic:`lowers` the user's mechanic:`Attack` and mechanic:`Defense` by one level." -184,4,Reflects back any effects the target tries to use on the user this turn.,"Until the user leaves the mechanic:`field`, any non-damaging move targeting the user that inflicts mechanic:`major status effect`\ s, mechanic:`stat change`\ s, or mechanic:`trap`\ ping effects will be reflected at its user. +184,4,Reflects back the first effect move used on the user this turn.,"The first non-damaging move targeting the user this turn that inflicts :mechanic:`major status effect`\ s, :mechanic:`stat change`\ s, or :mechanic:`trap`\ ping effects will be reflected at its user. :move:`Defog`, :move:`Memento`, and :move:`Teeter Dance` are not reflected. diff --git a/pokedex/db/rst.py b/pokedex/db/rst.py index 474a275..d3d6322 100644 --- a/pokedex/db/rst.py +++ b/pokedex/db/rst.py @@ -40,6 +40,8 @@ from docutils.parsers.rst import Parser, roles import docutils.utils from docutils.writers.html4css1 import Writer as HTMLWriter +import sqlalchemy.types + ### Subclasses of bits of docutils, to munge it into doing what I want class HTMLFragmentWriter(HTMLWriter): """Translates reST to HTML, but only as a fragment. Enclosing , @@ -138,7 +140,7 @@ class RstString(object): class MoveEffectProperty(object): """Property that wraps a move effect. Used like this: - MoveClass.effect = MoveEffectProperty() + MoveClass.effect = MoveEffectProperty('effect') some_move.effect # returns an RstString some_move.effect.as_html # returns a chunk of HTML @@ -162,3 +164,17 @@ class MoveEffectProperty(object): return RstString(getattr(move.move_effect, self.effect_column), document_properties=dict( _pokedex_handle_data=data_role_func)) + +class RstTextColumn(sqlalchemy.types.TypeDecorator): + """Generic column type for reST text. + + Do NOT use this for move effects! They need to know what move they belong + to so they can fill in, e.g., effect chances. + """ + impl = sqlalchemy.types.Unicode + + def process_bind_param(self, value, dialect): + return unicode(value) + + def process_result_value(self, value, dialect): + return RstString(value) diff --git a/pokedex/db/tables.py b/pokedex/db/tables.py index c295ddd..a0a4e92 100644 --- a/pokedex/db/tables.py +++ b/pokedex/db/tables.py @@ -181,6 +181,17 @@ class MoveEffect(TableBase): short_effect = Column(Unicode(256), nullable=False) effect = Column(Unicode(5120), nullable=False) +class MoveFlag(TableBase): + __tablename__ = 'move_flags' + move_id = Column(Integer, ForeignKey('moves.id'), primary_key=True, nullable=False, autoincrement=False) + move_flag_type_id = Column(Integer, ForeignKey('move_flag_types.id'), primary_key=True, nullable=False, autoincrement=False) + +class MoveFlagType(TableBase): + __tablename__ = 'move_flag_types' + id = Column(Integer, primary_key=True, nullable=False) + name = Column(Unicode(32), nullable=False) + description = Column(rst.RstTextColumn(128), nullable=False) + class MoveName(TableBase): __tablename__ = 'move_names' move_id = Column(Integer, ForeignKey('moves.id'), primary_key=True, nullable=False, autoincrement=False) @@ -409,10 +420,12 @@ LocationArea.location = relation(Location, backref='areas') Machine.generation = relation(Generation) Move.damage_class = relation(MoveDamageClass, backref='moves') +Move.flags = association_proxy('move_flags', 'flag') Move.foreign_names = relation(MoveName, backref='pokemon') Move.generation = relation(Generation, backref='moves') Move.machines = relation(Machine, backref='move') Move.move_effect = relation(MoveEffect, backref='moves') +Move.move_flags = relation(MoveFlag, backref='move') Move.target = relation(MoveTarget, backref='moves') Move.type = relation(Type, backref='moves') @@ -420,6 +433,8 @@ Move.effect = rst.MoveEffectProperty('effect') Move.priority = association_proxy('move_effect', 'priority') Move.short_effect = rst.MoveEffectProperty('short_effect') +MoveFlag.flag = relation(MoveFlagType) + MoveName.language = relation(Language) Pokemon.abilities = relation(Ability, secondary=PokemonAbility.__table__, -- 2.7.4