seagull-game/app/desktop.py

47 lines
1.7 KiB
Python
Raw Normal View History

2025-07-29 12:50:35 -07:00
#!/usr/bin/env python
import argparse
import os
import pathlib
import sys
import threading
import webview
import flask
2025-08-05 17:57:43 -07:00
from pylocal import core, actions, desktop, dev, items, tick
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"))
core.base_context["scripts"].insert(1, core.app.url_for("static", filename="js/seagull-desktop.js"))
return flask.render_template("main_page.j2", **core.base_context)
if __name__ == "__main__":
try:
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:
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
if argo.debug:
desktop.api.debug_mode = True
storage_dir.mkdir(exist_ok=True, parents=True)
webview.create_window("Seagull Game", core.app, js_api=desktop.api)
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)