content packs icons fix

This commit is contained in:
MihailRis 2024-04-19 13:56:24 +03:00
parent 01f41715d7
commit bedcc438f4
5 changed files with 18 additions and 2 deletions

View File

@ -8,7 +8,6 @@ function add_pack(packid, packinfo)
end
packinfo.id = packid
packinfo.remover = remover
packinfo.icon = "gui/no_icon"
document.packs_panel:add(gui.template("pack", packinfo))
end

View File

@ -7,7 +7,7 @@
</textbox>
<label>@Seed</label>
<textbox id='seed_box' placeholder='-' padding='4'></textbox>
<button onclick='menu.page="world_generators"' id='generator_btn' padding='10'>
<button onclick='menu.page="generators"' id='generator_btn' padding='10'>
@World generator
</button>
<button onclick='create_world()' padding='10' margin='1,20,1,1'>

View File

@ -2,10 +2,12 @@
#include "lua_commons.h"
#include "../scripting.h"
#include "../../../engine.h"
#include "../../../coders/imageio.h"
#include "../../../files/engine_paths.h"
#include "../../../files/WorldFiles.h"
#include "../../../world/Level.h"
#include "../../../world/World.h"
#include "../../../graphics/core/Texture.h"
#include <string>
#include <filesystem>
@ -73,6 +75,21 @@ 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");
// 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::is_regular_file(iconfile)) {
auto image = imageio::read(iconfile.string());
assets->store(Texture::from(image.get()), icon);
} else {
icon = "gui/no_icon";
}
}
lua_pushstring(L, icon.c_str());
lua_setfield(L, -2, "icon");
auto runtime = content ? content->getPackRuntime(pack.id) : nullptr;
if (runtime) {
lua_pushboolean(L, runtime->getStats().hasSavingContent());