refactor textures access

This commit is contained in:
MihailRis
2024-11-01 02:13:21 +03:00
parent 673f235ff9
commit 4f377b2056
13 changed files with 74 additions and 49 deletions
+24
View File
@@ -0,0 +1,24 @@
#include "assets_util.hpp"
#include "assets/Assets.hpp"
#include "graphics/core/Atlas.hpp"
#include "graphics/core/Texture.hpp"
util::TextureRegion util::getTextureRegion(
const Assets& assets, const std::string& name, const std::string& fallback
) {
size_t sep = name.find(':');
if (sep == std::string::npos) {
return {assets.get<Texture>(name), UVRegion(0,0,1,1)};
} else {
auto atlas = assets.get<Atlas>(name.substr(0, sep));
if (atlas) {
if (auto reg = atlas->getIf(name.substr(sep+1))) {
return {atlas->getTexture(), *reg};
} else if (!fallback.empty()){
return util::getTextureRegion(assets, fallback, "");
}
}
}
return {nullptr, UVRegion()};
}