oldschool-toontown/otp/settings/Settings.py

34 lines
823 B
Python
Raw Permalink Normal View History

2021-07-07 19:56:19 -05:00
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 = {}
2021-07-07 20:30:51 -05:00
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
2021-07-07 19:56:19 -05:00
def getSetting(self, setting, default=None):
2021-07-08 23:16:41 -05:00
return self.__settings.get(setting, default)