| """JSON save slots.""" | |
| from __future__ import annotations | |
| import json | |
| from pathlib import Path | |
| from typing import Any | |
| from game.io.migrate import migrate | |
| def save_slot(path: Path, state: dict) -> None: | |
| path.parent.mkdir(parents=True, exist_ok=True) | |
| state = migrate(dict(state)) | |
| path.write_text(json.dumps(state, ensure_ascii=False, indent=2), encoding="utf-8") | |
| def load_slot(path: Path) -> dict: | |
| raw = json.loads(path.read_text(encoding="utf-8")) | |
| return migrate(raw) | |