Merge branch 'main' into volume-renderer

This commit is contained in:
MihailRis 2026-01-29 22:34:34 +03:00
commit d9a7afad05
42 changed files with 539 additions and 196 deletions

View file

@ -1,6 +1,7 @@
#include "api_lua.hpp"
#include "assets/Assets.hpp"
#include "assets/AssetsLoader.hpp"
#include "coders/png.hpp"
#include "coders/vcm.hpp"
#include "debug/Logger.hpp"
@ -24,6 +25,14 @@ static void load_texture(
}
}
static int l_request_texture(lua::State* L) {
std::string filename = lua::require_string(L, 1);
std::string alias = lua::require_string(L, 2);
auto& loader = engine->acquireBackgroundLoader();
loader.add(AssetType::TEXTURE, filename, alias);
return 0;
}
static int l_load_texture(lua::State* L) {
if (lua::isstring(L, 3) && lua::require_lstring(L, 3) != "png") {
throw std::runtime_error("unsupportd image format");
@ -108,6 +117,7 @@ static int l_to_canvas(lua::State* L) {
}
const luaL_Reg assetslib[] = {
{"request_texture", lua::wrap<l_request_texture>},
{"load_texture", lua::wrap<l_load_texture>},
{"parse_model", lua::wrap<l_parse_model>},
{"to_canvas", lua::wrap<l_to_canvas>},

View file

@ -397,6 +397,13 @@ static int p_get_src(UINode* node, lua::State* L) {
return 0;
}
static int p_get_fallback(UINode* node, lua::State* L) {
if (auto image = dynamic_cast<Image*>(node)) {
return lua::pushstring(L, image->getFallback());
}
return 0;
}
static int p_get_region(UINode* node, lua::State* L) {
if (auto image = dynamic_cast<Image*>(node)) {
const auto& region = image->getRegion();
@ -663,6 +670,7 @@ static int l_gui_getattr(lua::State* L) {
{"syntax", p_get_syntax},
{"markup", p_get_markup},
{"src", p_get_src},
{"fallback", p_get_fallback},
{"value", p_get_value},
{"min", p_get_min},
{"max", p_get_max},
@ -790,6 +798,11 @@ static void p_set_src(UINode* node, lua::State* L, int idx) {
modelviewer->setModel(lua::require_string(L, idx));
}
}
static void p_set_fallback(UINode* node, lua::State* L, int idx) {
if (auto image = dynamic_cast<Image*>(node)) {
image->setFallback(lua::require_string(L, idx));
}
}
static void p_set_region(UINode* node, lua::State* L, int idx) {
if (auto image = dynamic_cast<Image*>(node)) {
auto vec = lua::tovec4(L, idx);
@ -962,6 +975,7 @@ static int l_gui_setattr(lua::State* L) {
{"syntax", p_set_syntax},
{"markup", p_set_markup},
{"src", p_set_src},
{"fallback", p_set_fallback},
{"caret", p_set_caret},
{"value", p_set_value},
{"min", p_set_min},

View file

@ -87,10 +87,10 @@ static int l_pack_get_info(
lua::setfield(L, "path");
if (!engine->isHeadless()) {
auto assets = engine->getAssets();
auto& assetsLoader = engine->acquireBackgroundLoader();
std::string icon = pack.id + ".icon";
if (!AssetsLoader::loadExternalTexture(
assets, icon, {pack.folder / "icon.png"}
assetsLoader, icon, {pack.folder / "icon.png"}
)) {
icon = "gui/no_icon";
}

View file

@ -56,10 +56,9 @@ static int l_get_list(lua::State* L) {
lua::pushstring(L, name);
lua::setfield(L, "name");
auto assets = engine->getAssets();
std::string icon = "world#" + name + ".icon";
if (!engine->isHeadless() && !AssetsLoader::loadExternalTexture(
assets,
engine->acquireBackgroundLoader(),
icon,
{worlds[i] / "icon.png",
worlds[i] / "preview.png"}

View file

@ -1,8 +1,5 @@
#include "scripting.hpp"
#include <iostream>
#include <stdexcept>
#include "scripting_commons.hpp"
#include "content/Content.hpp"
#include "content/ContentPack.hpp"
@ -28,6 +25,9 @@
#include "world/World.hpp"
#include "interfaces/Process.hpp"
#include <iostream>
#include <stdexcept>
using namespace scripting;
static debug::Logger logger("scripting");
@ -391,15 +391,15 @@ void scripting::on_blocks_tick(const Block& block, int tps) {
}
void scripting::update_block(const Block& block, const glm::ivec3& pos) {
std::string name = block.name + ".update";
lua::emit_event(lua::get_main_state(), name, [pos](auto L) {
lua::emit_event(lua::get_main_state(), block.rt.eventNames.update,
[pos](auto L) {
return lua::pushivec_stack(L, pos);
});
}
void scripting::random_update_block(const Block& block, const glm::ivec3& pos) {
std::string name = block.name + ".randupdate";
lua::emit_event(lua::get_main_state(), name, [pos](auto L) {
lua::emit_event(lua::get_main_state(), block.rt.eventNames.randomUpdate,
[pos](auto L) {
return lua::pushivec_stack(L, pos);
});
}
@ -660,7 +660,8 @@ void scripting::load_content_script(
const std::string& prefix,
const io::path& file,
const std::string& fileName,
BlockFuncsSet& funcsset
BlockFuncsSet& funcsset,
BlockFuncNamesCache& namesCache
) {
int env = *senv;
lua::pop(lua::get_main_state(), load_script(env, "block", file, fileName));
@ -686,6 +687,9 @@ void scripting::load_content_script(
register_event(env, "on_block_present", prefix + ".blockpresent");
funcsset.onblockremoved =
register_event(env, "on_block_removed", prefix + ".blockremoved");
namesCache.randomUpdate = prefix + ".update";
namesCache.randomUpdate = prefix + ".randupdate";
}
void scripting::load_content_script(
@ -693,7 +697,8 @@ void scripting::load_content_script(
const std::string& prefix,
const io::path& file,
const std::string& fileName,
ItemFuncsSet& funcsset
ItemFuncsSet& funcsset,
ItemFuncNamesCache& namesCache
) {
int env = *senv;
lua::pop(lua::get_main_state(), load_script(env, "item", file, fileName));

View file

@ -23,7 +23,9 @@ struct ItemDef;
class Inventory;
class UiDocument;
struct BlockFuncsSet;
struct BlockFuncNamesCache;
struct ItemFuncsSet;
struct ItemFuncNamesCache;
struct WorldFuncsSet;
struct UserComponent;
struct uidocscript;
@ -168,7 +170,8 @@ namespace scripting {
const std::string& prefix,
const io::path& file,
const std::string& fileName,
BlockFuncsSet& funcsset
BlockFuncsSet& funcsset,
BlockFuncNamesCache& namesCache
);
/// @brief Load script associated with an Item
@ -182,7 +185,8 @@ namespace scripting {
const std::string& prefix,
const io::path& file,
const std::string& fileName,
ItemFuncsSet& funcsset
ItemFuncsSet& funcsset,
ItemFuncNamesCache& namesCache
);
/// @brief Load component script