add block.properties, item.properties (experimental)
This commit is contained in:
parent
b40c8c4b4c
commit
cd630463b3
@ -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();
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
#include <glm/glm.hpp>
|
||||
#include <string>
|
||||
|
||||
#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};
|
||||
|
||||
@ -157,10 +157,26 @@ void scripting::process_post_runnables() {
|
||||
}
|
||||
}
|
||||
|
||||
template <class T>
|
||||
static int push_properties_tables(
|
||||
lua::State* L, const ContentUnitIndices<T>& 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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -119,6 +119,8 @@ public:
|
||||
/// @brief Textures set applied to block sides
|
||||
std::array<std::string, 6> 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;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user