From 4d3111122511f6e3155a2fd72cf8bd05d8c19822 Mon Sep 17 00:00:00 2001 From: Auric Vente Date: Sun, 21 Jul 2024 01:41:07 -0600 Subject: [PATCH] Mods --- cromulant/ants.py | 34 +++++++++++++--------------------- cromulant/game.py | 11 +++-------- cromulant/window.py | 2 +- 3 files changed, 17 insertions(+), 30 deletions(-) diff --git a/cromulant/ants.py b/cromulant/ants.py index 318bedf..f6ef08e 100644 --- a/cromulant/ants.py +++ b/cromulant/ants.py @@ -55,6 +55,13 @@ class Ant: def get_score(self) -> int: return self.triumph - self.hits + def tooltip(self) -> str: + tooltip = "" + tooltip += f"Updated: {Utils.to_date(self.updated)}" + tooltip += f"\nCreated: {Utils.to_date(self.created)}" + tooltip += f"\nTriumph: {self.triumph} | Hits: {self.hits}" + return tooltip + class Ants: ants: ClassVar[list[Ant]] = [] @@ -93,9 +100,6 @@ class Ants: def terminate() -> None: from .game import Game - if Ants.empty(): - return - ant = Ants.random_ant() if not ant: @@ -121,9 +125,6 @@ class Ants: @staticmethod def random_ant(ignore: list[Ant] | None = None) -> Ant | None: - if Ants.empty(): - return None - if ignore: ants = [a for a in Ants.ants if a not in ignore] else: @@ -139,15 +140,8 @@ class Ants: def save() -> None: Storage.save_ants(Ants.ants) - @staticmethod - def empty() -> bool: - return len(Ants.ants) == 0 - @staticmethod def get_next() -> Ant | None: - if Ants.empty(): - return None - now = Utils.now() ages = [(now - ant.updated) for ant in Ants.ants] @@ -166,9 +160,6 @@ class Ants: @staticmethod def get_current() -> Ant | None: - if Ants.empty(): - return None - return max(Ants.ants, key=lambda ant: ant.updated) @staticmethod @@ -216,9 +207,6 @@ class Ants: @staticmethod def get_top_ant() -> tuple[Ant, int] | None: - if Ants.empty(): - return None - top = None top_score = 0 @@ -308,14 +296,18 @@ class Ants: from .game import Game image_path = Config.hatched_image_path - Game.add_message("Hatched", f"{ant.name} is born", image_path) + Game.add_message( + "Hatched", f"{ant.name} is born", image_path, tooltip=ant.tooltip() + ) @staticmethod def announce_terminate(ant: Ant) -> None: from .game import Game image_path = Config.terminated_image_path - Game.add_message("Terminated", f"{ant.name} is gone", image_path) + Game.add_message( + "Terminated", f"{ant.name} is gone", image_path, tooltip=ant.tooltip() + ) @staticmethod def clear() -> None: diff --git a/cromulant/game.py b/cromulant/game.py index 9630566..4a0d0af 100644 --- a/cromulant/game.py +++ b/cromulant/game.py @@ -47,10 +47,7 @@ class Game: elif ant.method == "travel": status = f"Traveling to {status}" - tooltip = "" - tooltip += f"Updated: {Utils.to_date(ant.updated)}" - tooltip += f"\nCreated: {Utils.to_date(ant.created)}" - tooltip += f"\nTriumph: {ant.triumph} | Hits: {ant.hits}" + tooltip = ant.tooltip() image_label = Game.get_image(Config.status_image_path, color, tooltip=tooltip) right_container = Game.make_right_container(ant.name, status) @@ -65,9 +62,10 @@ class Game: message: str, image_path: Path, color: tuple[int, int, int] | None = None, + tooltip: str = "", ) -> None: container = QHBoxLayout() - image_label = Game.get_image(image_path, color) + image_label = Game.get_image(image_path, color, tooltip=tooltip) right_container = Game.make_right_container(title, message) container.addWidget(image_label) @@ -158,9 +156,6 @@ class Game: @staticmethod def get_status() -> None: - if Ants.empty(): - return - ant = Ants.get_next() if not ant: diff --git a/cromulant/window.py b/cromulant/window.py index 05b80eb..1e30be0 100644 --- a/cromulant/window.py +++ b/cromulant/window.py @@ -180,7 +180,7 @@ class Window: root = QWidget() container = QHBoxLayout() btn_restart = QPushButton("Restart") - btn_restart.setToolTip(f"Restart with a new set of ants") + btn_restart.setToolTip("Restart with a new set of ants") btn_restart.clicked.connect(Game.restart) Window.speed = QComboBox()