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

+51 -1
View File
@@ -17,6 +17,17 @@ const SERVERS: Array[String] = [
const DEBUG_SERVER: String = "http://localhost:8080"
## The winning score debug builds start with, so a game is quick to win while testing.
const DEBUG_WINNING_SCORE: int = 5
## The quiz settings that are saved to [method quiz_settings_path] and loaded at start.
## Count plays in statistics and Prefer less played soundtracks are left out on purpose.
const QUIZ_SETTINGS: Array[StringName] = [
&"auto_repeat_song", &"stop_after_current", &"hide_next_track", &"hide_beginning",
&"hide_for_seconds", &"hide_length", &"hide_ticks", &"winning_score",
&"inspiration_list_speed",
]
## When this environment variable is set, the settings file is kept in that folder instead
## of the user's config folder. The tests set it so they never touch the real file.
const CONFIG_DIR_ENV: String = "MUSICPLAYER_CONFIG_DIR"
const QUIZ_SETTINGS_SECTION: String = "quiz"
var default_path: String = "https://music.sanplex.xyz"
## Password for getting an API token from the server. Any password works when the
@@ -49,13 +60,52 @@ var version: String = ProjectSettings.get_setting("application/config/version",
# Autoloads are ready before any scene, so debug builds use the local server and the
# low winning score from the very first request
# low winning score from the very first request. The saved quiz settings come after, so
# the debug winning score is only used until another one is saved.
func _ready() -> void:
if OS.has_feature("debug"):
is_debug = true
default_path = DEBUG_SERVER
selected_server = SERVERS.find(DEBUG_SERVER)
winning_score = DEBUG_WINNING_SCORE
load_quiz_settings()
## Where the quiz settings are saved: a MusicPlayer folder in the user's config folder,
## e.g. [code]~/.config[/code] on Linux and [code]%APPDATA%[/code] on Windows. Debug
## builds use a file of their own, so testing never changes the real settings.
func quiz_settings_path() -> String:
var config_dir: String = OS.get_environment(CONFIG_DIR_ENV)
if config_dir.is_empty():
config_dir = OS.get_config_dir().path_join("MusicPlayer")
var file_name: String = "quiz_settings_debug.cfg" if is_debug else "quiz_settings.cfg"
return config_dir.path_join(file_name)
## Loads the saved quiz settings. Settings missing from the file, or saved with the
## wrong type, keep their current value.
func load_quiz_settings() -> void:
var file: ConfigFile = ConfigFile.new()
if file.load(quiz_settings_path()) != OK:
return
for setting: StringName in QUIZ_SETTINGS:
var current: Variant = get(setting)
var saved: Variant = file.get_value(QUIZ_SETTINGS_SECTION, setting, current)
if typeof(saved) == typeof(current):
set(setting, saved)
## Saves the quiz settings, so they are the same the next time the game starts.
func save_quiz_settings() -> void:
var path: String = quiz_settings_path()
DirAccess.make_dir_recursive_absolute(path.get_base_dir())
var file: ConfigFile = ConfigFile.new()
for setting: StringName in QUIZ_SETTINGS:
file.set_value(QUIZ_SETTINGS_SECTION, setting, get(setting))
var error: Error = file.save(path)
if error != OK:
GameLog.warning("Could not save the quiz settings to %s: %s"
% [path, error_string(error)])
func delete_children(node: Node) -> void: