"""Seed only the isolated formal-heroes database so 1-1 fields SparkBird and BubbleTurtle.""" import json from pathlib import Path import sqlite3 root = Path(__file__).resolve().parents[1] test_root = (root / "Tools/output/formal_heroes").resolve() database = (test_root / "bird_turtle.db").resolve() username = (test_root / "account.txt").read_text(encoding="utf-8-sig").strip() if test_root not in database.parents or not username.startswith("formalheroes_"): raise RuntimeError("Refusing to edit a database or account outside the isolated formal-heroes fixture") with sqlite3.connect(database) as conn: row = conn.execute( "SELECT u.pid, g.state FROM users u JOIN game_states g ON g.pid = u.pid WHERE u.username = ?", (username,), ).fetchone() if row is None: raise RuntimeError("Isolated account has no game state") state = json.loads(row[1]) if state.get("schema") != 9 or state.get("pendingShot") or state.get("pendingBattle"): raise RuntimeError("Isolated save is not a settled schema 9 state") if len(state.get("stages", [])) != 10 or len(state.get("formation", [])) != 6: raise RuntimeError("Unexpected roster or formation width") state["stages"][3] = 1 state["stages"][4] = 1 state["formation"] = [4, 3, -1, -1, -1, -1] state["revision"] = int(state.get("revision", 0)) + 1 conn.execute("UPDATE game_states SET state = ? WHERE pid = ?", (json.dumps(state, ensure_ascii=False), row[0])) print("Seeded isolated account to own and field SparkBird (3) and BubbleTurtle (4)")