mirror of
https://github.com/LazoCoder/Pokemon-Terminal
synced 2024-11-25 05:10:26 +00:00
Multiple regions and types filtering
This commit is contained in:
parent
9e4536657e
commit
b245861fa8
2 changed files with 9 additions and 8 deletions
|
@ -24,6 +24,7 @@ _filters_group.add_argument(
|
|||
help='Filter the pokemons by region',
|
||||
action=filters.RegionFilter,
|
||||
choices=Database.REGIONS,
|
||||
nargs='*',
|
||||
type=str.lower)
|
||||
_filters_group.add_argument(
|
||||
'-l',
|
||||
|
@ -53,6 +54,7 @@ _filters_group.add_argument(
|
|||
help='Filter the pokemons by type.',
|
||||
action=filters.TypeFilter,
|
||||
choices=Database.POKEMON_TYPES,
|
||||
nargs='*',
|
||||
type=str.lower)
|
||||
_filters_group.add_argument(
|
||||
'-ne',
|
||||
|
|
|
@ -27,10 +27,10 @@ class NameFilter(Filter):
|
|||
|
||||
|
||||
class RegionFilter(Filter):
|
||||
EXAMPLE_VAL = 'kanto'
|
||||
EXAMPLE_VAL = ['kanto']
|
||||
|
||||
def matches(self, pokemon: Pokemon, value: str):
|
||||
return pokemon.get_region() == value
|
||||
def matches(self, pokemon: Pokemon, value: list):
|
||||
return pokemon.get_region() in value
|
||||
|
||||
|
||||
class LightFilter(Filter):
|
||||
|
@ -48,12 +48,11 @@ class DarkFilter(Filter):
|
|||
|
||||
|
||||
class TypeFilter(Filter):
|
||||
EXAMPLE_VAL = 'water'
|
||||
EXAMPLE_VAL = ['water']
|
||||
|
||||
def matches(self, pokemon: Pokemon, value: str):
|
||||
value = value.lower()
|
||||
return value in (pokemon.get_pkmn_type(),
|
||||
pokemon.get_pkmn_type_secondary())
|
||||
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):
|
||||
|
|
Loading…
Reference in a new issue