From 52d76b733880f2ea1478cb17d8ba0b66b2fc9127 Mon Sep 17 00:00:00 2001 From: Sergio Date: Tue, 19 Aug 2025 13:36:03 +0200 Subject: [PATCH] arreglos pa NO integrar jail_audio en ResourceHelper --- source/resource.cpp | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/source/resource.cpp b/source/resource.cpp index 0365f53..a7f3dbd 100644 --- a/source/resource.cpp +++ b/source/resource.cpp @@ -7,6 +7,7 @@ #include // Para exit #include // Para runtime_error #include // Para move +#include // Para ofstream #include "asset.h" // Para Asset #include "color.h" // Para Color @@ -17,10 +18,27 @@ #include "param.h" // Para Param, param, ParamResource, ParamGame #include "screen.h" // Para Screen #include "text.h" // Para Text +#include "resource_helper.h" // Para ResourceHelper struct JA_Music_t; // lines 11-11 struct JA_Sound_t; // lines 12-12 +// Helper para cargar archivos de audio desde pack o filesystem +namespace { + std::string createTempAudioFile(const std::string& file_path) { + auto resource_data = ResourceHelper::loadFile(file_path); + if (!resource_data.empty()) { + // Crear archivo temporal + std::string temp_path = "/tmp/ccae_audio_" + std::to_string(std::hash{}(file_path)); + std::ofstream temp_file(temp_path, std::ios::binary); + temp_file.write(reinterpret_cast(resource_data.data()), resource_data.size()); + temp_file.close(); + return temp_path; + } + return file_path; // Usar ruta original si no está en pack + } +} + // Declaraciones de funciones que necesitas implementar en otros archivos // Singleton @@ -293,7 +311,8 @@ auto Resource::loadSoundLazy(const std::string &name) -> JA_Sound_t * { auto sound_list = Asset::get()->getListByType(Asset::Type::SOUND); for (const auto &file : sound_list) { if (getFileName(file) == name) { - return JA_LoadSound(file.c_str()); + std::string audio_path = createTempAudioFile(file); + return JA_LoadSound(audio_path.c_str()); } } #endif @@ -306,7 +325,8 @@ auto Resource::loadMusicLazy(const std::string &name) -> JA_Music_t * { auto music_list = Asset::get()->getListByType(Asset::Type::MUSIC); for (const auto &file : music_list) { if (getFileName(file) == name) { - return JA_LoadMusic(file.c_str()); + std::string audio_path = createTempAudioFile(file); + return JA_LoadMusic(audio_path.c_str()); } } #endif @@ -448,7 +468,8 @@ void Resource::loadSounds() { auto name = getFileName(l); updateLoadingProgress(name); #ifndef NO_AUDIO - sounds_.emplace_back(name, JA_LoadSound(l.c_str())); + std::string audio_path = createTempAudioFile(l); + sounds_.emplace_back(name, JA_LoadSound(audio_path.c_str())); #else sounds_.emplace_back(name, nullptr); #endif @@ -466,7 +487,8 @@ void Resource::loadMusics() { auto name = getFileName(l); updateLoadingProgress(name); #ifndef NO_AUDIO - musics_.emplace_back(name, JA_LoadMusic(l.c_str())); + std::string audio_path = createTempAudioFile(l); + musics_.emplace_back(name, JA_LoadMusic(audio_path.c_str())); #else musics_.emplace_back(name, nullptr); #endif