scripts/save_state.pyΒΆ
Part of Dungeon Explorer.
1"""SaveBag: a Node holding ``persist=True`` Property snapshots of game-state
2subsystems that aren't themselves Nodes (Inventory, FogOfWar, QuestManager,
3SkillTree).
4
5The :class:`simvx.core.SaveManager` walks the live scene tree and pickles
6every Property flagged ``persist=True``. To bring the non-Node subsystems
7into that envelope we copy their ``to_dict()`` output into this Node's
8properties before saving and rebuild the live objects from the loaded
9properties on apply.
10"""
11
12from __future__ import annotations
13
14from simvx.core import Node, Property
15
16
17class SaveBag(Node):
18 """Container Node for the dict-form snapshots of non-Node subsystems."""
19
20 __save_version__ = 1
21
22 inventory_data = Property(default_factory=dict, hint="Inventory.to_dict() snapshot", persist=True, save_version=1)
23 fog_data = Property(
24 default_factory=dict, hint="FogOfWar.to_dict() snapshot (empty if none)", persist=True, save_version=1
25 )
26 quests_data = Property(default_factory=dict, hint="QuestManager.to_dict() snapshot", persist=True, save_version=1)
27 skills_data = Property(default_factory=dict, hint="SkillTree.to_dict() snapshot", persist=True, save_version=1)
28 dungeon_seed = Property(0, hint="Active dungeon RNG seed (0 = none)", persist=True, save_version=1)
29 has_dungeon_seed = Property(False, hint="True iff dungeon_seed is meaningful", persist=True, save_version=1)
30 opened_chests_data = Property((), hint="Tuple of (level, gx, gy) for opened chests", persist=True, save_version=1)
31 tutorial_seen = Property(False, hint="Tutorial intro shown", persist=True, save_version=1)
32
33 def __init__(self, **kwargs):
34 super().__init__(name="SaveBag", **kwargs)