75 lines
2.1 KiB
Plaintext
75 lines
2.1 KiB
Plaintext
extends Node
|
|
|
|
@onready var syncedFeatures: ConfigFile = ConfigFile.new()
|
|
@onready var settingsmenu = $/root/Main/Settingsmenu/VBoxContainer/MarginContainer2/HBoxContainer/VBoxContainer
|
|
@onready var config : ConfigFile = ConfigFile.new()
|
|
@export var debug : bool = false
|
|
|
|
func _ready() -> void:
|
|
var ms = MultiplayerSynchronizer.new()
|
|
var spg = SceneReplicationConfig.new()
|
|
var ppath = name + ":syncedFeatures"
|
|
spg.add_property(ppath)
|
|
ms.name = "ConfigSynchronizer"
|
|
ms.replication_config = spg
|
|
$/root.add_child.call_deferred(ms)
|
|
loadConfig()
|
|
update_menu()
|
|
|
|
func update_menu():
|
|
for feature in config.get_sections():
|
|
var container = HBoxContainer.new()
|
|
container.size_flags_vertical = Control.SIZE_EXPAND_FILL
|
|
container.name = feature
|
|
var label = Label.new()
|
|
label.text = feature
|
|
container.add_child(label)
|
|
var control : Control
|
|
match config.get_value(feature,"mode","_"):
|
|
"check":
|
|
control = CheckButton.new()
|
|
"color:":
|
|
control = ColorPickerButton.new()
|
|
"text":
|
|
control = LineEdit.new()
|
|
"menu":
|
|
control = OptionButton.new()
|
|
"button":
|
|
control = Button.new()
|
|
_:
|
|
control = Button.new()
|
|
container.add_child(control)
|
|
settingsmenu.add_child(container)
|
|
func loadConfig():
|
|
var err : Error = config.load("user://config.cfg") if not debug else config.load("res://defaultconfig.cfg")
|
|
match err:
|
|
OK:
|
|
return
|
|
ERR_FILE_NOT_FOUND:
|
|
push_error("Config not found. Loading default config.")
|
|
_:
|
|
push_error("Failed to load config: error " + str(err))
|
|
var err2 : Error = config.load("res://defaultconfig.cfg")
|
|
match err2:
|
|
OK:
|
|
push_warning("Default config loaded successfully.")
|
|
ERR_PARSE_ERROR:
|
|
push_error("Invalid default config")
|
|
get_tree().quit(1)
|
|
return
|
|
_:
|
|
push_error("Yay a bug " + str(err2))
|
|
get_tree().quit(1)
|
|
return
|
|
if ResourceLoader.exists("user://config.cfg"):
|
|
return
|
|
var err3 : Error = config.save("user://config.cfg")
|
|
match err3:
|
|
OK:
|
|
print("Saved new config file")
|
|
ERR_FILE_NO_PERMISSION:
|
|
push_error("No permission to save new config file.")
|
|
_:
|
|
push_error("Could not save new config file: " + str(err3))
|
|
return
|