fix: integrate SQLite event storage into load/save system

- Fix load_game to use World.create_with_db() for SQLite event storage
- Add get_events_db_path() to compute event database path from save path
- Add JSON to SQLite migration for backward compatibility with old saves
- Close old EventManager before loading new save to prevent connection leaks
- Add events_db metadata to save file
- Add comprehensive tests for database switching bug and save/load cycle
This commit is contained in:
Zihao Xu
2026-01-07 23:21:55 -08:00
parent a6b8198c3f
commit 06d1bed987
4 changed files with 606 additions and 16 deletions

View File

@@ -1307,6 +1307,11 @@ def api_load_game(req: LoadGameRequest):
if not target_path.exists():
raise HTTPException(status_code=404, detail="File not found")
# 关闭旧 World 的 EventManager释放 SQLite 连接。
old_world = game_instance.get("world")
if old_world and hasattr(old_world, "event_manager"):
old_world.event_manager.close()
# 加载
new_world, new_sim, new_sects = load_game(target_path)