Defaults Support

This adds support for loading settings from the defaults folder, settings are loaded in the following order and overwritten if needed by the higher number.

1. The model config file.
2. The defaults folder.
3. The users defined settings file.

With this support we can begin to ship better defaults for models we do not manage. Our community tuners have been most helpful at adding good defaults to their configuration files, but for other models such as the base models this gives us the flexibility to define better settings for each model without messing with a users desired settings if they already exist.
This commit is contained in:
Henk 2022-06-01 10:34:16 +02:00
parent 714fc1729b
commit e5dcf91a08
2 changed files with 88 additions and 75 deletions

3
.gitignore vendored
View File

@ -31,3 +31,6 @@ Uninstall
# Ignore compiled Python files. # Ignore compiled Python files.
*.pyc *.pyc
# Don't ignore defaults
!defaults/*

View File

@ -660,12 +660,24 @@ def settingschanged():
#==================================================================# #==================================================================#
# Read settings from client file JSON and send to vars # Read settings from client file JSON and send to vars
#==================================================================# #==================================================================#
def loadsettings(): def loadsettings():
if(path.exists("defaults/" + getmodelname().replace('/', '_') + ".settings")):
# Read file contents into JSON object
file = open("defaults/" + getmodelname().replace('/', '_') + ".settings", "r")
js = json.load(file)
processsettings(js)
file.close()
if(path.exists("settings/" + getmodelname().replace('/', '_') + ".settings")): if(path.exists("settings/" + getmodelname().replace('/', '_') + ".settings")):
# Read file contents into JSON object # Read file contents into JSON object
file = open("settings/" + getmodelname().replace('/', '_') + ".settings", "r") file = open("settings/" + getmodelname().replace('/', '_') + ".settings", "r")
js = json.load(file) js = json.load(file)
processsettings(js)
file.close()
def processsettings(js):
# Copy file contents to vars # Copy file contents to vars
if("apikey" in js): if("apikey" in js):
vars.apikey = js["apikey"] vars.apikey = js["apikey"]
@ -741,8 +753,6 @@ def loadsettings():
else: else:
vars.corescript = "default.lua" vars.corescript = "default.lua"
file.close()
#==================================================================# #==================================================================#
# Load a soft prompt from a file # Load a soft prompt from a file
#==================================================================# #==================================================================#