fix Image for non-existing textures in atlas
This commit is contained in:
parent
2dffdf757c
commit
71c754b039
@ -34,6 +34,14 @@ const UVRegion& Atlas::get(const std::string& name) const {
|
|||||||
return regions.at(name);
|
return regions.at(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::optional<UVRegion> Atlas::getIf(const std::string& name) const {
|
||||||
|
const auto& found = regions.find(name);
|
||||||
|
if (found == regions.end()) {
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
return found->second;
|
||||||
|
}
|
||||||
|
|
||||||
Texture* Atlas::getTexture() const {
|
Texture* Atlas::getTexture() const {
|
||||||
return texture.get();
|
return texture.get();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,6 +5,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <optional>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include "../../maths/UVRegion.hpp"
|
#include "../../maths/UVRegion.hpp"
|
||||||
#include "../../typedefs.hpp"
|
#include "../../typedefs.hpp"
|
||||||
@ -31,6 +32,7 @@ public:
|
|||||||
|
|
||||||
bool has(const std::string& name) const;
|
bool has(const std::string& name) const;
|
||||||
const UVRegion& get(const std::string& name) const;
|
const UVRegion& get(const std::string& name) const;
|
||||||
|
std::optional<UVRegion> getIf(const std::string& name) const;
|
||||||
|
|
||||||
Texture* getTexture() const;
|
Texture* getTexture() const;
|
||||||
ImageData* getImage() const;
|
ImageData* getImage() const;
|
||||||
|
|||||||
@ -30,14 +30,17 @@ void Image::draw(const DrawContext* pctx, Assets* assets) {
|
|||||||
} else {
|
} else {
|
||||||
auto atlasName = this->texture.substr(0, separator);
|
auto atlasName = this->texture.substr(0, separator);
|
||||||
if (auto atlas = assets->get<Atlas>(atlasName)) {
|
if (auto atlas = assets->get<Atlas>(atlasName)) {
|
||||||
|
if (auto region = atlas->getIf(this->texture.substr(separator+1))) {
|
||||||
texture = atlas->getTexture();
|
texture = atlas->getTexture();
|
||||||
batch->texture(atlas->getTexture());
|
batch->texture(atlas->getTexture());
|
||||||
auto& region = atlas->get(this->texture.substr(separator+1));
|
batch->setRegion(*region);
|
||||||
batch->setRegion(region);
|
|
||||||
if (autoresize) {
|
if (autoresize) {
|
||||||
setSize(glm::vec2(
|
setSize(glm::vec2(
|
||||||
texture->getWidth()*region.getWidth(),
|
texture->getWidth()*region->getWidth(),
|
||||||
texture->getHeight()*region.getHeight()));
|
texture->getHeight()*region->getHeight()));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
batch->texture(nullptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,7 +26,7 @@ static int l_world_get_list(lua::State* L) {
|
|||||||
lua::setfield(L, "name");
|
lua::setfield(L, "name");
|
||||||
|
|
||||||
auto assets = engine->getAssets();
|
auto assets = engine->getAssets();
|
||||||
std::string icon = "world:"+name+".icon";
|
std::string icon = "world#"+name+".icon";
|
||||||
if (!AssetsLoader::loadExternalTexture(assets, icon, {
|
if (!AssetsLoader::loadExternalTexture(assets, icon, {
|
||||||
worlds[i]/fs::path("icon.png"),
|
worlds[i]/fs::path("icon.png"),
|
||||||
worlds[i]/fs::path("preview.png")
|
worlds[i]/fs::path("preview.png")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user