Update only the queue ID in settings.cfg
Build / test (push) Successful in 44s
Build / build (push) Successful in 1m12s

Saving a new queue ID wrote every setting from memory, which could also save
a setting that is in use but not saved yet, like the debug winning score.
Now it loads the file, changes only the queue ID and saves it again.
This commit is contained in:
Sansan committed 2026-10-07 21:28:02 +02:00
1 parent 4a45e8516d
commit 62fa63fd8b
2 files changed
+41 -2

No files matched your search

+11 -2
View File
@@ -181,10 +181,19 @@ func save_settings() -> void:
GameLog.warning("Could not save the settings to %s: %s" % [path, error_string(error)])
## Sets the play queue ID for [param server] and saves it.
## Sets the play queue ID for [param server] and saves it. Only the ID is changed in
## the file; the other settings in it stay as they were saved.
func set_queue_id(server: String, id: String) -> void:
queue_ids[server] = id
save_settings()
var path: String = saved_settings_path()
var file: ConfigFile = ConfigFile.new()
# A missing file is fine: it is written with only the queue ID
file.load(path)
file.set_value("queues", server, id)
DirAccess.make_dir_recursive_absolute(path.get_base_dir())
var error: Error = file.save(path)
if error != OK:
GameLog.warning("Could not save the queue ID to %s: %s" % [path, error_string(error)])
## Turns fullscreen on or off and saves it.
+30
View File
@@ -107,6 +107,36 @@ func test_queue_ids_are_saved_and_load_back() -> void:
assert_dict(Settings.queue_ids).is_equal({"https://music.example.com": "queue-1"})
func test_saving_a_queue_id_leaves_the_other_settings_as_saved() -> void:
Settings.winning_score = 10
Settings.save_settings()
Settings.winning_score = 12
Settings.set_queue_id("https://music.example.com", "queue-1")
var file: ConfigFile = _saved_file()
assert_int(file.get_value("quiz", "winning_score")).is_equal(10)
assert_str(file.get_value("queues", "https://music.example.com")).is_equal("queue-1")
func test_saving_a_queue_id_without_a_file_saves_only_the_queue_id() -> void:
Settings.set_queue_id("https://music.example.com", "queue-1")
var file: ConfigFile = _saved_file()
assert_array(file.get_sections()).contains_exactly(["queues"])
assert_str(file.get_value("queues", "https://music.example.com")).is_equal("queue-1")
func test_new_queue_id_replaces_only_its_server() -> void:
Settings.set_queue_id("https://music.example.com", "queue-1")
Settings.set_queue_id("http://localhost:8080", "local-1")
Settings.set_queue_id("https://music.example.com", "queue-2")
var file: ConfigFile = _saved_file()
assert_str(file.get_value("queues", "https://music.example.com")).is_equal("queue-2")
assert_str(file.get_value("queues", "http://localhost:8080")).is_equal("local-1")
func test_file_without_queues_keeps_the_current_queue_ids() -> void:
Settings.save_settings()
Settings.queue_ids["https://music.example.com"] = "queue-1"