29 lines
802 B
GDScript3
29 lines
802 B
GDScript3
|
extends Node
|
||
|
|
||
|
var cfg_path = "user://settings.cfg"
|
||
|
@onready var configuration = get_settings()
|
||
|
|
||
|
# Called when the node enters the scene tree for the first time.
|
||
|
func _ready():
|
||
|
pass
|
||
|
|
||
|
func save():
|
||
|
var file = ConfigFile.new()
|
||
|
for section in configuration.keys():
|
||
|
for key in configuration[section].keys():
|
||
|
file.set_value(section, key, configuration[section][key])
|
||
|
file.save(cfg_path)
|
||
|
|
||
|
func get_settings():
|
||
|
var cfg = {}
|
||
|
var config = ConfigFile.new()
|
||
|
var cfg_file_content = config.load(cfg_path)
|
||
|
if cfg_file_content != OK:
|
||
|
return cfg
|
||
|
for section in config.get_sections():
|
||
|
print ("Config section : %s" % section)
|
||
|
for parameter in config.get_section_keys(section):
|
||
|
print("Config parameter : %s" % parameter)
|
||
|
cfg[section] = {parameter:config.get_value(section, parameter)}
|
||
|
return cfg
|