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

View File

@ -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:

View File

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