saumwacht-godot/scripts/autoload/preferences.gd
Martin Stickelbroeck c2b447610c Baseline: Saumwacht 0.15.0 (Phase 20A) vor dem Umbau zu Champions of Luneraria
Unveränderter Ausgangsstand inklusive Masterprompt und Konzeptbildern
unter assets/. .godot/ und docs/screenshots/ bleiben laut .gitignore
unversioniert; letztere sind unter ../backups gesichert.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-27 20:00:36 +02:00

45 lines
1.6 KiB
GDScript

extends Node
## Local preferences only. Match rules and ownership are never saved here.
signal changed
var volume: float = .65
var muted: bool = false
var follow_camera: bool = true
var fullscreen: bool = false
## Menu camera travel, idle drift, particles and fades are skipped when set.
var reduced_motion: bool = false
var storage_path: String = "user://preferences.cfg"
func _ready() -> void:
read_settings()
apply()
func read_settings() -> void:
var config := ConfigFile.new()
if config.load(storage_path) != OK:
return
volume = clampf(float(config.get_value("audio", "volume", .65)), 0.0, 1.0)
muted = bool(config.get_value("audio", "muted", false))
follow_camera = bool(config.get_value("camera", "follow", true))
fullscreen = bool(config.get_value("display", "fullscreen", false))
reduced_motion = bool(config.get_value("display", "reduced_motion", false))
func apply() -> void:
AudioServer.set_bus_volume_db(0, linear_to_db(maxf(.001, volume)))
AudioServer.set_bus_mute(0, muted or volume <= 0.0)
if DisplayServer.get_name() != "headless":
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN if fullscreen else DisplayServer.WINDOW_MODE_WINDOWED)
changed.emit()
func save_settings() -> Error:
var config := ConfigFile.new()
config.set_value("audio", "volume", volume)
config.set_value("audio", "muted", muted)
config.set_value("camera", "follow", follow_camera)
config.set_value("display", "fullscreen", fullscreen)
config.set_value("display", "reduced_motion", reduced_motion)
return config.save(storage_path)
func commit() -> void:
apply()
save_settings()