From 77dd0be99a811512f90aa393ccd17aad23185416 Mon Sep 17 00:00:00 2001 From: Jamie Gravendeel Date: Sun, 30 Nov 2025 14:40:39 +0100 Subject: [PATCH] games: Add game saving --- cartridges/games.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cartridges/games.py b/cartridges/games.py index 3e7e43a..cc03052 100644 --- a/cartridges/games.py +++ b/cartridges/games.py @@ -96,6 +96,15 @@ class Game(Gio.SimpleActionGroup): creationflags=subprocess.CREATE_NEW_PROCESS_GROUP if os.name == "nt" else 0, ) + def save(self): + """Save the game's properties to disk.""" + properties = {name: getattr(self, name) for name in _PROPERTIES} + + _GAMES_DIR.mkdir(parents=True, exist_ok=True) + path = (_GAMES_DIR / self.game_id).with_suffix(".json") + with path.open(encoding="utf-8") as f: + json.dump(properties, f, indent=4) + def _load() -> Generator[Game]: for path in _GAMES_DIR.glob("*.json"):