From cd630463b3ad1f6a02691fd3a48426bbd52c328f Mon Sep 17 00:00:00 2001 From: MihailRis Date: Fri, 22 Nov 2024 11:08:36 +0300 Subject: [PATCH 01/23] add block.properties, item.properties (experimental) --- src/content/ContentLoader.cpp | 2 ++ src/items/ItemDef.hpp | 3 +++ src/logic/scripting/scripting.cpp | 24 ++++++++++++++++++++++++ src/voxels/Block.hpp | 2 ++ 4 files changed, 31 insertions(+) diff --git a/src/content/ContentLoader.cpp b/src/content/ContentLoader.cpp index 0f8bf6a2..1e954a55 100644 --- a/src/content/ContentLoader.cpp +++ b/src/content/ContentLoader.cpp @@ -191,6 +191,7 @@ void ContentLoader::loadBlock( Block& def, const std::string& name, const fs::path& file ) { auto root = files::read_json(file); + def.properties = root; if (root.has("parent")) { const auto& parentName = root["parent"].asString(); @@ -360,6 +361,7 @@ void ContentLoader::loadItem( ItemDef& def, const std::string& name, const fs::path& file ) { auto root = files::read_json(file); + def.properties = root; if (root.has("parent")) { const auto& parentName = root["parent"].asString(); diff --git a/src/items/ItemDef.hpp b/src/items/ItemDef.hpp index 999b190f..7a2ef8d1 100644 --- a/src/items/ItemDef.hpp +++ b/src/items/ItemDef.hpp @@ -3,6 +3,7 @@ #include #include +#include "data/dv.hpp" #include "typedefs.hpp" struct item_funcs_set { @@ -25,6 +26,8 @@ struct ItemDef { /// @brief Item name will shown in inventory std::string caption; + dv::value properties = nullptr; + itemcount_t stackSize = 64; bool generated = false; uint8_t emission[4] {0, 0, 0, 0}; diff --git a/src/logic/scripting/scripting.cpp b/src/logic/scripting/scripting.cpp index 0778fd45..99be18c4 100644 --- a/src/logic/scripting/scripting.cpp +++ b/src/logic/scripting/scripting.cpp @@ -157,10 +157,26 @@ void scripting::process_post_runnables() { } } +template +static int push_properties_tables( + lua::State* L, const ContentUnitIndices& indices +) { + const auto units = indices.getDefs(); + size_t size = indices.count(); + lua::createtable(L, size, 0); + for (size_t i = 0; i < size; i++) { + lua::pushvalue(L, units[i]->properties); + lua::rawseti(L, i); + } + return 1; +} + void scripting::on_content_load(Content* content) { scripting::content = content; scripting::indices = content->getIndices(); + const auto& indices = *content->getIndices(); + auto L = lua::get_main_state(); if (lua::getglobal(L, "block")) { const auto& materials = content->getBlockMaterials(); @@ -170,6 +186,14 @@ void scripting::on_content_load(Content* content) { lua::setfield(L, name); } lua::setfield(L, "materials"); + + push_properties_tables(L, indices.blocks); + lua::setfield(L, "properties"); + lua::pop(L); + } + if (lua::getglobal(L, "item")) { + push_properties_tables(L, indices.blocks); + lua::setfield(L, "properties"); lua::pop(L); } } diff --git a/src/voxels/Block.hpp b/src/voxels/Block.hpp index 4fe51b0d..79b739e5 100644 --- a/src/voxels/Block.hpp +++ b/src/voxels/Block.hpp @@ -119,6 +119,8 @@ public: /// @brief Textures set applied to block sides std::array textureFaces; // -x,x, -y,y, -z,z + dv::value properties = nullptr; + /// @brief id of used BlockMaterial, may specify non-existing material std::string material = DEFAULT_MATERIAL; From 9ed80ec83579a90d5c6369f134d0c8abdd2eecc5 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Sun, 24 Nov 2024 12:09:46 +0300 Subject: [PATCH 02/23] disable traceback lines with non-existing files --- res/layouts/console.xml.lua | 6 ++---- res/layouts/templates/stack_frame.xml | 2 +- src/assets/assetload_funcs.cpp | 10 +++++++++- src/logic/scripting/lua/libs/libfile.cpp | 2 +- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/res/layouts/console.xml.lua b/res/layouts/console.xml.lua index 7d4c2771..11d7bd14 100644 --- a/res/layouts/console.xml.lua +++ b/res/layouts/console.xml.lua @@ -84,13 +84,11 @@ events.on("core:open_traceback", function(traceback_b64) framestr = framestr.."("..tostring(frame.name)..")" end local color = "#FFFFFF" - if frame.source:starts_with("core:") then - color = "#C0D0C5" - end tb_list:add(gui.template("stack_frame", { location=framestr, color=color, - callback=callback + callback=callback, + enabled=file.exists(frame.source) })) end tb_list.size = srcsize diff --git a/res/layouts/templates/stack_frame.xml b/res/layouts/templates/stack_frame.xml index c73890bb..16f2571c 100644 --- a/res/layouts/templates/stack_frame.xml +++ b/res/layouts/templates/stack_frame.xml @@ -1,3 +1,3 @@ -