feat(config): persistència de les opcions d'àudio al config.yaml

This commit is contained in:
2026-05-24 18:40:33 +02:00
parent bacfbe6eac
commit 8c48a9a772
4 changed files with 68 additions and 7 deletions
+10
View File
@@ -56,9 +56,19 @@ namespace Config {
std::string gamepad_name; // Empty = auto-assign by index
};
struct AudioConfig {
bool enabled{true};
float volume{1.0F}; // Master 0..1
bool music_enabled{true};
float music_volume{1.0F};
bool sound_enabled{true};
float sound_volume{0.25F};
};
struct EngineConfig {
WindowConfig window{};
RenderingConfig rendering{};
AudioConfig audio{};
PlayerBindings player1{};
PlayerBindings player2{};
KeyboardBindings keyboard_controls{}; // Defaults globals per Input
+6 -7
View File
@@ -11,7 +11,6 @@
#include "core/audio/audio.hpp"
#include "core/audio/audio_adapter.hpp"
#include "core/defaults/audio.hpp"
#include "core/defaults/window.hpp"
#include "core/input/input.hpp"
#include "core/input/mouse.hpp"
@@ -138,12 +137,12 @@ Director::Director(int argc, char* argv[])
}
const Audio::Config AUDIO_CONFIG{
.enabled = Defaults::Audio::ENABLED,
.volume = Defaults::Audio::VOLUME,
.music_enabled = Defaults::Audio::MUSIC_ENABLED,
.music_volume = Defaults::Audio::MUSIC_VOLUME,
.sound_enabled = Defaults::Audio::SOUND_ENABLED,
.sound_volume = Defaults::Audio::SOUND_VOLUME,
.enabled = cfg_->audio.enabled,
.volume = cfg_->audio.volume,
.music_enabled = cfg_->audio.music_enabled,
.music_volume = cfg_->audio.music_volume,
.sound_enabled = cfg_->audio.sound_enabled,
.sound_volume = cfg_->audio.sound_volume,
};
Audio::init(AUDIO_CONFIG);
Audio::get()->applySettings(AUDIO_CONFIG);
+12
View File
@@ -299,6 +299,8 @@ namespace System {
.on_change = [](int) {
if (auto* a = Audio::get(); a != nullptr) {
a->toggleEnabled();
ConfigYaml::engine_config.audio.enabled = a->isEnabled();
ConfigYaml::saveToFile();
} },
},
// VOLUM GENERAL (master)
@@ -315,6 +317,8 @@ namespace System {
.on_change = [step_volume](int dir) {
if (auto* a = Audio::get(); a != nullptr) {
a->setMasterVolume(step_volume(a->getMasterVolume(), dir));
ConfigYaml::engine_config.audio.volume = a->getMasterVolume();
ConfigYaml::saveToFile();
} },
},
// MUSICA ON/OFF
@@ -330,6 +334,8 @@ namespace System {
.on_change = [](int) {
if (auto* a = Audio::get(); a != nullptr) {
a->toggleMusic();
ConfigYaml::engine_config.audio.music_enabled = a->isMusicEnabled();
ConfigYaml::saveToFile();
} },
},
// VOLUM MUSICA
@@ -346,6 +352,8 @@ namespace System {
.on_change = [step_volume](int dir) {
if (auto* a = Audio::get(); a != nullptr) {
a->setMusicVolume(step_volume(a->getMusicVolume(), dir));
ConfigYaml::engine_config.audio.music_volume = a->getMusicVolume();
ConfigYaml::saveToFile();
} },
},
// SONS ON/OFF
@@ -361,6 +369,8 @@ namespace System {
.on_change = [](int) {
if (auto* a = Audio::get(); a != nullptr) {
a->toggleSound();
ConfigYaml::engine_config.audio.sound_enabled = a->isSoundEnabled();
ConfigYaml::saveToFile();
} },
},
// VOLUM SONS
@@ -377,6 +387,8 @@ namespace System {
.on_change = [step_volume](int dir) {
if (auto* a = Audio::get(); a != nullptr) {
a->setSoundVolume(step_volume(a->getSoundVolume(), dir));
ConfigYaml::engine_config.audio.sound_volume = a->getSoundVolume();
ConfigYaml::saveToFile();
} },
},
};