This commit is contained in:
Auric Vente 2024-07-21 01:41:07 -06:00
parent 6964d3fb18
commit 4d31111225
3 changed files with 17 additions and 30 deletions

View File

@ -55,6 +55,13 @@ class Ant:
def get_score(self) -> int: def get_score(self) -> int:
return self.triumph - self.hits 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: class Ants:
ants: ClassVar[list[Ant]] = [] ants: ClassVar[list[Ant]] = []
@ -93,9 +100,6 @@ class Ants:
def terminate() -> None: def terminate() -> None:
from .game import Game from .game import Game
if Ants.empty():
return
ant = Ants.random_ant() ant = Ants.random_ant()
if not ant: if not ant:
@ -121,9 +125,6 @@ class Ants:
@staticmethod @staticmethod
def random_ant(ignore: list[Ant] | None = None) -> Ant | None: def random_ant(ignore: list[Ant] | None = None) -> Ant | None:
if Ants.empty():
return None
if ignore: if ignore:
ants = [a for a in Ants.ants if a not in ignore] ants = [a for a in Ants.ants if a not in ignore]
else: else:
@ -139,15 +140,8 @@ class Ants:
def save() -> None: def save() -> None:
Storage.save_ants(Ants.ants) Storage.save_ants(Ants.ants)
@staticmethod
def empty() -> bool:
return len(Ants.ants) == 0
@staticmethod @staticmethod
def get_next() -> Ant | None: def get_next() -> Ant | None:
if Ants.empty():
return None
now = Utils.now() now = Utils.now()
ages = [(now - ant.updated) for ant in Ants.ants] ages = [(now - ant.updated) for ant in Ants.ants]
@ -166,9 +160,6 @@ class Ants:
@staticmethod @staticmethod
def get_current() -> Ant | None: def get_current() -> Ant | None:
if Ants.empty():
return None
return max(Ants.ants, key=lambda ant: ant.updated) return max(Ants.ants, key=lambda ant: ant.updated)
@staticmethod @staticmethod
@ -216,9 +207,6 @@ class Ants:
@staticmethod @staticmethod
def get_top_ant() -> tuple[Ant, int] | None: def get_top_ant() -> tuple[Ant, int] | None:
if Ants.empty():
return None
top = None top = None
top_score = 0 top_score = 0
@ -308,14 +296,18 @@ class Ants:
from .game import Game from .game import Game
image_path = Config.hatched_image_path 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 @staticmethod
def announce_terminate(ant: Ant) -> None: def announce_terminate(ant: Ant) -> None:
from .game import Game from .game import Game
image_path = Config.terminated_image_path 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 @staticmethod
def clear() -> None: def clear() -> None:

View File

@ -47,10 +47,7 @@ class Game:
elif ant.method == "travel": elif ant.method == "travel":
status = f"Traveling to {status}" status = f"Traveling to {status}"
tooltip = "" tooltip = ant.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}"
image_label = Game.get_image(Config.status_image_path, color, tooltip=tooltip) image_label = Game.get_image(Config.status_image_path, color, tooltip=tooltip)
right_container = Game.make_right_container(ant.name, status) right_container = Game.make_right_container(ant.name, status)
@ -65,9 +62,10 @@ class Game:
message: str, message: str,
image_path: Path, image_path: Path,
color: tuple[int, int, int] | None = None, color: tuple[int, int, int] | None = None,
tooltip: str = "",
) -> None: ) -> None:
container = QHBoxLayout() 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) right_container = Game.make_right_container(title, message)
container.addWidget(image_label) container.addWidget(image_label)
@ -158,9 +156,6 @@ class Game:
@staticmethod @staticmethod
def get_status() -> None: def get_status() -> None:
if Ants.empty():
return
ant = Ants.get_next() ant = Ants.get_next()
if not ant: if not ant:

View File

@ -180,7 +180,7 @@ class Window:
root = QWidget() root = QWidget()
container = QHBoxLayout() container = QHBoxLayout()
btn_restart = QPushButton("Restart") 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) btn_restart.clicked.connect(Game.restart)
Window.speed = QComboBox() Window.speed = QComboBox()