mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-12 14:31:50 +00:00
fix components parent environment
This commit is contained in:
parent
2afadb4ae6
commit
dcaf87988b
2 changed files with 21 additions and 1 deletions
|
|
@ -114,6 +114,14 @@ struct ContentPack {
|
||||||
default: return "";
|
default: return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static std::string_view getPrefix(std::string_view path) {
|
||||||
|
size_t pos = path.find(':');
|
||||||
|
if (pos == std::string::npos) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return path.substr(0, pos);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct WorldFuncsSet {
|
struct WorldFuncsSet {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
#include "scripting.hpp"
|
#include "scripting.hpp"
|
||||||
|
|
||||||
|
#include "debug/Logger.hpp"
|
||||||
#include "lua/lua_engine.hpp"
|
#include "lua/lua_engine.hpp"
|
||||||
#include "objects/Entities.hpp"
|
#include "objects/Entities.hpp"
|
||||||
#include "objects/EntityDef.hpp"
|
#include "objects/EntityDef.hpp"
|
||||||
|
|
@ -11,6 +12,7 @@
|
||||||
|
|
||||||
using namespace scripting;
|
using namespace scripting;
|
||||||
|
|
||||||
|
static debug::Logger logger("scripting-entities");
|
||||||
static inline const std::string STDCOMP = "stdcomp";
|
static inline const std::string STDCOMP = "stdcomp";
|
||||||
|
|
||||||
[[nodiscard]] static scriptenv create_component_environment(
|
[[nodiscard]] static scriptenv create_component_environment(
|
||||||
|
|
@ -61,9 +63,19 @@ static void create_component(
|
||||||
const dv::value& args,
|
const dv::value& args,
|
||||||
const dv::value& saved
|
const dv::value& saved
|
||||||
) {
|
) {
|
||||||
|
auto parentEnv = get_root_environment();
|
||||||
|
auto prefix = ContentPack::getPrefix(component.name);
|
||||||
|
const auto& content = *scripting::content;
|
||||||
|
if (auto runtime = content.getPackRuntime(std::string(prefix))) {
|
||||||
|
parentEnv = runtime->getEnvironment();
|
||||||
|
} else {
|
||||||
|
logger.warning() << "pack environment is not available for "
|
||||||
|
<< component.name;
|
||||||
|
}
|
||||||
|
logger.debug() << "creating instance of component " << component.name;
|
||||||
lua::pushvalue(L, entityIdx);
|
lua::pushvalue(L, entityIdx);
|
||||||
auto compenv = create_component_environment(
|
auto compenv = create_component_environment(
|
||||||
get_root_environment(), -1, component.name
|
std::move(parentEnv), -1, component.name
|
||||||
);
|
);
|
||||||
lua::get_from(L, lua::CHUNKS_TABLE, component.name, true);
|
lua::get_from(L, lua::CHUNKS_TABLE, component.name, true);
|
||||||
lua::pushenv(L, *compenv);
|
lua::pushenv(L, *compenv);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue