mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-05 02:51:49 +00:00
AssetsLoader::loadExternalTexture
This commit is contained in:
parent
0c731f3fe4
commit
cc5784c878
4 changed files with 44 additions and 30 deletions
|
|
@ -2,12 +2,11 @@
|
|||
#include "lua_commons.h"
|
||||
#include "../scripting.h"
|
||||
#include "../../../engine.h"
|
||||
#include "../../../coders/imageio.h"
|
||||
#include "../../../assets/AssetsLoader.h"
|
||||
#include "../../../files/engine_paths.h"
|
||||
#include "../../../files/WorldFiles.h"
|
||||
#include "../../../world/Level.h"
|
||||
#include "../../../world/World.h"
|
||||
#include "../../../graphics/core/Texture.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <filesystem>
|
||||
|
|
@ -75,21 +74,14 @@ static int l_pack_get_info(lua_State* L, const ContentPack& pack, const Content*
|
|||
lua_pushstring(L, pack.version.c_str());
|
||||
lua_setfield(L, -2, "version");
|
||||
|
||||
// FIXME: hmm
|
||||
auto assets = scripting::engine->getAssets();
|
||||
std::string icon = pack.id+".icon";
|
||||
if (assets->getTexture(icon) == nullptr) {
|
||||
auto iconfile = pack.folder/fs::path("icon.png");
|
||||
if (!fs::exists(iconfile)) {
|
||||
iconfile = pack.folder/fs::path("preview.png");
|
||||
}
|
||||
if (fs::exists(iconfile)) {
|
||||
auto image = imageio::read(iconfile.string());
|
||||
assets->store(Texture::from(image.get()), icon);
|
||||
} else {
|
||||
icon = "gui/no_icon";
|
||||
}
|
||||
if (!AssetsLoader::loadExternalTexture(assets, icon, {
|
||||
pack.folder/fs::path("icon.png")
|
||||
})) {
|
||||
icon = "gui/no_icon";
|
||||
}
|
||||
|
||||
lua_pushstring(L, icon.c_str());
|
||||
lua_setfield(L, -2, "icon");
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,7 @@
|
|||
#include "api_lua.h"
|
||||
#include "../scripting.h"
|
||||
#include "../../../assets/Assets.h"
|
||||
#include "../../../coders/imageio.h"
|
||||
#include "../../../graphics/core/Texture.hpp"
|
||||
#include "../../../assets/AssetsLoader.h"
|
||||
#include "../../../files/engine_paths.h"
|
||||
#include "../../../world/Level.h"
|
||||
#include "../../../world/World.h"
|
||||
|
|
@ -26,18 +25,13 @@ static int l_world_get_list(lua_State* L) {
|
|||
lua_pushstring(L, name.c_str());
|
||||
lua_setfield(L, -2, "name");
|
||||
|
||||
// FIXME: hmm
|
||||
auto assets = scripting::engine->getAssets();
|
||||
std::string icon = "world:"+name+".icon";
|
||||
|
||||
if (assets->getTexture(icon) == nullptr) {
|
||||
auto iconfile = worlds[i]/fs::path("preview.png");
|
||||
if (fs::is_regular_file(iconfile)) {
|
||||
auto image = imageio::read(iconfile.string());
|
||||
assets->store(Texture::from(image.get()), icon);
|
||||
} else {
|
||||
icon = "gui/no_world_icon";
|
||||
}
|
||||
if (!AssetsLoader::loadExternalTexture(assets, icon, {
|
||||
worlds[i]/fs::path("icon.png"),
|
||||
worlds[i]/fs::path("preview.png")
|
||||
})) {
|
||||
icon = "gui/no_world_icon";
|
||||
}
|
||||
lua_pushstring(L, icon.c_str());
|
||||
lua_setfield(L, -2, "icon");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue