From 9af842340f7847427d2149522b72ffbd6a59b460 Mon Sep 17 00:00:00 2001 From: Tino Date: Thu, 24 Oct 2024 03:46:26 +0700 Subject: [PATCH] Fix displaying moves of the '???' type in console... once again (#474) --- modules/console.py | 8 +++++--- modules/pokemon.py | 4 ++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/modules/console.py b/modules/console.py index 8e1a1da4..eed98125 100644 --- a/modules/console.py +++ b/modules/console.py @@ -29,7 +29,9 @@ "dragon": "#7038f8", "dark": "#705848", "steel": "#b8b8d0", - "question_marks": "#68a090", + # This is the '???' type, but because we cannot just use that as a colour name, + # it has been renamed. This is done by the `Type` class' `safe_name` property. + "unknown": "#68a090", } ) @@ -102,7 +104,7 @@ def percentage(value, total) -> str: def print_stats(stats: "GlobalStats", encounter: "EncounterInfo") -> None: pokemon = encounter.pokemon - type_colour = pokemon.species.types[0].name.lower() + type_colour = pokemon.species.types[0].safe_name.lower() if pokemon.gender is not None and not pokemon.species.name.startswith("Nidoran"): gender_code = "♂" if pokemon.gender == "male" else "♀" gender_label = "[cyan]Male ♂[/]" if pokemon.gender == "male" else "[pink]Female ♀[/]" @@ -155,7 +157,7 @@ def print_stats(stats: "GlobalStats", encounter: "EncounterInfo") -> None: for learned_move in pokemon.moves: if learned_move is not None: move = learned_move.move - move_list.append(f"[{move.type.name.lower()}]{move.name}[/]") + move_list.append(f"[{move.type.safe_name.lower()}]{move.name}[/]") move_list = f"\n[bold]Moves:[/] {', '.join(move_list)}" # EV Yield diff --git a/modules/pokemon.py b/modules/pokemon.py index 40b4c85d..e4bcf631 100644 --- a/modules/pokemon.py +++ b/modules/pokemon.py @@ -316,6 +316,10 @@ def is_special(self) -> bool: def kind(self) -> str: return "Physical" if self.is_physical else "Special" + @property + def safe_name(self) -> str: + return "Unknown" if self.name == "???" else self.name + def __str__(self): return self.name