Files
UnheardCity/ackit/settings.py
2026-10-09 02:48:24 +02:00

33 lines
848 B
Python

"""Small JSON settings file shared by the CLI and the editor (user config folder)."""
import json
import os
from .paths import user_dir
DEFAULTS = {"game_dir": None, "store_root": None, "full_backup": True, "language": None,
"input_device": None, "output_device": None, "last_dir": None,
"background_enabled": True, "background_opacity": 0.1}
OBSOLETE = ("theme", "background_image")
def path():
return os.path.join(user_dir("config"), "settings.json")
def load():
s = dict(DEFAULTS)
try:
s.update(json.load(open(path(), encoding="utf-8")))
except (OSError, ValueError):
pass
for k in OBSOLETE:
s.pop(k, None)
return s
def save(s):
tmp = path() + ".tmp"
with open(tmp, "w", encoding="utf-8") as f:
json.dump(s, f, indent=1)
os.replace(tmp, path())