Merge pull request #355 from opchik98/main

Feature #152 and potential fix #320
This commit is contained in:
MihailRis
2024-11-10 21:36:17 +03:00
committed by GitHub
11 changed files with 117 additions and 13 deletions
+21
View File
@@ -36,6 +36,26 @@ static int l_close_inventory(lua::State*) {
return 0;
}
static int l_open(lua::State* L) {
auto invid = lua::tointeger(L, 1);
auto layoutid = lua::require_string(L, 2);
bool playerInventory = !lua::toboolean(L, 3);
auto assets = engine->getAssets();
auto layout = assets->get<UiDocument>(layoutid);
if (layout == nullptr) {
throw std::runtime_error("there is no ui layout " + util::quote(layoutid));
}
hud->openInventory(
layout,
level->inventories->get(invid),
playerInventory
);
return 0;
}
static int l_open_block(lua::State* L) {
auto x = lua::tointeger(L, 1);
auto y = lua::tointeger(L, 2);
@@ -154,6 +174,7 @@ static int l_set_debug_cheats(lua::State* L) {
const luaL_Reg hudlib[] = {
{"open_inventory", lua::wrap<l_open_inventory>},
{"close_inventory", lua::wrap<l_close_inventory>},
{"open", lua::wrap<l_open>},
{"open_block", lua::wrap<l_open_block>},
{"open_permanent", lua::wrap<l_open_permanent>},
{"show_overlay", lua::wrap<l_show_overlay>},
@@ -109,6 +109,26 @@ static int l_inventory_unbind_block(lua::State* L) {
return 0;
}
static int l_inventory_create(lua::State* L) {
auto invsize = lua::tointeger(L, 1);
auto inv = level->inventories->create(invsize);
if (inv == nullptr) {
return lua::pushinteger(L, 0);
}
return lua::pushinteger(L, inv->getId());
}
static int l_inventory_remove(lua::State* L) {
auto invid = lua::tointeger(L, 1);
auto inv = get_inventory(invid);
if (inv == nullptr) {
return 0;
}
level->inventories->remove(invid);
return 0;
}
static int l_inventory_clone(lua::State* L) {
auto id = lua::tointeger(L, 1);
auto clone = level->inventories->clone(id);
@@ -145,5 +165,7 @@ const luaL_Reg inventorylib[] = {
{"get_block", lua::wrap<l_inventory_get_block>},
{"bind_block", lua::wrap<l_inventory_bind_block>},
{"unbind_block", lua::wrap<l_inventory_unbind_block>},
{"create", lua::wrap<l_inventory_create>},
{"remove", lua::wrap<l_inventory_remove>},
{"clone", lua::wrap<l_inventory_clone>},
{NULL, NULL}};