#!/usr/bin/env python3 """Builds DungeonCraft as one self-contained HTML file (no server needed, works from file://). The JavaScript bundle, the plugin and the WASM module (base64) are embedded; fetching "dungeoncraft.wasm" is answered from the embedded bytes. Service worker and manifest are left out. Without the savegame service the game uses savegame files (download / file picker), so savegames downloaded from the server open in the standalone version as well. usage: make_standalone.py """ import base64 import pathlib import sys www = pathlib.Path(sys.argv[1]) out = pathlib.Path(sys.argv[2]) wasm = base64.b64encode((www / "dungeoncraft.wasm").read_bytes()).decode() bundle = (www / "mq_js_bundle.js").read_text() plugin = (www / "dc_plugin.js").read_text() icon = base64.b64encode((www / "icons" / "icon-192.png").read_bytes()).decode() # keep a "" inside the code from ending the script element def safe(js: str) -> str: return js.replace(" DungeonCraft """ out.write_text(html) print(f"{out}: {len(html) // 1024} KB")