From e0c6dc3bde1bd6189214952dffa9478f86f50379 Mon Sep 17 00:00:00 2001 From: Auric Vente Date: Mon, 22 Jul 2024 02:11:52 -0600 Subject: [PATCH] Mods --- cromulant/config.py | 7 +++++++ cromulant/game.py | 31 ++++++++++++++++++++++++------- cromulant/storage.py | 5 +++++ 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/cromulant/config.py b/cromulant/config.py index 350f5cc..19a06f5 100644 --- a/cromulant/config.py +++ b/cromulant/config.py @@ -55,10 +55,15 @@ class Config: filter_debouncer_delay: int = 200 default_population: int = 100 merge_goal: int = 8 + manifest_path: Path + manifest: dict[str, str] @staticmethod def prepare() -> None: + from .storage import Storage + Config.here = Path(__file__).parent + Config.manifest_path = Config.here / "manifest.json" Config.ants_json = Path(appdirs.user_data_dir()) / "cromulant" / "ants.json" if not Config.ants_json.exists(): @@ -83,3 +88,5 @@ class Config: Config.emoji_font_path = Config.here / "fonts" / "NotoEmoji-Regular.ttf" Config.song_path = Config.here / "audio" / "March of the Cyber Ants.mp3" Config.logo_path = Config.here / "img" / "logo_3.jpg" + + Config.manifest = Storage.get_manifest() diff --git a/cromulant/game.py b/cromulant/game.py index 9060643..3d835a6 100644 --- a/cromulant/game.py +++ b/cromulant/game.py @@ -40,26 +40,38 @@ class Game: def prepare() -> None: Game.fill() Game.info() + Game.intro() @staticmethod def update(ant: Ant) -> None: + root = QWidget() container = QHBoxLayout() + root.setContentsMargins(0, 0, 0, 0) + container.setContentsMargins(0, 0, 0, 0) image_label = Game.get_image(ant) right_container = Game.make_right_container(ant) container.addWidget(image_label) container.addSpacing(Config.space_1) container.addWidget(right_container) - Game.add_container(container) + root.setLayout(container) + Game.add_item(root) @staticmethod - def add_container(container: QHBoxLayout) -> None: + def message(text: str) -> None: + root = QWidget() + root.setContentsMargins(0, 10, 0, 10) + container = QHBoxLayout() + container.setAlignment(Qt.AlignCenter) + label = QLabel(text) + container.addWidget(label) + root.setLayout(container) + Game.add_item(root) + + @staticmethod + def add_item(item: QWidget) -> None: from .filter import Filter - root = QWidget() - root.setContentsMargins(0, 0, 0, 0) - container.setContentsMargins(0, 0, 0, 0) - root.setLayout(container) - Window.view.insertWidget(0, root) + Window.view.insertWidget(0, item) while Window.view.count() > Config.max_updates: item = Window.view.takeAt(Window.view.count() - 1) @@ -333,3 +345,8 @@ class Game: Game.start_loop() else: Game.toggle_song() + + @staticmethod + def intro() -> None: + version = Config.manifest["version"] + Game.message(f"🐜 🐜 Welcome to Cromulant v{version} 🐜 🐜") diff --git a/cromulant/storage.py b/cromulant/storage.py index 9596cec..376cdb3 100644 --- a/cromulant/storage.py +++ b/cromulant/storage.py @@ -41,3 +41,8 @@ class Storage: def get_countries() -> Any: with Config.countries_json.open() as file: return json.load(file) + + @staticmethod + def get_manifest() -> Any: + with Config.manifest_path.open() as file: + return json.load(file)