diff --git a/.gitignore b/.gitignore index 3c69019..83f601e 100644 --- a/.gitignore +++ b/.gitignore @@ -153,3 +153,10 @@ dmypy.json # Cython debug symbols cython_debug/ + +# UPX archive +upx-*.zip +packaging/upx-* + +# Versionfile +**/versionfile.txt diff --git a/images/icon-48.png b/images/icon-48.png new file mode 100644 index 0000000..279e36d Binary files /dev/null and b/images/icon-48.png differ diff --git a/scripts/build.py b/scripts/build.py index 2011791..c896e26 100644 --- a/scripts/build.py +++ b/scripts/build.py @@ -61,7 +61,7 @@ def build_pyinstaller_args( ) -> list[str]: logger.info("Build Pyinstaller args.") build_args = [] - script_entrypoint = f"{PACKAGE_NAME}/__main__.py" + script_entrypoint = f"src/{PACKAGE_NAME}/__main__.py" logger.info(f"entrypoint: {script_entrypoint}") build_args += [script_entrypoint] @@ -75,11 +75,16 @@ def build_pyinstaller_args( logger.info(f"Output exe filename: {output_filename}") build_args += ["-n", output_filename] - logger.info(f"Output file icon: {ASSETS_PATH.joinpath('icon-48.png')}") - build_args += ["--icon", f"{ASSETS_PATH.joinpath('icon-48.png')}"] + logger.info(f"Output file icon: {ASSETS_PATH.joinpath('icon-256.ico')}") + build_args += ["--icon", f"{ASSETS_PATH.joinpath('icon-256.ico')}"] logger.info(f"Add assets folder: {ASSETS_PATH}") - build_args += ["--add-data", f"{ASSETS_PATH};./{ASSETS_FOLDER}"] + build_args += ["--add-data", f"{ASSETS_PATH}/*;./{ASSETS_FOLDER}"] + for items in ASSETS_PATH.glob("**/*"): + if not items.is_dir(): + continue + logger.info(f"Add data: {items};./{ASSETS_FOLDER}/{items.name}") + build_args += ["--add-data", f"{items};./{ASSETS_FOLDER}/{items.name}"] logger.info(f"Add splash image: {ASSETS_PATH.joinpath('splash.png')}") build_args += ["--splash", f"{ASSETS_PATH.joinpath('splash.png')}"] diff --git a/src/doggo/__init__.py b/src/doggo/__init__.py index 2119d2f..4ba13ff 100644 --- a/src/doggo/__init__.py +++ b/src/doggo/__init__.py @@ -1,11 +1,14 @@ from __future__ import annotations -from importlib import metadata +import sys + from pathlib import Path +from doggo.config import COMPILED_ENV -__app_name__ = "doggo" -__version__ = metadata.version(__app_name__) -ROOT_PATH = Path(__file__).parent +if COMPILED_ENV: + ROOT_PATH = Path(sys._MEIPASS) # type: ignore +elif __file__: + ROOT_PATH = Path(__file__).parent ASSETS_PATH = ROOT_PATH.joinpath("assets") diff --git a/src/doggo/__main__.py b/src/doggo/__main__.py index a45609d..bfa7691 100644 --- a/src/doggo/__main__.py +++ b/src/doggo/__main__.py @@ -2,6 +2,7 @@ import pygame as pg +from doggo import ASSETS_PATH from doggo import config from doggo.config import COMPILED_ENV from doggo.world import World @@ -21,6 +22,7 @@ def run() -> None: world = World( title=config.WORLD_TITLE, size=(config.WORLD_WIDTH, config.WORLD_HEIGHT), + icon=ASSETS_PATH.joinpath("icon-256.png"), fps=config.WORLD_FPS, ) diff --git a/src/doggo/assets/icon-256.ico b/src/doggo/assets/icon-256.ico new file mode 100644 index 0000000..c751096 Binary files /dev/null and b/src/doggo/assets/icon-256.ico differ diff --git a/src/doggo/assets/icon-256.png b/src/doggo/assets/icon-256.png new file mode 100644 index 0000000..fc3afbc Binary files /dev/null and b/src/doggo/assets/icon-256.png differ diff --git a/src/doggo/assets/splash.png b/src/doggo/assets/splash.png new file mode 100644 index 0000000..17aa3b2 Binary files /dev/null and b/src/doggo/assets/splash.png differ diff --git a/src/doggo/world.py b/src/doggo/world.py index 392eeaa..1432285 100644 --- a/src/doggo/world.py +++ b/src/doggo/world.py @@ -1,7 +1,10 @@ from __future__ import annotations +import sys import time +from typing import TYPE_CHECKING + import pygame as pg from loguru import logger @@ -12,13 +15,19 @@ from doggo.ui import DraggableWindow +if TYPE_CHECKING: + from pathlib import Path + + class World: """The world where the dog lives. It contains the game loop and the main logic of the game. """ - def __init__(self, title: str, size: tuple[int, int], fps: int = 60) -> None: + def __init__( + self, title: str, size: tuple[int, int], icon: Path, fps: int = 60 + ) -> None: self.window: pg.window.Window = pg.window.Window( title=title, size=size, @@ -26,6 +35,7 @@ def __init__(self, title: str, size: tuple[int, int], fps: int = 60) -> None: always_on_top=True, ) self.screen: pg.Surface = self.window.get_surface() + self.window.set_icon(pg.image.load(icon).convert_alpha()) self.draggable: DraggableWindow = DraggableWindow(window=self.window) self.fps: int = fps self.clock: pg.time.Clock = pg.time.Clock() @@ -88,4 +98,4 @@ def stop() -> None: """Stop the world.""" pg.quit() logger.info("World stopped. Dog is going to sleep.") - exit() + sys.exit()