add bytearray option for generation.load_fragment (#597)

This commit is contained in:
MihailRis 2025-08-23 19:46:07 +03:00 committed by GitHub
parent 17f3e03ea9
commit 8c7409eed1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -36,11 +36,19 @@ static int l_create_fragment(lua::State* L) {
}
static int l_load_fragment(lua::State* L) {
io::path path = lua::require_string(L, 1);
if (!io::exists(path)) {
throw std::runtime_error("file "+path.string()+" does not exist");
dv::value map;
if (!lua::isstring(L, 1)) {
io::path path = lua::require_string(L, 1);
if (!io::exists(path)) {
throw std::runtime_error("file "+path.string()+" does not exist");
}
map = io::read_binary_json(path);
} else {
auto bytearray = lua::bytearray_as_string(L, 1);
map = json::from_binary(
reinterpret_cast<const ubyte*>(bytearray.data()), bytearray.size()
);
}
auto map = io::read_binary_json(path);
auto fragment = std::make_shared<VoxelFragment>();
fragment->deserialize(map);