Files
uconsole_asw_game/tools/gen_support_qr.py
T
Claude 88f5132f22 Support link, guides brought up to date (1.3.8)
Support: a QR code of buymeacoffee.com/zquu1xu570 in the uConsole main
menu (src/ui/support.py, rows generated offline by
tools/gen_support_qr.py), a small link on the Remote Crew pairing, lobby
and settings screens and the web-host admin page (never inside
#operations), .github/FUNDING.yml and a badge and Support section in both
READMEs.

Guides: the reference chapter lists 31 kn, VDS +/-4 deg and a VDS glossary
entry and how a solo browser picks the submarine; the READMEs list the VDS
keys and the mission editor's actual runtime subset (the DE README gets its
missing 1.3.1 paragraph and current versions); the co-op, protocol and
web-host guides cover the solo side choice, the seven submarine roles,
sonar_set_vds_depth and the admin shutdown; help strings say submarine
crew 1-7 and that a lowered VDS listens in parallel. Manual, shortcuts and
manual PDFs regenerated. Saves stay v23.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AS36Eg72iLviiSVbCUVNAi
2026-09-28 09:08:13 +00:00

54 lines
1.7 KiB
Python

#!/usr/bin/env python3
"""Regenerate the QR code of the support link in ``src/ui/support.py``.
The game draws the code from the module's rows, so the runtime needs no QR
library. This tool needs ``segno`` (``pip install segno``) and is only run
when ``SUPPORT_URL`` changes; ``--check`` verifies the stored rows.
"""
from __future__ import annotations
import argparse
from pathlib import Path
import re
import sys
ROOT = Path(__file__).resolve().parents[1]
MODULE = ROOT / "src" / "ui" / "support.py"
BEGIN, END = "# --- generated by tools/gen_support_qr.py ---", "# --- end generated ---"
def render_rows(url: str) -> list[str]:
import segno
code = segno.make(url, error="m", micro=False)
return ["".join("1" if cell else "0" for cell in row)
for row in code.matrix_iter(scale=1, border=0)]
def block(rows: list[str]) -> str:
body = "\n".join(f' "{row}",' for row in rows)
return f"{BEGIN}\nQR_ROWS = (\n{body}\n)\n{END}"
def main() -> int:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--check", action="store_true")
args = parser.parse_args()
text = MODULE.read_text(encoding="utf-8")
url = re.search(r'^SUPPORT_URL = "([^"]+)"$', text, re.M).group(1)
start, stop = text.index(BEGIN), text.index(END) + len(END)
updated = text[:start] + block(render_rows(url)) + text[stop:]
if args.check:
if updated != text:
print("support QR is stale: run python tools/gen_support_qr.py", file=sys.stderr)
return 1
print("support QR up to date")
return 0
MODULE.write_text(updated, encoding="utf-8")
print(f"wrote {MODULE.relative_to(ROOT)}")
return 0
if __name__ == "__main__":
raise SystemExit(main())