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))