feat: world script reloading
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include "assets/AssetsLoader.hpp"
|
||||
#include "coders/json.hpp"
|
||||
#include "content/Content.hpp"
|
||||
#include "content/ContentLoader.hpp"
|
||||
#include "engine/Engine.hpp"
|
||||
#include "world/files/WorldFiles.hpp"
|
||||
#include "io/engine_paths.hpp"
|
||||
@@ -213,6 +214,17 @@ static int l_count_chunks(lua::State* L) {
|
||||
return lua::pushinteger(L, level->chunks->size());
|
||||
}
|
||||
|
||||
static int l_reload_script(lua::State* L) {
|
||||
auto packid = lua::require_string(L, 1);
|
||||
if (content == nullptr) {
|
||||
throw std::runtime_error("content is not initialized");
|
||||
}
|
||||
auto& writeableContent = *engine->getWriteableContent();
|
||||
auto pack = writeableContent.getPackRuntime(packid);
|
||||
ContentLoader::loadWorldScript(*pack);
|
||||
return 0;
|
||||
}
|
||||
|
||||
const luaL_Reg worldlib[] = {
|
||||
{"is_open", lua::wrap<l_is_open>},
|
||||
{"get_list", lua::wrap<l_get_list>},
|
||||
@@ -230,5 +242,6 @@ const luaL_Reg worldlib[] = {
|
||||
{"set_chunk_data", lua::wrap<l_set_chunk_data>},
|
||||
{"save_chunk_data", lua::wrap<l_save_chunk_data>},
|
||||
{"count_chunks", lua::wrap<l_count_chunks>},
|
||||
{"reload_script", lua::wrap<l_reload_script>},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
@@ -836,6 +836,8 @@ void scripting::load_content_script(
|
||||
) {
|
||||
int env = *senv;
|
||||
lua::pop(lua::get_main_state(), load_script(env, "block", file, fileName));
|
||||
|
||||
funcsset = {};
|
||||
funcsset.init = register_event(env, "init", prefix + ".init");
|
||||
funcsset.update = register_event(env, "on_update", prefix + ".update");
|
||||
funcsset.randupdate =
|
||||
@@ -861,6 +863,8 @@ void scripting::load_content_script(
|
||||
) {
|
||||
int env = *senv;
|
||||
lua::pop(lua::get_main_state(), load_script(env, "item", file, fileName));
|
||||
|
||||
funcsset = {};
|
||||
funcsset.init = register_event(env, "init", prefix + ".init");
|
||||
funcsset.on_use = register_event(env, "on_use", prefix + ".use");
|
||||
funcsset.on_use_on_block =
|
||||
@@ -888,6 +892,8 @@ void scripting::load_world_script(
|
||||
) {
|
||||
int env = *senv;
|
||||
lua::pop(lua::get_main_state(), load_script(env, "world", file, fileName));
|
||||
|
||||
funcsset = {};
|
||||
register_event(env, "init", prefix + ".init");
|
||||
register_event(env, "on_world_open", prefix + ":.worldopen");
|
||||
register_event(env, "on_world_tick", prefix + ":.worldtick");
|
||||
|
||||
Reference in New Issue
Block a user