docker000 / game /io /save.py
seachen's picture
Deploy Quiet Town Corner Shop Docker demo (Gradio + Python sim) (part 5)
3831e97 verified
Raw
History Blame Contribute Delete
489 Bytes
"""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)