teststrecke-game/scripts/configFileHandler.gd

44 lines
1.3 KiB
GDScript

extends Node
var config = ConfigFile.new()
const SETTINGS_FILE_PATH = "config.ini"
func _ready() -> void:
if !FileAccess.file_exists(SETTINGS_FILE_PATH):
config.set_value("keywhitelist", "enabled", false)
config.set_value("video", "fullscreen", false)
config.save(SETTINGS_FILE_PATH)
else:
config.load(SETTINGS_FILE_PATH)
func save_video_setting(key: String, value):
config.set_value("video", key,value)
config.save(SETTINGS_FILE_PATH)
func get_video_setting(key: String):
return config.get_value("video", key)
func get_keywhitelist_setting():
var keywhitelist=[]
if config.get_value("keywhitelist", "enabled"):
for key in config.get_section_keys("keywhitelist"):
if key.is_valid_int(): #is a playernumber
print("added "+str(key)+" to whitelist of keys")
keywhitelist.append(int(config.get_value("keywhitelist",key)))
return keywhitelist #returns empty list if enabled is false
func save_keywhitelist_setting(whitelist):
for key in config.get_section_keys("keywhitelist"):
if key.is_valid_int(): #is a playernumber
config.set_value("keywhitelist",key,"none") #set all existing keys to -1 = none
var i=0
for k in whitelist:
print("saving keywhitelist "+str(i)+" = "+str(k))
config.set_value("keywhitelist",str(i),str(k))
i+=1
config.save(SETTINGS_FILE_PATH)