Files
seagull-game/app/desktop.py

71 lines
2.5 KiB
Python
Raw Normal View History

2025-07-29 12:50:35 -07:00
#!/usr/bin/env python
## \file desktop.py
# \brief Entrypoint file for desktop versions of the Seagull Game.
2025-07-29 12:50:35 -07:00
import argparse
import os
import pathlib
import sys
import threading
import webview
import flask
import fs.tree
try:
import pyi_splash
except ImportError:
class NullModule():
def update_text(self, *args, **kwargs):
pass
def close(self):
pass
pyi_splash = NullModule()
2025-07-29 12:50:35 -07:00
from pylocal import core, actions, desktop, dev, gamedata, items, tick, upgrades
2025-07-29 12:50:35 -07:00
core.desktop_mode = True
sig_exit = threading.Event()
argp = argparse.ArgumentParser("seagull")
2025-08-05 17:57:43 -07:00
argp.add_argument("-d", "--debug", action="store_true", help="Launches the game in \"debug mode\".")
2025-07-29 12:50:35 -07:00
argo = argp.parse_args()
@core.app.route("/")
def index():
if not core.base_context_live:
core.render_base_context()
core.base_context["scripts"].insert(0, (core.app.url_for("static", filename="js/desktop-structuredclone.js"), False))
core.base_context["scripts"].insert(1, (core.app.url_for("static", filename="js/seagull-desktop.js"), False))
gamedata.vfs.copy_out("templates/main_page.j2", dest=core.path_appdir.as_posix())
2025-07-29 12:50:35 -07:00
return flask.render_template("main_page.j2", **core.base_context)
if __name__ == "__main__":
try:
pyi_splash.update_text("Determining storage directory")
2025-07-29 12:50:35 -07:00
if sys.platform.startswith("win"):
storage_dir = pathlib.Path(os.environ["APPDATA"]) / "seagull"
elif sys.platform.startswith("darwin"): # macos
storage_dir = pathlib.Path(os.environ["HOME"]) / "Library/Application Support/seagull"
else:
2025-08-22 13:01:58 -07:00
# TODO: check if XDG env vars are set and prioritize those
2025-07-29 12:50:35 -07:00
storage_dir = pathlib.Path(os.environ["HOME"]) / ".local/share/seagull"
2025-07-31 11:28:09 -07:00
desktop.path_storagedir = storage_dir
2025-07-29 12:50:35 -07:00
pyi_splash.update_text("Loading VFS")
gamedata.vfs.load_data_source("basepak")
gamedata.vfs.load_data_source("seagull.pak", proto="zip")
2025-07-29 12:50:35 -07:00
if argo.debug:
desktop.api.debug_mode = True
pyi_splash.update_text("Starting browser shell")
2025-07-29 12:50:35 -07:00
storage_dir.mkdir(exist_ok=True, parents=True)
webview.create_window("Seagull Game", core.app, js_api=desktop.api, width=1280, height=720)
pyi_splash.close()
2025-07-29 12:50:35 -07:00
webview.start(private_mode=False, storage_path=storage_dir.as_posix(), debug=True if argo.debug else False)
except KeyboardInterrupt:
core.log.info("Goodnight, moon ...")
sig_exit.set()
sys.exit(0)