Skip to content

Commit

Permalink
build: add splash image and icon
Browse files Browse the repository at this point in the history
  • Loading branch information
u8slvn committed Aug 24, 2024
1 parent 8491d9c commit 3e80c27
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 10 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,10 @@ dmypy.json

# Cython debug symbols
cython_debug/

# UPX archive
upx-*.zip
packaging/upx-*

# Versionfile
**/versionfile.txt
Binary file added images/icon-48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 9 additions & 4 deletions scripts/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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')}"]
Expand Down
11 changes: 7 additions & 4 deletions src/doggo/__init__.py
Original file line number Diff line number Diff line change
@@ -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")
2 changes: 2 additions & 0 deletions src/doggo/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
)

Expand Down
Binary file added src/doggo/assets/icon-256.ico
Binary file not shown.
Binary file added src/doggo/assets/icon-256.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/doggo/assets/splash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 12 additions & 2 deletions src/doggo/world.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -12,20 +15,27 @@
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,
borderless=True,
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()
Expand Down Expand Up @@ -88,4 +98,4 @@ def stop() -> None:
"""Stop the world."""
pg.quit()
logger.info("World stopped. Dog is going to sleep.")
exit()
sys.exit()

0 comments on commit 3e80c27

Please sign in to comment.