forked from LazoCoder/Pokemon-Terminal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
filters.py
65 lines (41 loc) · 1.62 KB
/
filters.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from argparse import Action
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):
return value in pokemon.get_name()
class RegionFilter(Filter):
EXAMPLE_VAL = ['kanto']
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):
EXAMPLE_VAL = ['water']
def matches(self, pokemon: Pokemon, value: list):
return pokemon.get_pkmn_type() in value or \
pokemon.get_pkmn_type_secondary() in value
class NonExtrasFilter(Filter):
def matches(self, pokemon: Pokemon, value):
return not pokemon.is_extra()
class ExtrasFilter(Filter):
def matches(self, pokemon: Pokemon, value):
return pokemon.is_extra()