Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:4thfever Cultivation world simulator save load control

From Leeroopedia
Knowledge Sources
Domains Persistence, Server
Last Updated 2026-10-22 14:00 GMT

Overview

Concrete tool for orchestrating save, load, and delete operations through the runtime mutation lock with progress tracking and language synchronization, provided by the Cultivation World Simulator save/load control service.

Description

The save_load_control module provides three top-level functions:

  • save_current_game: reads world/sim from runtime, validates custom name, calls `save_game`, returns result
  • load_game_into_runtime: validates filename, resolves save path, runs the full load inside `runtime.run_mutation()` with progress tracking, language sync, and runtime reinitialization
  • delete_save_file: validates filename, removes JSON save and SQLite events DB

`load_game_into_runtime` is the most complex: it broadcasts a language-sync toast, switches the backend locale to match the save's language, scans avatar assets, loads the save, sets world/sim on runtime, restores run config, and finalizes initialization.

Usage

Import and call these functions when:

  • API command endpoints: `GameCommandService.save_game`, `load_game`, `delete_save` delegate to these
  • Direct server logic: called by the save/load control flow

Code Reference

Source Location

Signature

def save_current_game(
    runtime,
    *,
    custom_name: str | None,
    validate_save_name: Callable[[str], bool],
    save_game,
    sects_by_id,
) -> dict[str, Any]:
    """Save the current game state."""

async def load_game_into_runtime(
    runtime,
    *,
    filename: str,
    saves_dir,
    fallback_saves_dirs=None,
    get_save_info,
    language_manager,
    manager,
    t,
    apply_runtime_content_locale,
    scan_avatar_assets,
    load_game,
    get_settings_service,
    _model_to_dict,
) -> dict[str, Any]:
    """Load a save file into the runtime with full reinitialization."""

def delete_save_file(
    *,
    filename: str,
    saves_dir,
    fallback_saves_dirs=None,
    get_events_db_path,
) -> dict[str, Any]:
    """Delete a save file and its events database."""

def validate_save_filename(filename: str) -> None:
    """Reject filenames containing path traversal sequences."""

def list_saves_query(*, list_saves) -> dict[str, Any]:
    """List saves formatted for the API response."""

Import

from src.server.services.save_load_control import (
    save_current_game, load_game_into_runtime, delete_save_file,
    validate_save_filename, list_saves_query,
)

I/O Contract

Inputs (load_game_into_runtime)

Name Type Required Description
runtime GameSessionRuntime Yes Runtime with mutation lock
filename str Yes Save file name
saves_dir Path Yes Saves directory
load_game Callable Yes Load function (from src/sim/load)

Outputs

Name Type Description
return dict {"status": "ok", "message": ...} on success
(side effects) None World/sim set on runtime; roleplay cleared; locale synced; progress tracked

Usage Examples

Load Game via API

from src.server.services.save_load_control import load_game_into_runtime

result = await load_game_into_runtime(
    runtime=runtime,
    filename="save_20260101_120000.json",
    saves_dir=config.paths.saves,
    fallback_saves_dirs=fallback_dirs,
    get_save_info=get_save_info,
    language_manager=lang_mgr,
    manager=ws_manager,
    t=t,
    apply_runtime_content_locale=apply_locale,
    scan_avatar_assets=scan_assets,
    load_game=load_game,
    get_settings_service=get_settings_service,
    _model_to_dict=model_to_dict,
)

Related Pages

Implements Principle

Required Environments

Uses Heuristics

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment