"""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, "input_device": None, "output_device": None, "last_dir": None, "background_enabled": True, "background_opacity": 0.1} OBSOLETE = ("theme", "background_image", "language") # the editor starts in the game's language 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())