arreglos pa NO integrar jail_audio en ResourceHelper

This commit is contained in:
2025-08-19 13:36:03 +02:00
parent 83ee9c2649
commit 52d76b7338

View File

@@ -7,6 +7,7 @@
#include <cstdlib> // Para exit #include <cstdlib> // Para exit
#include <stdexcept> // Para runtime_error #include <stdexcept> // Para runtime_error
#include <utility> // Para move #include <utility> // Para move
#include <fstream> // Para ofstream
#include "asset.h" // Para Asset #include "asset.h" // Para Asset
#include "color.h" // Para Color #include "color.h" // Para Color
@@ -17,10 +18,27 @@
#include "param.h" // Para Param, param, ParamResource, ParamGame #include "param.h" // Para Param, param, ParamResource, ParamGame
#include "screen.h" // Para Screen #include "screen.h" // Para Screen
#include "text.h" // Para Text #include "text.h" // Para Text
#include "resource_helper.h" // Para ResourceHelper
struct JA_Music_t; // lines 11-11 struct JA_Music_t; // lines 11-11
struct JA_Sound_t; // lines 12-12 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<std::string>{}(file_path));
std::ofstream temp_file(temp_path, std::ios::binary);
temp_file.write(reinterpret_cast<const char*>(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 // Declaraciones de funciones que necesitas implementar en otros archivos
// Singleton // Singleton
@@ -293,7 +311,8 @@ auto Resource::loadSoundLazy(const std::string &name) -> JA_Sound_t * {
auto sound_list = Asset::get()->getListByType(Asset::Type::SOUND); auto sound_list = Asset::get()->getListByType(Asset::Type::SOUND);
for (const auto &file : sound_list) { for (const auto &file : sound_list) {
if (getFileName(file) == name) { if (getFileName(file) == name) {
return JA_LoadSound(file.c_str()); std::string audio_path = createTempAudioFile(file);
return JA_LoadSound(audio_path.c_str());
} }
} }
#endif #endif
@@ -306,7 +325,8 @@ auto Resource::loadMusicLazy(const std::string &name) -> JA_Music_t * {
auto music_list = Asset::get()->getListByType(Asset::Type::MUSIC); auto music_list = Asset::get()->getListByType(Asset::Type::MUSIC);
for (const auto &file : music_list) { for (const auto &file : music_list) {
if (getFileName(file) == name) { if (getFileName(file) == name) {
return JA_LoadMusic(file.c_str()); std::string audio_path = createTempAudioFile(file);
return JA_LoadMusic(audio_path.c_str());
} }
} }
#endif #endif
@@ -448,7 +468,8 @@ void Resource::loadSounds() {
auto name = getFileName(l); auto name = getFileName(l);
updateLoadingProgress(name); updateLoadingProgress(name);
#ifndef NO_AUDIO #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 #else
sounds_.emplace_back(name, nullptr); sounds_.emplace_back(name, nullptr);
#endif #endif
@@ -466,7 +487,8 @@ void Resource::loadMusics() {
auto name = getFileName(l); auto name = getFileName(l);
updateLoadingProgress(name); updateLoadingProgress(name);
#ifndef NO_AUDIO #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 #else
musics_.emplace_back(name, nullptr); musics_.emplace_back(name, nullptr);
#endif #endif