Pokemon-Terminal/pokemonterminal/filters.py

66 lines
1.6 KiB
Python
Raw Normal View History

from argparse import Action
2017-10-06 17:48:05 +00:00
from pokemonterminal.database import Database, Pokemon
class Filter(Action):
POKEMON_LIST = Database().get_all()
filtered_list = [p for p in POKEMON_LIST]
FILTERS = []
EXAMPLE_VAL = None
def matches(self, pokemon, value):
raise NotImplementedError
def __init_subclass__(cls, **kwargs):
Filter.FILTERS.append(cls)
def __call__(self, parser, namespace, value, option_string=None):
Filter.filtered_list = [pkmn for pkmn in Filter.filtered_list
if self.matches(pkmn, value)]
class NameFilter(Filter):
EXAMPLE_VAL = 'bulb'
def matches(self, pokemon: Pokemon, value: str):
2017-07-06 01:39:28 +00:00
return value in pokemon.get_name()
class RegionFilter(Filter):
2017-10-09 12:45:10 +00:00
EXAMPLE_VAL = ['kanto']
2017-10-09 12:45:10 +00:00
def matches(self, pokemon: Pokemon, value: list):
return pokemon.get_region() in value
class LightFilter(Filter):
EXAMPLE_VAL = 0.7
def matches(self, pokemon: Pokemon, value: float):
return pokemon.get_dark_threshold() > value
class DarkFilter(Filter):
EXAMPLE_VAL = 0.4
def matches(self, pokemon: Pokemon, value: float):
return pokemon.get_dark_threshold() < value
class TypeFilter(Filter):
2017-10-09 12:45:10 +00:00
EXAMPLE_VAL = ['water']
2017-10-09 12:45:10 +00:00
def matches(self, pokemon: Pokemon, value: list):
return pokemon.get_pkmn_type() in value or \
pokemon.get_pkmn_type_secondary() in value
2017-07-06 01:39:28 +00:00
class NonExtrasFilter(Filter):
def matches(self, pokemon: Pokemon, value):
return not pokemon.is_extra()
2017-07-06 01:39:28 +00:00
class ExtrasFilter(Filter):
def matches(self, pokemon: Pokemon, value):
return pokemon.is_extra()