Implementation:4thfever Cultivation world simulator load game
| Knowledge Sources | |
|---|---|
| Domains | Persistence, Save_Load |
| Last Updated | 2026-10-22 14:00 GMT |
Overview
Concrete tool for loading game state from a JSON save file through section-based deserialization, provided by the Cultivation World Simulator load system.
Description
The load_game function reads a JSON save file, creates a `LoadContext`, and calls `restore_loaded_game(context)` which iterates 8 ordered load sections (RunConfig, WorldCore, SectRuntime, Avatars, RegionRuntime, Membership, Events, Simulator) to reconstruct the world, simulator, and existed sects.
Supporting functions: get_events_db_path (derives SQLite path from save path), check_save_compatibility (currently always returns True in dev phase).
Usage
Import and call this function when:
- Load game: called by `load_game_into_runtime` in the control service
- Testing: called directly with a save path to verify load logic
Code Reference
Source Location
- Repository: cultivation-world-simulator
- File: src/sim/load/load_game.py
Signature
def load_game(save_path: Optional[Path] = None) -> Tuple["World", "Simulator", List["Sect"]]:
"""Load game state from a JSON save file."""
def get_events_db_path(save_path: Path) -> Path:
"""Derive SQLite events DB path from save path (e.g., save.json -> save_events.db)."""
def check_save_compatibility(save_path: Path) -> Tuple[bool, str]:
"""Check save compatibility. Currently always True (dev phase)."""
Import
from src.sim.load.load_game import load_game, get_events_db_path, check_save_compatibility
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| save_path | None | No | Save file path (default: saves_dir / "save.json") |
Outputs
| Name | Type | Description |
|---|---|---|
| return | tuple[World, Simulator, list[Sect]] | Reconstructed game state |
Usage Examples
Load a Save File
from src.sim.load.load_game import load_game
from pathlib import Path
world, sim, existed_sects = load_game(Path("saves/save_20260101_120000.json"))
print(f"Loaded {len(world.avatar_manager.avatars)} avatars")