mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-05 19:11:50 +00:00
Merge branch 'main' into debugging-client
This commit is contained in:
commit
4d82fb7873
30 changed files with 560 additions and 135 deletions
|
|
@ -730,7 +730,7 @@ static int l_pull_register_events(lua::State* L) {
|
|||
lua::createtable(L, events.size() * 4, 0);
|
||||
for (int i = 0; i < events.size(); i++) {
|
||||
const auto& event = events[i];
|
||||
lua::pushinteger(L, static_cast<int>(event.type) | event.id << 16);
|
||||
lua::pushinteger(L, static_cast<int>(event.bits) | event.id << 16);
|
||||
lua::rawseti(L, i * 4 + 1);
|
||||
|
||||
for (int j = 0; j < 3; j++) {
|
||||
|
|
|
|||
|
|
@ -120,6 +120,7 @@ static int l_close_world(lua::State* L) {
|
|||
if (controller == nullptr) {
|
||||
throw std::runtime_error("no world open");
|
||||
}
|
||||
controller->processBeforeQuit();
|
||||
bool save_world = lua::toboolean(L, 1);
|
||||
if (save_world) {
|
||||
controller->saveWorld();
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
#define VC_ENABLE_REFLECTION
|
||||
#include "lua_type_canvas.hpp"
|
||||
|
||||
#include "graphics/core/ImageData.hpp"
|
||||
#include "graphics/core/Texture.hpp"
|
||||
#include "logic/scripting/lua/lua_util.hpp"
|
||||
#include "coders/imageio.hpp"
|
||||
#include "engine/Engine.hpp"
|
||||
#include "assets/Assets.hpp"
|
||||
|
||||
|
|
@ -284,6 +286,23 @@ static int l_sub(State* L) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int l_encode(State* L) {
|
||||
auto canvas = touserdata<LuaCanvas>(L, 1);
|
||||
if (canvas == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
auto format = imageio::ImageFileFormat::PNG;
|
||||
if (lua::isstring(L, 2)) {
|
||||
auto name = lua::require_string(L, 2);
|
||||
if (!imageio::ImageFileFormatMeta.getItem(name, format)) {
|
||||
throw std::runtime_error("unsupported image file format");
|
||||
}
|
||||
}
|
||||
|
||||
auto buffer = imageio::encode(format, canvas->getData());
|
||||
return lua::create_bytearray(L, buffer.data(), buffer.size());
|
||||
}
|
||||
|
||||
static std::unordered_map<std::string, lua_CFunction> methods {
|
||||
{"at", lua::wrap<l_at>},
|
||||
{"set", lua::wrap<l_set>},
|
||||
|
|
@ -296,6 +315,7 @@ static std::unordered_map<std::string, lua_CFunction> methods {
|
|||
{"mul", lua::wrap<l_mul>},
|
||||
{"add", lua::wrap<l_add>},
|
||||
{"sub", lua::wrap<l_sub>},
|
||||
{"encode", lua::wrap<l_encode>},
|
||||
{"_set_data", lua::wrap<l_set_data>},
|
||||
};
|
||||
|
||||
|
|
@ -354,6 +374,23 @@ static int l_meta_meta_call(lua::State* L) {
|
|||
);
|
||||
}
|
||||
|
||||
static int l_canvas_decode(lua::State* L) {
|
||||
auto bytes = bytearray_as_string(L, 1);
|
||||
auto formatName = require_lstring(L, 2);
|
||||
imageio::ImageFileFormat format;
|
||||
if (!imageio::ImageFileFormatMeta.getItem(formatName, format)) {
|
||||
throw std::runtime_error("unsupported image format");
|
||||
}
|
||||
return newuserdata<LuaCanvas>(
|
||||
L,
|
||||
nullptr,
|
||||
imageio::decode(
|
||||
format,
|
||||
{reinterpret_cast<const unsigned char*>(bytes.data()), bytes.size()}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
int LuaCanvas::createMetatable(State* L) {
|
||||
createtable(L, 0, 3);
|
||||
pushcfunction(L, lua::wrap<l_meta_index>);
|
||||
|
|
@ -365,5 +402,8 @@ int LuaCanvas::createMetatable(State* L) {
|
|||
pushcfunction(L, lua::wrap<l_meta_meta_call>);
|
||||
setfield(L, "__call");
|
||||
setmetatable(L);
|
||||
|
||||
pushcfunction(L, lua::wrap<l_canvas_decode>);
|
||||
setfield(L, "decode");
|
||||
return 1;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue