Mods
This commit is contained in:
parent
aeb81739ba
commit
ac9c7d5dba
|
@ -17,7 +17,7 @@ class Ant:
|
||||||
self.updated = now
|
self.updated = now
|
||||||
self.name = ""
|
self.name = ""
|
||||||
self.status = ""
|
self.status = ""
|
||||||
self.method = ""
|
self.method = "hatched"
|
||||||
self.triumph = 0
|
self.triumph = 0
|
||||||
self.hits = 0
|
self.hits = 0
|
||||||
|
|
||||||
|
@ -62,6 +62,25 @@ class Ant:
|
||||||
tooltip += f"\nTriumph: {self.triumph} | Hits: {self.hits}"
|
tooltip += f"\nTriumph: {self.triumph} | Hits: {self.hits}"
|
||||||
return tooltip
|
return tooltip
|
||||||
|
|
||||||
|
def get_status(self) -> str:
|
||||||
|
if (not self.status) and (not self.method):
|
||||||
|
return "No update yet"
|
||||||
|
|
||||||
|
status = self.status
|
||||||
|
|
||||||
|
if self.method == "triumph":
|
||||||
|
total = f"({self.triumph} total)"
|
||||||
|
status = f"{Config.triumph_icon} {Config.triumph_message} {total}"
|
||||||
|
elif self.method == "hit":
|
||||||
|
total = f"({self.hits} total)"
|
||||||
|
status = f"{Config.hit_icon} {Config.hit_message} {total}"
|
||||||
|
elif self.method == "thinking":
|
||||||
|
status = f"Thinking about {status}"
|
||||||
|
elif self.method == "travel":
|
||||||
|
status = f"Traveling to {status}"
|
||||||
|
|
||||||
|
return status
|
||||||
|
|
||||||
|
|
||||||
class Ants:
|
class Ants:
|
||||||
ants: ClassVar[list[Ant]] = []
|
ants: ClassVar[list[Ant]] = []
|
||||||
|
@ -83,7 +102,7 @@ class Ants:
|
||||||
ant.name = Ants.random_name()
|
ant.name = Ants.random_name()
|
||||||
|
|
||||||
Ants.ants.append(ant)
|
Ants.ants.append(ant)
|
||||||
Ants.announce_hatch(ant)
|
Game.add_update(ant)
|
||||||
|
|
||||||
Ants.save()
|
Ants.save()
|
||||||
Game.update_info()
|
Game.update_info()
|
||||||
|
@ -136,7 +155,7 @@ class Ants:
|
||||||
ant.method = method
|
ant.method = method
|
||||||
ant.updated = Utils.now()
|
ant.updated = Utils.now()
|
||||||
|
|
||||||
Game.add_status(ant)
|
Game.add_update(ant)
|
||||||
Game.update_info()
|
Game.update_info()
|
||||||
Ants.save()
|
Ants.save()
|
||||||
|
|
||||||
|
@ -177,9 +196,8 @@ class Ants:
|
||||||
return top, top_score
|
return top, top_score
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def merge() -> None:
|
def merge(ant_1: Ant | None = None) -> None:
|
||||||
if len(Ants.ants) < 2:
|
from .game import Game
|
||||||
return
|
|
||||||
|
|
||||||
def split(ant: Ant) -> list[str]:
|
def split(ant: Ant) -> list[str]:
|
||||||
return re.split(r"[ -]", ant.name)
|
return re.split(r"[ -]", ant.name)
|
||||||
|
@ -195,6 +213,7 @@ class Ants:
|
||||||
|
|
||||||
return [Utils.capitalize(word) for word in words]
|
return [Utils.capitalize(word) for word in words]
|
||||||
|
|
||||||
|
if not ant_1:
|
||||||
ant_1 = Ants.random_ant()
|
ant_1 = Ants.random_ant()
|
||||||
|
|
||||||
if not ant_1:
|
if not ant_1:
|
||||||
|
@ -226,11 +245,8 @@ class Ants:
|
||||||
if not name:
|
if not name:
|
||||||
return
|
return
|
||||||
|
|
||||||
Ants.announce_terminate(ant_1)
|
Ants.set_terminated(ant_1)
|
||||||
Ants.announce_terminate(ant_2)
|
Ants.set_terminated(ant_2)
|
||||||
|
|
||||||
Ants.ants.remove(ant_1)
|
|
||||||
Ants.ants.remove(ant_2)
|
|
||||||
|
|
||||||
now = Utils.now()
|
now = Utils.now()
|
||||||
|
|
||||||
|
@ -242,27 +258,25 @@ class Ants:
|
||||||
ant.hits = ant_1.hits + ant_2.hits
|
ant.hits = ant_1.hits + ant_2.hits
|
||||||
|
|
||||||
Ants.ants.append(ant)
|
Ants.ants.append(ant)
|
||||||
Ants.announce_hatch(ant)
|
Game.add_update(ant)
|
||||||
Ants.hatch()
|
Ants.hatch()
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def announce_hatch(ant: Ant) -> None:
|
|
||||||
from .game import Game
|
|
||||||
|
|
||||||
image_path = Config.hatched_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, tooltip=ant.tooltip()
|
|
||||||
)
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def clear() -> None:
|
def clear() -> None:
|
||||||
Ants.ants = []
|
Ants.ants = []
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def terminate(ant: Ant) -> None:
|
||||||
|
if ant.method == "terminated":
|
||||||
|
return
|
||||||
|
|
||||||
|
Ants.set_terminated(ant)
|
||||||
|
Ants.hatch()
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def set_terminated(ant: Ant) -> None:
|
||||||
|
from .game import Game
|
||||||
|
|
||||||
|
ant.method = "terminated"
|
||||||
|
Game.add_update(ant)
|
||||||
|
Ants.ants.remove(ant)
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import random
|
import random
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
from PySide6.QtCore import Qt # type: ignore
|
from PySide6.QtCore import Qt # type: ignore
|
||||||
from PySide6.QtWidgets import QHBoxLayout # type: ignore
|
from PySide6.QtWidgets import QHBoxLayout # type: ignore
|
||||||
from PySide6.QtWidgets import QVBoxLayout
|
from PySide6.QtWidgets import QVBoxLayout
|
||||||
from PySide6.QtWidgets import QLabel
|
from PySide6.QtWidgets import QLabel
|
||||||
from PySide6.QtWidgets import QWidget
|
from PySide6.QtWidgets import QWidget
|
||||||
from PySide6.QtGui import QPixmap # type: ignore
|
from PySide6.QtGui import QMouseEvent # type: ignore
|
||||||
|
from PySide6.QtGui import QPixmap
|
||||||
from PySide6.QtCore import QTimer
|
from PySide6.QtCore import QTimer
|
||||||
|
|
||||||
from .config import Config
|
from .config import Config
|
||||||
|
@ -29,47 +29,12 @@ class Game:
|
||||||
Game.update_info()
|
Game.update_info()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def add_status(ant: Ant) -> None:
|
def add_update(
|
||||||
container = QHBoxLayout()
|
ant: Ant,
|
||||||
status = ant.status
|
|
||||||
color = None
|
|
||||||
|
|
||||||
if (not ant.status) and (not ant.method):
|
|
||||||
status = "No update yet"
|
|
||||||
|
|
||||||
if ant.method == "triumph":
|
|
||||||
total = f"({ant.triumph} total)"
|
|
||||||
status = f"{Config.triumph_icon} {Config.triumph_message} {total}"
|
|
||||||
color = Config.triumph_color
|
|
||||||
elif ant.method == "hit":
|
|
||||||
total = f"({ant.hits} total)"
|
|
||||||
status = f"{Config.hit_icon} {Config.hit_message} {total}"
|
|
||||||
color = Config.hit_color
|
|
||||||
elif ant.method == "thinking":
|
|
||||||
status = f"Thinking about {status}"
|
|
||||||
elif ant.method == "travel":
|
|
||||||
status = f"Traveling to {status}"
|
|
||||||
|
|
||||||
tooltip = ant.tooltip()
|
|
||||||
image_label = Game.get_image(Config.status_image_path, color, tooltip=tooltip)
|
|
||||||
right_container = Game.make_right_container(ant.name, status)
|
|
||||||
|
|
||||||
container.addWidget(image_label)
|
|
||||||
container.addSpacing(Config.space_1)
|
|
||||||
container.addWidget(right_container)
|
|
||||||
Game.add_container(container)
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def add_message(
|
|
||||||
title: str,
|
|
||||||
message: str,
|
|
||||||
image_path: Path,
|
|
||||||
color: tuple[int, int, int] | None = None,
|
|
||||||
tooltip: str = "",
|
|
||||||
) -> None:
|
) -> None:
|
||||||
container = QHBoxLayout()
|
container = QHBoxLayout()
|
||||||
image_label = Game.get_image(image_path, color, tooltip=tooltip)
|
image_label = Game.get_image(ant)
|
||||||
right_container = Game.make_right_container(title, message)
|
right_container = Game.make_right_container(ant)
|
||||||
|
|
||||||
container.addWidget(image_label)
|
container.addWidget(image_label)
|
||||||
container.addSpacing(Config.space_1)
|
container.addSpacing(Config.space_1)
|
||||||
|
@ -97,7 +62,17 @@ class Game:
|
||||||
Filter.check()
|
Filter.check()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def make_right_container(title: str, message: str) -> QWidget:
|
def make_right_container(ant: Ant) -> QWidget:
|
||||||
|
if ant.method == "hatched":
|
||||||
|
title = "Hatched"
|
||||||
|
message = f"{ant.name} is born"
|
||||||
|
elif ant.method == "terminated":
|
||||||
|
title = "Terminated"
|
||||||
|
message = f"{ant.name} is gone"
|
||||||
|
else:
|
||||||
|
title = ant.name
|
||||||
|
message = ant.get_status()
|
||||||
|
|
||||||
root = QWidget()
|
root = QWidget()
|
||||||
root.setObjectName("view_right")
|
root.setObjectName("view_right")
|
||||||
container = QVBoxLayout()
|
container = QVBoxLayout()
|
||||||
|
@ -124,8 +99,23 @@ class Game:
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_image(
|
def get_image(
|
||||||
path: Path, color: tuple[int, int, int] | None = None, tooltip: str = ""
|
ant: Ant,
|
||||||
) -> QLabel:
|
) -> QLabel:
|
||||||
|
if ant.method == "hatched":
|
||||||
|
path = Config.hatched_image_path
|
||||||
|
elif ant.method == "terminated":
|
||||||
|
path = Config.terminated_image_path
|
||||||
|
else:
|
||||||
|
path = Config.status_image_path
|
||||||
|
|
||||||
|
if ant.method == "triumph":
|
||||||
|
color = Config.triumph_color
|
||||||
|
elif ant.method == "hit":
|
||||||
|
color = Config.hit_color
|
||||||
|
else:
|
||||||
|
color = None
|
||||||
|
|
||||||
|
tooltip = ant.tooltip()
|
||||||
image_label = QLabel()
|
image_label = QLabel()
|
||||||
image_label.setObjectName("view_image")
|
image_label.setObjectName("view_image")
|
||||||
pixmap = QPixmap(str(path))
|
pixmap = QPixmap(str(path))
|
||||||
|
@ -154,7 +144,7 @@ class Game:
|
||||||
if tooltip:
|
if tooltip:
|
||||||
image_label.setToolTip(tooltip)
|
image_label.setToolTip(tooltip)
|
||||||
|
|
||||||
image_label.mousePressEvent = lambda event: Game.toggle_song()
|
image_label.mousePressEvent = lambda event: Game.image_action(event, ant)
|
||||||
return image_label
|
return image_label
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -207,7 +197,7 @@ class Game:
|
||||||
ants = sorted(Ants.ants, key=lambda ant: ant.updated)
|
ants = sorted(Ants.ants, key=lambda ant: ant.updated)
|
||||||
|
|
||||||
for ant in ants:
|
for ant in ants:
|
||||||
Game.add_status(ant)
|
Game.add_update(ant)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def start_loop() -> None:
|
def start_loop() -> None:
|
||||||
|
@ -289,3 +279,12 @@ class Game:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def update_size() -> None:
|
def update_size() -> None:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def image_action(event: QMouseEvent, ant: Ant) -> None:
|
||||||
|
if event.button() == Qt.LeftButton:
|
||||||
|
Ants.terminate(ant)
|
||||||
|
elif event.button() == Qt.MiddleButton:
|
||||||
|
Ants.merge(ant)
|
||||||
|
else:
|
||||||
|
Game.toggle_song()
|
||||||
|
|
Loading…
Reference in New Issue