Fixed resource loader
This commit is contained in:
@ -7,6 +7,8 @@
|
||||
#include <SDL3_ttf/SDL_ttf.h>
|
||||
#include <filesystem>
|
||||
#include "../../utils/ImagePathResolver.h"
|
||||
#include "../../core/Config.h"
|
||||
#include "../../resources/AssetPaths.h"
|
||||
|
||||
AssetManager::AssetManager()
|
||||
: m_renderer(nullptr)
|
||||
@ -103,7 +105,34 @@ SDL_Texture* AssetManager::loadTexture(const std::string& id, const std::string&
|
||||
|
||||
SDL_Texture* AssetManager::getTexture(const std::string& id) const {
|
||||
auto it = m_textures.find(id);
|
||||
return (it != m_textures.end()) ? it->second : nullptr;
|
||||
if (it != m_textures.end()) return it->second;
|
||||
|
||||
// Lazy fallback: attempt to load well-known short ids from configured asset paths.
|
||||
std::vector<std::string> candidates;
|
||||
if (id == "logo") {
|
||||
candidates.push_back(std::string(Assets::LOGO));
|
||||
candidates.push_back(Config::Assets::LOGO_BMP);
|
||||
} else if (id == "logo_small") {
|
||||
candidates.push_back(Config::Assets::LOGO_SMALL_BMP);
|
||||
candidates.push_back(std::string(Assets::LOGO));
|
||||
} else if (id == "background") {
|
||||
candidates.push_back(std::string(Assets::MAIN_SCREEN));
|
||||
candidates.push_back(Config::Assets::BACKGROUND_BMP);
|
||||
} else if (id == "blocks") {
|
||||
candidates.push_back(std::string(Assets::BLOCKS_SPRITE));
|
||||
candidates.push_back(Config::Assets::BLOCKS_BMP);
|
||||
} else if (id == "asteroids") {
|
||||
candidates.push_back(std::string(Assets::ASTEROID_SPRITE));
|
||||
}
|
||||
|
||||
for (const auto &candidatePath : candidates) {
|
||||
if (candidatePath.empty()) continue;
|
||||
AssetManager* self = const_cast<AssetManager*>(this);
|
||||
SDL_Texture* tex = self->loadTexture(id, candidatePath);
|
||||
if (tex) return tex;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool AssetManager::unloadTexture(const std::string& id) {
|
||||
|
||||
Reference in New Issue
Block a user