This commit is contained in:
Auric Vente 2024-07-22 02:11:52 -06:00
parent 828a6cb6d4
commit e0c6dc3bde
3 changed files with 36 additions and 7 deletions

View File

@ -55,10 +55,15 @@ class Config:
filter_debouncer_delay: int = 200 filter_debouncer_delay: int = 200
default_population: int = 100 default_population: int = 100
merge_goal: int = 8 merge_goal: int = 8
manifest_path: Path
manifest: dict[str, str]
@staticmethod @staticmethod
def prepare() -> None: def prepare() -> None:
from .storage import Storage
Config.here = Path(__file__).parent Config.here = Path(__file__).parent
Config.manifest_path = Config.here / "manifest.json"
Config.ants_json = Path(appdirs.user_data_dir()) / "cromulant" / "ants.json" Config.ants_json = Path(appdirs.user_data_dir()) / "cromulant" / "ants.json"
if not Config.ants_json.exists(): if not Config.ants_json.exists():
@ -83,3 +88,5 @@ class Config:
Config.emoji_font_path = Config.here / "fonts" / "NotoEmoji-Regular.ttf" Config.emoji_font_path = Config.here / "fonts" / "NotoEmoji-Regular.ttf"
Config.song_path = Config.here / "audio" / "March of the Cyber Ants.mp3" Config.song_path = Config.here / "audio" / "March of the Cyber Ants.mp3"
Config.logo_path = Config.here / "img" / "logo_3.jpg" Config.logo_path = Config.here / "img" / "logo_3.jpg"
Config.manifest = Storage.get_manifest()

View File

@ -40,26 +40,38 @@ class Game:
def prepare() -> None: def prepare() -> None:
Game.fill() Game.fill()
Game.info() Game.info()
Game.intro()
@staticmethod @staticmethod
def update(ant: Ant) -> None: def update(ant: Ant) -> None:
root = QWidget()
container = QHBoxLayout() container = QHBoxLayout()
root.setContentsMargins(0, 0, 0, 0)
container.setContentsMargins(0, 0, 0, 0)
image_label = Game.get_image(ant) image_label = Game.get_image(ant)
right_container = Game.make_right_container(ant) 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)
container.addWidget(right_container) container.addWidget(right_container)
Game.add_container(container) root.setLayout(container)
Game.add_item(root)
@staticmethod @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 from .filter import Filter
root = QWidget() Window.view.insertWidget(0, item)
root.setContentsMargins(0, 0, 0, 0)
container.setContentsMargins(0, 0, 0, 0)
root.setLayout(container)
Window.view.insertWidget(0, root)
while Window.view.count() > Config.max_updates: while Window.view.count() > Config.max_updates:
item = Window.view.takeAt(Window.view.count() - 1) item = Window.view.takeAt(Window.view.count() - 1)
@ -333,3 +345,8 @@ class Game:
Game.start_loop() Game.start_loop()
else: else:
Game.toggle_song() Game.toggle_song()
@staticmethod
def intro() -> None:
version = Config.manifest["version"]
Game.message(f"🐜 🐜 Welcome to Cromulant v{version} 🐜 🐜")

View File

@ -41,3 +41,8 @@ class Storage:
def get_countries() -> Any: def get_countries() -> Any:
with Config.countries_json.open() as file: with Config.countries_json.open() as file:
return json.load(file) return json.load(file)
@staticmethod
def get_manifest() -> Any:
with Config.manifest_path.open() as file:
return json.load(file)