Save the quiz settings to the config folder
Build / test (push) Successful in 45s
Build / build (push) Successful in 1m20s

The quiz card's settings are saved to quiz_settings.cfg in OS.get_config_dir()
on every change and loaded at start. Debug builds use their own file, and
MUSICPLAYER_CONFIG_DIR moves the file elsewhere so tests never touch it.

Count plays in statistics and Prefer less played soundtracks are not saved and
move from the quiz card to the Settings popup.
This commit is contained in:
Sansan committed 2026-10-07 18:13:00 +02:00
1 parent b510aa47f2
commit 92e3a66075
15 files changed
+835 -591

No files matched your search

File diff suppressed because it is too large. Load diff
+23 -4
View File
@@ -69,8 +69,6 @@ func test_each_toggle_changes_its_setting() -> void:
"hide_beginning_button": "hide_beginning",
"hide_length_button": "hide_length",
"hide_ticks_button": "hide_ticks",
"low_played_button": "use_low_played_mode",
"add_to_database_button": "add_to_stats",
}
await _open()
for button_name: String in toggles:
@@ -89,12 +87,12 @@ func test_each_toggle_changes_its_setting() -> void:
func test_card_shows_settings_changed_elsewhere() -> void:
await _open()
_card.close()
Settings.add_to_stats = false
Settings.hide_next_track = false
Settings.auto_repeat_song = false
await _open()
assert_bool(_card.add_to_database_button.button_pressed).is_false()
assert_bool(_card.hide_next_track_button.button_pressed).is_false()
assert_bool(_card.auto_repeat_button.button_pressed).is_false()
@@ -158,3 +156,24 @@ func test_card_grows_upward_for_the_seconds_row() -> void:
assert_float(open_row.size.y).is_greater(closed_row.size.y)
# Every row stays inside the card
assert_bool(open_row.encloses(_card.rows.get_global_rect())).is_true()
func test_statistics_settings_are_in_the_settings_popup_instead() -> void:
await _open()
assert_object(_card.find_child("LowPlayedCheckButton")).is_null()
assert_object(_card.find_child("AddToDatabaseCheckButton")).is_null()
func test_changes_are_saved_at_once() -> void:
Settings.hide_next_track = true
Settings.winning_score = 20
await _open()
await _click_at(_card.hide_next_track_button.get_global_rect().get_center())
_card.lower_winning_score_button.pressed.emit()
var saved: ConfigFile = ConfigFile.new()
assert_int(saved.load(Settings.quiz_settings_path())).is_equal(OK)
assert_bool(saved.get_value("quiz", "hide_next_track")).is_false()
assert_int(saved.get_value("quiz", "winning_score")).is_equal(19)
+55
View File
@@ -0,0 +1,55 @@
extends MainWindowTestSuite
## The statistics settings in the application Settings popup.
var _popup: SettingsPopup
func before_test() -> void:
super()
_popup = _window.get_node("SettingsPopup")
func test_less_played_toggle_changes_the_setting() -> void:
Settings.use_low_played_mode = false
_popup.open()
await _runner.simulate_frames(1)
assert_bool(_popup.low_played_button.button_pressed).is_false()
await _click_at(_popup.low_played_button.get_global_rect().get_center())
assert_bool(Settings.use_low_played_mode).is_true()
func test_statistics_toggle_changes_the_setting() -> void:
Settings.add_to_stats = true
_popup.open()
await _runner.simulate_frames(1)
assert_bool(_popup.add_to_database_button.button_pressed).is_true()
await _click_at(_popup.add_to_database_button.get_global_rect().get_center())
assert_bool(Settings.add_to_stats).is_false()
func test_statistics_settings_are_not_saved_with_the_quiz_settings() -> void:
Settings.add_to_stats = false
Settings.use_low_played_mode = true
Settings.save_quiz_settings()
var saved: ConfigFile = ConfigFile.new()
assert_int(saved.load(Settings.quiz_settings_path())).is_equal(OK)
assert_bool(saved.has_section_key("quiz", "add_to_stats")).is_false()
assert_bool(saved.has_section_key("quiz", "use_low_played_mode")).is_false()
func test_popup_fits_its_rows_and_is_centred() -> void:
_popup.open()
await _runner.simulate_frames(1)
var panel: Rect2 = _popup.settings_panel.get_global_rect()
var rows: Control = _popup.settings_panel.get_node("VBoxContainer")
assert_bool(panel.encloses(rows.get_global_rect())).is_true()
# The rows' own height fits, so the last toggle is not squeezed or cut off
assert_float(rows.get_combined_minimum_size().y).is_less_equal(rows.size.y)
assert_vector(panel.get_center()).is_equal(Vector2(960, 540))
@@ -0,0 +1 @@
uid://cp3f85h44jh3x
+2 -2
View File
@@ -12,7 +12,7 @@ func before_test() -> void:
func _stats_checkbox() -> CheckButton:
return _quiz.get_node("QuizSettingsCard").get_node("%AddToDatabaseCheckButton")
return _window.get_node("SettingsPopup").get_node("%AddToDatabaseCheckButton")
func test_winning_turns_statistics_off() -> void:
@@ -41,7 +41,7 @@ func test_statistics_turned_off_by_hand_stay_off_after_reset() -> void:
func test_settings_checkbox_shows_statistics_off_after_win() -> void:
await _give_point_with_keybind(1)
_press("QuizSettingsButton")
(_window.get_node("SettingsPopup") as SettingsPopup).open()
assert_bool(_stats_checkbox().button_pressed).is_false()
+97
View File
@@ -0,0 +1,97 @@
extends GdUnitTestSuite
## Saving the quiz settings to a file in the config folder and loading them back.
const SAVED_VALUES: Dictionary = {
&"auto_repeat_song": false, &"stop_after_current": false, &"hide_next_track": false,
&"hide_beginning": true, &"hide_for_seconds": 7.0, &"hide_length": true,
&"hide_ticks": true, &"winning_score": 13, &"inspiration_list_speed": 4,
}
var _snapshot: AutoloadSnapshot
var _config_dir_before: String
var _config_dir: String
func before_test() -> void:
_snapshot = AutoloadSnapshot.take([Settings])
_config_dir_before = OS.get_environment(Settings.CONFIG_DIR_ENV)
_config_dir = create_temp_dir("quiz_settings_file")
OS.set_environment(Settings.CONFIG_DIR_ENV, _config_dir)
DirAccess.remove_absolute(Settings.quiz_settings_path())
func after_test() -> void:
OS.set_environment(Settings.CONFIG_DIR_ENV, _config_dir_before)
_snapshot.restore()
func _set_settings(values: Dictionary) -> void:
for setting: StringName in values:
Settings.set(setting, values[setting])
func test_saved_settings_load_back() -> void:
_set_settings(SAVED_VALUES)
Settings.save_quiz_settings()
_snapshot.restore()
Settings.load_quiz_settings()
for setting: StringName in SAVED_VALUES:
assert_that(Settings.get(setting)).override_failure_message(setting) \
.is_equal(SAVED_VALUES[setting])
func test_every_quiz_setting_is_saved() -> void:
assert_array(Settings.QUIZ_SETTINGS).contains_exactly_in_any_order(SAVED_VALUES.keys())
func test_missing_file_keeps_the_current_settings() -> void:
Settings.winning_score = 9
Settings.load_quiz_settings()
assert_int(Settings.winning_score).is_equal(9)
func test_value_of_the_wrong_type_is_ignored() -> void:
var file: ConfigFile = ConfigFile.new()
file.set_value("quiz", "winning_score", "lots")
file.set_value("quiz", "hide_ticks", true)
DirAccess.make_dir_recursive_absolute(Settings.quiz_settings_path().get_base_dir())
file.save(Settings.quiz_settings_path())
Settings.winning_score = 9
Settings.hide_ticks = false
Settings.load_quiz_settings()
assert_int(Settings.winning_score).is_equal(9)
assert_bool(Settings.hide_ticks).is_true()
func test_statistics_settings_are_not_saved() -> void:
Settings.save_quiz_settings()
var file: ConfigFile = ConfigFile.new()
file.load(Settings.quiz_settings_path())
assert_bool(file.has_section_key("quiz", "add_to_stats")).is_false()
assert_bool(file.has_section_key("quiz", "use_low_played_mode")).is_false()
func test_file_is_in_the_folder_from_the_environment() -> void:
assert_str(Settings.quiz_settings_path().get_base_dir()).is_equal(_config_dir)
func test_file_is_in_the_config_folder_without_the_environment() -> void:
OS.unset_environment(Settings.CONFIG_DIR_ENV)
assert_str(Settings.quiz_settings_path().get_base_dir()) \
.is_equal(OS.get_config_dir().path_join("MusicPlayer"))
func test_debug_builds_use_a_file_of_their_own() -> void:
Settings.is_debug = true
var debug_path: String = Settings.quiz_settings_path()
Settings.is_debug = false
assert_str(debug_path).is_not_equal(Settings.quiz_settings_path())
@@ -0,0 +1 @@
uid://5qjw3px3wve6