This commit is contained in:
Auric Vente 2024-07-19 20:17:07 -06:00
parent 959efe2d8e
commit ade8f9486c
3 changed files with 50 additions and 2 deletions

View File

@ -65,6 +65,7 @@ class Ants:
from .game import Game from .game import Game
if len(Ants.ants) >= Config.max_ants: if len(Ants.ants) >= Config.max_ants:
Window.alert("Max ants reached\nTerminate some to hatch new ones")
return return
now = Utils.now() now = Utils.now()
@ -152,12 +153,20 @@ class Ants:
@staticmethod @staticmethod
def get_ants() -> None: def get_ants() -> None:
objs = Storage.get_ants() objs = Storage.get_ants()
changed = False
if len(objs) > Config.max_ants:
objs = objs[: Config.max_ants]
changed = True
for obj in objs: for obj in objs:
ant = Ant() ant = Ant()
ant.from_dict(obj) ant.from_dict(obj)
Ants.ants.append(ant) Ants.ants.append(ant)
if changed:
Ants.save()
@staticmethod @staticmethod
def most_hits() -> Ant | None: def most_hits() -> Ant | None:
if not len(Ants.ants): if not len(Ants.ants):

View File

@ -9,7 +9,7 @@ class Config:
title: str = "Cromulant" title: str = "Cromulant"
width: int = 900 width: int = 900
height: int = 900 height: int = 900
max_ants: int = 100 max_ants: int = 10
here: Path here: Path
ants_json: Path ants_json: Path
icon_path: Path icon_path: Path
@ -42,6 +42,13 @@ class Config:
context_menu_text_color: str = "white" context_menu_text_color: str = "white"
context_menu_hover_background_color: str = "rgb(36, 36, 36)" context_menu_hover_background_color: str = "rgb(36, 36, 36)"
context_menu_hover_text_color: str = "white" context_menu_hover_text_color: str = "white"
message_box_background_color: str = "rgb(22, 22, 22)"
message_box_text_color: str = "white"
message_box_label_text_color: str = "white"
message_box_button_background_color: str = "rgb(44, 44, 44)"
message_box_button_text_color: str = "white"
message_box_button_hover_background_color: str = "rgb(66, 66, 66)"
message_box_button_hover_text_color: str = "white"
@staticmethod @staticmethod
def prepare() -> None: def prepare() -> None:

View File

@ -71,7 +71,11 @@ class Window:
Window.root.setAlignment(Qt.AlignTop) Window.root.setAlignment(Qt.AlignTop)
Window.window.setCentralWidget(central_widget) Window.window.setCentralWidget(central_widget)
Window.window.setWindowIcon(QIcon(str(Config.icon_path))) Window.window.setWindowIcon(QIcon(str(Config.icon_path)))
Window.root.setContentsMargins(0, 0, 0, 0)
Window.set_style()
@staticmethod
def set_style() -> None:
font_id = QFontDatabase.addApplicationFont(str(Config.font_path)) font_id = QFontDatabase.addApplicationFont(str(Config.font_path))
emoji_font_id = QFontDatabase.addApplicationFont(str(Config.emoji_font_path)) emoji_font_id = QFontDatabase.addApplicationFont(str(Config.emoji_font_path))
@ -97,11 +101,30 @@ class Window:
background-color: {Config.context_menu_hover_background_color}; background-color: {Config.context_menu_hover_background_color};
color: {Config.context_menu_hover_text_color}; color: {Config.context_menu_hover_text_color};
}} }}
QMessageBox {{
background-color: {Config.message_box_background_color};
color: {Config.message_box_text_color};
}}
QMessageBox QLabel {{
background-color: {Config.message_box_background_color};
color: {Config.message_box_label_text_color};
}}
QMessageBox QPushButton {{
background-color: {Config.message_box_button_background_color};
color: {Config.message_box_button_text_color};
}}
QMessageBox QPushButton:hover {{
background-color: {Config.message_box_button_hover_background_color};
color: {Config.message_box_button_hover_text_color};
}}
""".strip() """.strip()
Window.app.setStyleSheet(style) Window.app.setStyleSheet(style)
Window.app.setFont(Window.font) Window.app.setFont(Window.font)
Window.root.setContentsMargins(0, 0, 0, 0)
@staticmethod @staticmethod
def add_buttons() -> None: def add_buttons() -> None:
@ -245,3 +268,12 @@ class Window:
@staticmethod @staticmethod
def stop_audio() -> None: def stop_audio() -> None:
Window.player.stop() Window.player.stop()
@staticmethod
def alert(message: str) -> None:
msg_box = QMessageBox()
msg_box.setIcon(QMessageBox.Information)
msg_box.setText(message)
msg_box.setWindowTitle("Information")
msg_box.setStandardButtons(QMessageBox.Ok)
msg_box.exec()