From 0082a3444e1b8052bfb091d06e3fc3ea736b279b Mon Sep 17 00:00:00 2001 From: MihailRis Date: Tue, 2 Jul 2024 20:01:29 +0300 Subject: [PATCH] update component parent environment to the pack environment --- src/content/ContentLoader.cpp | 19 ------------------- src/logic/scripting/scripting.cpp | 2 +- src/objects/Entities.cpp | 31 +++++++++++++++++++------------ src/objects/rigging.hpp | 7 +++++++ 4 files changed, 27 insertions(+), 32 deletions(-) diff --git a/src/content/ContentLoader.cpp b/src/content/ContentLoader.cpp index c00a0f3e..253434a9 100644 --- a/src/content/ContentLoader.cpp +++ b/src/content/ContentLoader.cpp @@ -380,25 +380,6 @@ void ContentLoader::loadBlockMaterial(BlockMaterial& def, const fs::path& file) root->str("break-sound", def.breakSound); } -template -static void load_defs(ContentLoader* cl, dynamic::List* arr, const ContentPack* pack, ContentUnitBuilder& builder, size_t& counter) { - if (arr == nullptr) { - return; - } - for (size_t i = 0; i < arr->size(); i++) { - std::string name = arr->str(i); - auto colon = name.find(':'); - std::string full = colon == std::string::npos ? pack->id + ":" + name : name; - if (colon != std::string::npos) name[colon] = '/'; - auto& def = builder.create(full); - if (colon != std::string::npos) { - def.scriptName = name.substr(0, colon) + '/' + def.scriptName; - } - cl->*loadfunc(def, full, name); - counter++; - } -} - void ContentLoader::load() { logger.info() << "loading pack [" << pack->id << "]"; diff --git a/src/logic/scripting/scripting.cpp b/src/logic/scripting/scripting.cpp index 5843f6d2..c5c99fbc 100644 --- a/src/logic/scripting/scripting.cpp +++ b/src/logic/scripting/scripting.cpp @@ -451,7 +451,7 @@ void scripting::load_entity_component(const scriptenv& penv, const EntityDef& de auto L = lua::get_main_thread(); std::string src = files::read_string(file); logger.info() << "script (component) " << file.u8string(); - lua::loadbuffer(L, 0, src, file.u8string()); + lua::loadbuffer(L, *penv, src, file.u8string()); lua::store_in(L, lua::CHUNKS_TABLE, def.scriptName); } diff --git a/src/objects/Entities.cpp b/src/objects/Entities.cpp index a62b03d5..00385120 100644 --- a/src/objects/Entities.cpp +++ b/src/objects/Entities.cpp @@ -53,20 +53,27 @@ entityid_t Entities::spawn( auto& body = registry.emplace( entity, true, Hitbox {pos, def.hitbox}, std::vector{}); for (auto& box : def.triggers) { - body.triggers.emplace_back(Trigger{true, id, box, AABB{}, {}, {}, - [=](auto entityid, auto index, auto otherid) { - if (auto entity = get(entityid)) { - if (entity->isValid()) { - scripting::on_trigger_enter(*entity, index, otherid); + body.triggers.emplace_back(Trigger{ + true, + id, + box, + AABB{}, + {}, + {}, + [=](auto entityid, auto index, auto otherid) { + if (auto entity = get(entityid)) { + if (entity->isValid()) { + scripting::on_trigger_enter(*entity, index, otherid); + } } - } - }, [=](auto entityid, auto index, auto otherid) { - if (auto entity = get(entityid)) { - if (entity->isValid()) { - scripting::on_trigger_exit(*entity, index, otherid); + }, + [=](auto entityid, auto index, auto otherid) { + if (auto entity = get(entityid)) { + if (entity->isValid()) { + scripting::on_trigger_exit(*entity, index, otherid); + } } - } - }}); + }}); } auto& scripting = registry.emplace( entity, entity_funcs_set {}, nullptr); diff --git a/src/objects/rigging.hpp b/src/objects/rigging.hpp index c1028890..6da4bf97 100644 --- a/src/objects/rigging.hpp +++ b/src/objects/rigging.hpp @@ -73,6 +73,13 @@ namespace rigging { class RigConfig { std::unique_ptr root; std::unordered_map indices; + + /// Nodes and indices are ordered from root to subnodes. + /// Example: + /// 0 - root + /// 1 --- sub1 + /// 2 ----- subsub1 + /// 3 --- sub2 std::vector nodes; size_t update(