afegit soport per a configurar el audio (en config i en console)

This commit is contained in:
2026-03-28 11:08:01 +01:00
parent 21c8d1e8ca
commit f15658a767
3 changed files with 168 additions and 0 deletions

View File

@@ -7,6 +7,7 @@
#include <string> // Para string
#include <vector> // Para vector
#include "core/audio/audio.hpp" // Para Audio
#include "core/rendering/screen.hpp" // Para Screen
#include "core/rendering/sprite/sprite.hpp" // Para Sprite
#include "core/rendering/surface.hpp" // Para Surface
@@ -77,6 +78,9 @@ static void printHelp() {
#ifdef _DEBUG
SDL_Log(" DEBUG Toggle debug overlay (F12)");
#endif
SDL_Log(" AUDIO [ON|OFF|VOL <0-100>] Audio master");
SDL_Log(" MUSIC [ON|OFF|VOL <0-100>] Music volume");
SDL_Log(" SOUND [ON|OFF|VOL <0-100>] Sound volume");
SDL_Log(" SCENE [LOGO|LOADING|TITLE|CREDITS|GAME|ENDING|ENDING2|RESTART]");
SDL_Log(" KIOSK [ON] Enable kiosk mode");
SDL_Log(" EXIT / QUIT Quit application");
@@ -364,6 +368,107 @@ static const std::vector<ConsoleCommand> COMMANDS = {
return "Usage: KIOSK [ON]";
}},
// AUDIO [ON|OFF|VOL <0-100>] — Audio maestro (estado + volumen)
{.keyword = "AUDIO", .execute = [](const std::vector<std::string>& args) -> std::string {
if (args.empty()) {
const int VOL = static_cast<int>(Options::audio.volume * 100.0F);
return std::string("Audio ") + (Options::audio.enabled ? "ON" : "OFF") +
" vol:" + std::to_string(VOL);
}
if (args[0] == "ON") {
if (Options::audio.enabled) { return "Audio already ON"; }
Options::audio.enabled = true;
Audio::get()->enable(true);
return "Audio ON";
}
if (args[0] == "OFF") {
if (!Options::audio.enabled) { return "Audio already OFF"; }
Options::audio.enabled = false;
Audio::get()->enable(false);
return "Audio OFF";
}
if (args[0] == "VOL" && args.size() >= 2) {
try {
const int VAL = std::stoi(args[1]);
if (VAL < 0 || VAL > 100) { return "Vol must be 0-100"; }
Options::audio.volume = static_cast<float>(VAL) / 100.0F;
Audio::get()->enable(Options::audio.enabled);
return "Audio vol:" + std::to_string(VAL);
} catch (...) { return "Usage: AUDIO VOL <0-100>"; }
}
return "Usage: AUDIO [ON|OFF|VOL N]";
}},
// MUSIC [ON|OFF|VOL <0-100>] — Volumen e interruptor de música
{.keyword = "MUSIC", .execute = [](const std::vector<std::string>& args) -> std::string {
if (args.empty()) {
const int VOL = static_cast<int>(Options::audio.music.volume * 100.0F);
return std::string("Music ") + (Options::audio.music.enabled ? "ON" : "OFF") +
" vol:" + std::to_string(VOL);
}
if (args[0] == "ON") {
if (Options::audio.music.enabled) { return "Music already ON"; }
Options::audio.music.enabled = true;
Audio::get()->enableMusic(true);
Audio::get()->setMusicVolume(Options::audio.music.volume);
return "Music ON";
}
if (args[0] == "OFF") {
if (!Options::audio.music.enabled) { return "Music already OFF"; }
Audio::get()->setMusicVolume(0.0F);
Audio::get()->enableMusic(false);
Options::audio.music.enabled = false;
return "Music OFF";
}
if (args[0] == "VOL" && args.size() >= 2) {
try {
const int VAL = std::stoi(args[1]);
if (VAL < 0 || VAL > 100) { return "Vol must be 0-100"; }
Options::audio.music.volume = static_cast<float>(VAL) / 100.0F;
if (Options::audio.music.enabled) {
Audio::get()->setMusicVolume(Options::audio.music.volume);
}
return "Music vol:" + std::to_string(VAL);
} catch (...) { return "Usage: MUSIC VOL <0-100>"; }
}
return "Usage: MUSIC [ON|OFF|VOL N]";
}},
// SOUND [ON|OFF|VOL <0-100>] — Volumen e interruptor de efectos de sonido
{.keyword = "SOUND", .execute = [](const std::vector<std::string>& args) -> std::string {
if (args.empty()) {
const int VOL = static_cast<int>(Options::audio.sound.volume * 100.0F);
return std::string("Sound ") + (Options::audio.sound.enabled ? "ON" : "OFF") +
" vol:" + std::to_string(VOL);
}
if (args[0] == "ON") {
if (Options::audio.sound.enabled) { return "Sound already ON"; }
Options::audio.sound.enabled = true;
Audio::get()->enableSound(true);
Audio::get()->setSoundVolume(Options::audio.sound.volume);
return "Sound ON";
}
if (args[0] == "OFF") {
if (!Options::audio.sound.enabled) { return "Sound already OFF"; }
Audio::get()->setSoundVolume(0.0F);
Audio::get()->enableSound(false);
Options::audio.sound.enabled = false;
return "Sound OFF";
}
if (args[0] == "VOL" && args.size() >= 2) {
try {
const int VAL = std::stoi(args[1]);
if (VAL < 0 || VAL > 100) { return "Vol must be 0-100"; }
Options::audio.sound.volume = static_cast<float>(VAL) / 100.0F;
if (Options::audio.sound.enabled) {
Audio::get()->setSoundVolume(Options::audio.sound.volume);
}
return "Sound vol:" + std::to_string(VAL);
} catch (...) { return "Usage: SOUND VOL <0-100>"; }
}
return "Usage: SOUND [ON|OFF|VOL N]";
}},
// EXIT / QUIT — Cerrar la aplicacion (bloqueado en kiosk)
{.keyword = "EXIT", .execute = [](const std::vector<std::string>& args) -> std::string {
if (Options::kiosk.enabled && (args.empty() || args[0] != "PLEASE")) {