mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-07 20:11:50 +00:00
refactor textures access
This commit is contained in:
parent
673f235ff9
commit
4f377b2056
13 changed files with 74 additions and 49 deletions
24
src/assets/assets_util.cpp
Normal file
24
src/assets/assets_util.cpp
Normal 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()};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue