From db25aaf10d29b84064ed266b65861d128d076aa3 Mon Sep 17 00:00:00 2001 From: John Cote Date: Wed, 7 Jul 2021 20:56:19 -0400 Subject: [PATCH] settings: Initial commit --- libotp/__init__.py | 1 - libotp/settings/Settings.py | 80 ---------------------------- otp/settings/Settings.py | 27 ++++++++++ {libotp => otp}/settings/__init__.py | 0 toontown/shtiker/OptionsPage.py | 6 --- toontown/toonbase/DisplayOptions.py | 22 +++----- toontown/toonbase/ToonBase.py | 19 +++---- 7 files changed, 43 insertions(+), 112 deletions(-) delete mode 100644 libotp/settings/Settings.py create mode 100644 otp/settings/Settings.py rename {libotp => otp}/settings/__init__.py (100%) diff --git a/libotp/__init__.py b/libotp/__init__.py index dbc1c03..09acffd 100644 --- a/libotp/__init__.py +++ b/libotp/__init__.py @@ -1,2 +1 @@ from panda3d.otp import * -from .settings.Settings import Settings diff --git a/libotp/settings/Settings.py b/libotp/settings/Settings.py deleted file mode 100644 index 8ff63ac..0000000 --- a/libotp/settings/Settings.py +++ /dev/null @@ -1,80 +0,0 @@ -class Settings: - GL = 0 - DX7 = 1 - DX8 = 5 - - @staticmethod - def readSettings(): - pass # todo - - @staticmethod - def writeSettings(): - pass # lol not yet - - @staticmethod - def setWindowedMode(_): - pass - - @staticmethod - def getWindowedMode(): - return 1 - - @staticmethod - def setMusic(_): - pass - - @staticmethod - def getMusic(): - return 1 - - @staticmethod - def setSfx(_): - pass - - @staticmethod - def getSfx(): - return 1 - - @staticmethod - def setToonChatSounds(_): - pass - - @staticmethod - def getToonChatSounds(): - return 1 - - @staticmethod - def setResolutionDimensions(_, __): - pass - - @staticmethod - def getResolution(): - return 1 - - @staticmethod - def setEmbeddedMode(_): - pass - - @staticmethod - def getEmbeddedMode(): - return 0 - - @staticmethod - def doSavedSettingsExist(): - return 0 - - @staticmethod - def setAcceptingNewFriends(_): - pass - - @staticmethod - def getAcceptingNewFriends(): - return 1 - - @staticmethod - def setAcceptingNonFriendWhispers(_): - pass - - @staticmethod - def getAcceptingNonFriendWhispers(): - return 1 diff --git a/otp/settings/Settings.py b/otp/settings/Settings.py new file mode 100644 index 0000000..2fc9b98 --- /dev/null +++ b/otp/settings/Settings.py @@ -0,0 +1,27 @@ +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 getSetting(self, setting, default=None): + result = self.__settings.get(setting, default) + return result diff --git a/libotp/settings/__init__.py b/otp/settings/__init__.py similarity index 100% rename from libotp/settings/__init__.py rename to otp/settings/__init__.py diff --git a/toontown/shtiker/OptionsPage.py b/toontown/shtiker/OptionsPage.py index a340d7f..1a56173 100644 --- a/toontown/shtiker/OptionsPage.py +++ b/toontown/shtiker/OptionsPage.py @@ -1,9 +1,7 @@ from pandac.PandaModules import * -from libotp import * from . import ShtikerPage from toontown.toontowngui import TTDialog from direct.gui.DirectGui import * -from pandac.PandaModules import * from toontown.toonbase import TTLocalizer from . import DisplaySettingsDialog from direct.task import Task @@ -12,7 +10,6 @@ from otp.speedchat import SCColorScheme from otp.speedchat import SCStaticTextTerminal from direct.showbase import PythonUtil from direct.directnotify import DirectNotifyGlobal -from toontown.toonbase import ToontownGlobals speedChatStyles = ((2000, (200 / 255.0, 60 / 255.0, 229 / 255.0), (200 / 255.0, 135 / 255.0, 255 / 255.0), @@ -123,9 +120,6 @@ class OptionsTabPage(DirectFrame): DisplaySettingsDelay = 60 ChangeDisplaySettings = base.config.GetBool('change-display-settings', 1) ChangeDisplayAPI = base.config.GetBool('change-display-api', 0) - DisplaySettingsApiMap = {'OpenGL': Settings.GL, - 'DirectX7': Settings.DX7, - 'DirectX8': Settings.DX8} def __init__(self, parent = aspect2d): self._parent = parent diff --git a/toontown/toonbase/DisplayOptions.py b/toontown/toonbase/DisplayOptions.py index 47ffe2e..d970292 100644 --- a/toontown/toonbase/DisplayOptions.py +++ b/toontown/toonbase/DisplayOptions.py @@ -4,7 +4,6 @@ import os import sys import datetime from pandac.PandaModules import loadPrcFileData, WindowProperties -from libotp import Settings from otp.otpgui import OTPDialog from otp.otpbase import OTPGlobals from otp.otpbase import OTPRender @@ -22,25 +21,20 @@ class DisplayOptions: self.loadFromSettings() def loadFromSettings(self): - Settings.readSettings() - mode = not Settings.getWindowedMode() - music = Settings.getMusic() - sfx = Settings.getSfx() - toonChatSounds = Settings.getToonChatSounds() - resList = [(640, 480), - (800, 600), - (1024, 768), - (1280, 1024), - (1600, 1200)] - res = resList[Settings.getResolution()] - embed = Settings.getEmbeddedMode() + base.settings.readSettings() + mode = not base.settings.getSetting('windowed-mode', 1) + music = base.settings.getSetting('music', 1) + sfx = base.settings.getSetting('sfx', 1) + toonChatSounds = base.settings.getSetting('toon-chat-sounds', 1) + res = base.settings.getSetting('resolution', (800, 600)) + embed = base.settings.getSetting('embedded-mode', 0) self.notify.debug('before prc settings embedded mode=%s' % str(embed)) self.notify.debug('before prc settings full screen mode=%s' % str(mode)) if mode == None: mode = 1 if res == None: res = (800, 600) - if not Settings.doSavedSettingsExist(): + if not base.settings.doSavedSettingsExist(): self.notify.info('loadFromSettings: No settings; isDefaultEmbedded=%s' % self.isDefaultEmbedded()) embed = self.isDefaultEmbedded() if embed and not self.isEmbeddedPossible(): diff --git a/toontown/toonbase/ToonBase.py b/toontown/toonbase/ToonBase.py index b76cb97..ab5cb59 100644 --- a/toontown/toonbase/ToonBase.py +++ b/toontown/toonbase/ToonBase.py @@ -1,6 +1,7 @@ from otp.otpbase import OTPBase from otp.otpbase import OTPLauncherGlobals from otp.otpbase import OTPGlobals +from otp.settings.Settings import Settings from direct.showbase.PythonUtil import * from . import ToontownGlobals from direct.directnotify import DirectNotifyGlobal @@ -21,18 +22,14 @@ class ToonBase(OTPBase.OTPBase): notify = DirectNotifyGlobal.directNotify.newCategory('ToonBase') def __init__(self): + self.settings = Settings() if not config.GetInt('ignore-user-options', 0): - Settings.readSettings() - mode = not Settings.getWindowedMode() - music = Settings.getMusic() - sfx = Settings.getSfx() - toonChatSounds = Settings.getToonChatSounds() - resList = [(640, 480), - (800, 600), - (1024, 768), - (1280, 1024), - (1600, 1200)] - res = resList[Settings.getResolution()] + self.settings.readSettings() + mode = not self.settings.getSetting('windowed-mode', 1) + music = self.settings.getSetting('music', 1) + sfx = self.settings.getSetting('sfx', 1) + toonChatSounds = self.settings.getSetting('toon-chat-sounds', 1) + res = self.settings.getSetting('resolution', (800, 600)) if mode == None: mode = 1 if res == None: