oldschool-toontown/otp/settings/Settings.py
2021-07-09 00:16:41 -04:00

33 lines
823 B
Python

import json
import os
class Settings:
def __init__(self):
self.__settings = {}
self.__filename = 'useropt.json'
def doSavedSettingsExist(self):
return os.path.exists(self.__filename)
def readSettings(self):
if not self.doSavedSettingsExist():
self.__settings = {}
return
try:
with open(self.__filename, 'r') as f:
self.__settings = json.load(f)
except:
self.__settings = {}
def writeSettings(self):
with open(self.__filename, 'w+') as f:
json.dump(self.__settings, f, indent=4)
def updateSetting(self, setting, value):
self.__settings[setting] = value
def getSetting(self, setting, default=None):
return self.__settings.get(setting, default)