fix: pack environment not passed to components
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include "libentity.hpp"
|
||||
|
||||
#include "content/Content.hpp"
|
||||
#include "content/ContentPack.hpp"
|
||||
#include "engine/Engine.hpp"
|
||||
#include "engine/EnginePaths.hpp"
|
||||
#include "objects/Entities.hpp"
|
||||
@@ -236,7 +237,14 @@ static int l_reload_component(lua::State* L) {
|
||||
}
|
||||
auto filename = name.substr(0, pos + 1) + "scripts/components/" +
|
||||
name.substr(pos + 1) + ".lua";
|
||||
scripting::load_entity_component(name, filename, filename);
|
||||
auto prefix = name.substr(0, pos);
|
||||
auto runtime = content->getPackRuntime(prefix);
|
||||
if (runtime == nullptr) {
|
||||
throw std::runtime_error("pack '" + prefix + "' content is not loaded");
|
||||
}
|
||||
scripting::load_entity_component(
|
||||
runtime->getEnvironment(), name, filename, filename
|
||||
);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -708,12 +708,15 @@ void scripting::load_content_script(
|
||||
}
|
||||
|
||||
void scripting::load_entity_component(
|
||||
const std::string& name, const io::path& file, const std::string& fileName
|
||||
const scriptenv& env,
|
||||
const std::string& name,
|
||||
const io::path& file,
|
||||
const std::string& fileName
|
||||
) {
|
||||
auto L = lua::get_main_state();
|
||||
std::string src = io::read_string(file);
|
||||
logger.info() << "script (component) " << file.string();
|
||||
lua::loadbuffer(L, 0, src, fileName);
|
||||
lua::loadbuffer(L, *env, src, fileName);
|
||||
lua::store_in(L, lua::CHUNKS_TABLE, name);
|
||||
}
|
||||
|
||||
|
||||
@@ -186,10 +186,12 @@ namespace scripting {
|
||||
);
|
||||
|
||||
/// @brief Load component script
|
||||
/// @param env environment
|
||||
/// @param name component full name (packid:name)
|
||||
/// @param file component script file path
|
||||
/// @param fileName script file path using the engine format
|
||||
void load_entity_component(
|
||||
const scriptenv& env,
|
||||
const std::string& name,
|
||||
const io::path& file,
|
||||
const std::string& fileName
|
||||
|
||||
Reference in New Issue
Block a user