Skip to content

Commit

Permalink
Relocate more data files into the data directory. Fix the task bar ic…
Browse files Browse the repository at this point in the history
…on when running as Python on Windows. Fix the splash screen when running as a PyInstaller binary.
  • Loading branch information
justinbeetle committed Dec 9, 2023
1 parent e2959c3 commit 8e925e6
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 6 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,8 @@ of problems in the add_problem_to_use_dialog method.
2. source pyinstaller_venv/Scripts/activate
3. pip install .
4. pip install pyinstaller
5. pyinstaller --onefile --name pyDragonWarrior --icon icon.ico --add-data "game.xml;./"
--add-data "game_licensed_assets.xml;./" --add-data "data;data" --add-data "icon.png;./" --splash data/images/title.png
src/pydw/game.py
5. pyinstaller --onefile --name pyDragonWarrior --add-data "data;data" --icon data/images/icon.ico --splash
data/images/title.png src/pydw/game.py

### Using Docker

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
15 changes: 12 additions & 3 deletions src/pydw/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ def main() -> None:
print("Running as a PyInstaller binary executable", flush=True)
application_path = os.path.dirname(os.path.abspath(sys.executable))
base_path = os.path.dirname(os.path.abspath(__file__))

# Close the PyInstaller splash screen
import pyi_splash
pyi_splash.close()
else:
# Normal execution
if args.verbose:
Expand All @@ -128,6 +132,11 @@ def main() -> None:
os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
)

# On Windows, change the app user model so that Windows doesn't use the Python icon in the taskbar.
if is_windows():
import ctypes
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID("pydw")

# Set the current working directory to the base path so that the game can be run from any path
# First ensure sys.argv[0] is an absolute path
sys.argv[0] = os.path.abspath(sys.argv[0])
Expand Down Expand Up @@ -225,7 +234,7 @@ def main() -> None:
pygame.init()
pygame.mouse.set_visible(False)
pygame.display.set_caption(application_name)
icon_image_filename = os.path.join(base_path, "icon.png")
icon_image_filename = os.path.join(base_path, "data", "images", "icon.png")
if os.path.exists(icon_image_filename):
try:
icon_image = pygame.image.load(icon_image_filename)
Expand Down Expand Up @@ -271,7 +280,7 @@ def create_game_loop(
if game_loop is None:
if not args.force_use_unlicensed_assets:
# Attempt to load game using the licensed assets
game_xml_path = os.path.join(base_path, "game_licensed_assets.xml")
game_xml_path = os.path.join(base_path, "data", "game_licensed_assets.xml")
game_loop = create_game_loop(
game_xml_path, "Failed to load using licensed assets"
)
Expand All @@ -297,7 +306,7 @@ def create_game_loop(

if game_loop is None:
# Fallback to using unlicensed assets
game_xml_path = os.path.join(base_path, "game.xml")
game_xml_path = os.path.join(base_path, "data", "game.xml")
game_loop = create_game_loop(
game_xml_path, "ERROR: Failed to load unlicensed assets"
)
Expand Down

0 comments on commit 8e925e6

Please sign in to comment.