afegit resources.pack y prefixe a les rutes de recursos

This commit is contained in:
2025-12-08 21:48:52 +01:00
parent 4b7cbd88bb
commit a41e696b69
21 changed files with 1066 additions and 36 deletions

View File

@@ -3,6 +3,8 @@
#include "core/audio/audio_cache.hpp"
#include "core/resources/resource_helper.hpp"
#include <iostream>
// Inicialització de variables estàtiques
@@ -19,17 +21,28 @@ JA_Sound_t* AudioCache::getSound(const std::string& name) {
return it->second;
}
// Cache miss - cargar archivo
std::string fullpath = resolveSoundPath(name);
JA_Sound_t* sound = JA_LoadSound(fullpath.c_str());
// Normalize path: "laser_shoot.wav" → "sounds/laser_shoot.wav"
std::string normalized = name;
if (normalized.find("sounds/") != 0 && normalized.find('/') == std::string::npos) {
normalized = "sounds/" + normalized;
}
// Load from resource system
std::vector<uint8_t> data = Resource::Helper::loadFile(normalized);
if (data.empty()) {
std::cerr << "[AudioCache] Error: no s'ha pogut carregar " << normalized << std::endl;
return nullptr;
}
// Load sound from memory
JA_Sound_t* sound = JA_LoadSound(data.data(), static_cast<uint32_t>(data.size()));
if (sound == nullptr) {
std::cerr << "[AudioCache] Error: no s'ha pogut carregar " << fullpath
std::cerr << "[AudioCache] Error: no s'ha pogut decodificar " << normalized
<< std::endl;
return nullptr;
}
std::cout << "[AudioCache] Sound loaded: " << name << std::endl;
std::cout << "[AudioCache] Sound loaded: " << normalized << std::endl;
sounds_[name] = sound;
return sound;
}
@@ -42,17 +55,28 @@ JA_Music_t* AudioCache::getMusic(const std::string& name) {
return it->second;
}
// Cache miss - cargar archivo
std::string fullpath = resolveMusicPath(name);
JA_Music_t* music = JA_LoadMusic(fullpath.c_str());
// Normalize path: "title.ogg" → "music/title.ogg"
std::string normalized = name;
if (normalized.find("music/") != 0 && normalized.find('/') == std::string::npos) {
normalized = "music/" + normalized;
}
// Load from resource system
std::vector<uint8_t> data = Resource::Helper::loadFile(normalized);
if (data.empty()) {
std::cerr << "[AudioCache] Error: no s'ha pogut carregar " << normalized << std::endl;
return nullptr;
}
// Load music from memory
JA_Music_t* music = JA_LoadMusic(data.data(), static_cast<uint32_t>(data.size()));
if (music == nullptr) {
std::cerr << "[AudioCache] Error: no s'ha pogut carregar " << fullpath
std::cerr << "[AudioCache] Error: no s'ha pogut decodificar " << normalized
<< std::endl;
return nullptr;
}
std::cout << "[AudioCache] Music loaded: " << name << std::endl;
std::cout << "[AudioCache] Music loaded: " << normalized << std::endl;
musics_[name] = music;
return music;
}