27 lines
681 B
Python
27 lines
681 B
Python
import os
|
|
import json
|
|
|
|
SIM_CONFIGS_DIR = os.getenv("SIM_CONFIGS_DIR", "/app/src/config")
|
|
|
|
_REFERENCE_CONFIG_ID = 1
|
|
|
|
|
|
def load_sim_config(session_id: int) -> dict | None:
|
|
path = os.path.join(SIM_CONFIGS_DIR, f"sim_{session_id:03d}.json")
|
|
try:
|
|
with open(path) as f:
|
|
return json.load(f)
|
|
except Exception:
|
|
return None
|
|
|
|
|
|
def save_sim_config(session_id: int, cfg: dict):
|
|
path = os.path.join(SIM_CONFIGS_DIR, f"sim_{session_id:03d}.json")
|
|
with open(path, "w") as f:
|
|
json.dump(cfg, f, indent=2, ensure_ascii=False)
|
|
|
|
|
|
def load_all_modes() -> dict:
|
|
cfg = load_sim_config(_REFERENCE_CONFIG_ID) or {}
|
|
return cfg.get("modes", {})
|