You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
977 B

from ..objects.pokemon import Pokemon
from ..core.location import Location
from thefuzz.fuzz import partial_ratio
class PokemonList():
def __init__(self, *args: Pokemon):
self.pokemons = [*args]
def sort_by_name(self, reverse=False):
self.pokemons.sort(key=lambda pokemon: pokemon.name, reverse=reverse)
def sort_by_cp(self, reverse=False):
self.pokemons.sort(key=lambda pokemon: pokemon.cp, reverse=reverse)
def sort_by_level(self, reverse=False):
self.pokemons.sort(key=lambda pokemon: pokemon.level, reverse=reverse)
def sort_by_distance(self, location: Location, reverse=False):
self.pokemons.sort(key=lambda pokemon: location.distance(pokemon.location), reverse=False)
def get_at(self, index:int):
return self.pokemons[index]
def search_by_name(self, query:str):
return PokemonList(*filter(lambda pokemon: partial_ratio(query.lower(), pokemon.name) >= 80, self.pokemons))