add VoxelStructure lua usertype
This commit is contained in:
@@ -5,6 +5,8 @@
|
||||
#include "coders/binary_json.hpp"
|
||||
#include "world/Level.hpp"
|
||||
#include "world/generator/VoxelStructure.hpp"
|
||||
#include "engine.hpp"
|
||||
#include "lua_custom_types.hpp"
|
||||
|
||||
using namespace scripting;
|
||||
|
||||
@@ -25,6 +27,21 @@ static int l_save_structure(lua::State* L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_load_structure(lua::State* L) {
|
||||
auto paths = engine->getPaths();
|
||||
auto filename = lua::require_string(L, 1);
|
||||
auto path = paths->resolve(filename);
|
||||
if (!std::filesystem::exists(path)) {
|
||||
throw std::runtime_error("file "+path.u8string()+" does not exist");
|
||||
}
|
||||
auto map = files::read_binary_json(path);
|
||||
|
||||
auto structure = std::make_shared<VoxelStructure>();
|
||||
structure->deserialize(map);
|
||||
return lua::newuserdata<lua::LuaVoxelStructure>(L, std::move(structure));
|
||||
}
|
||||
|
||||
const luaL_Reg generationlib[] = {
|
||||
{"save_structure", lua::wrap<l_save_structure>},
|
||||
{"load_structure", lua::wrap<l_load_structure>},
|
||||
{NULL, NULL}};
|
||||
|
||||
Reference in New Issue
Block a user