mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-04 18:41:51 +00:00
add missing inventory function
This commit is contained in:
parent
46b4aab6dc
commit
8e719eace6
4 changed files with 46 additions and 3 deletions
|
|
@ -162,7 +162,19 @@ inventory.get_all_data(
|
|||
invid: int,
|
||||
-- slot index
|
||||
slot: int,
|
||||
) -> table
|
||||
) -> table | nil
|
||||
|
||||
-- Sets the values of all local item properties.
|
||||
inventory.set_all_data(
|
||||
-- inventory id
|
||||
invid: int,
|
||||
-- slot index
|
||||
slot: int,
|
||||
-- property:value table
|
||||
fields: table,
|
||||
-- clear other property values
|
||||
[optional] clear: boolean = false
|
||||
)
|
||||
```
|
||||
|
||||
```lua
|
||||
|
|
|
|||
|
|
@ -170,7 +170,19 @@ inventory.get_all_data(
|
|||
invid: int,
|
||||
-- индекс слота
|
||||
slot: int,
|
||||
) -> table
|
||||
) -> table | nil
|
||||
|
||||
-- Устанавливает значения локальных cвойств предмета.
|
||||
inventory.set_all_data(
|
||||
-- id инвентаря
|
||||
invid: int,
|
||||
-- индекс слота
|
||||
slot: int,
|
||||
-- таблица cвойство:значение
|
||||
fields: table,
|
||||
-- удалить остальные значения свойств
|
||||
[опционально] clear: boolean = false
|
||||
)
|
||||
```
|
||||
|
||||
```lua
|
||||
|
|
@ -222,4 +234,4 @@ inventory.use(
|
|||
-- индекс слота
|
||||
slot: int
|
||||
)
|
||||
```
|
||||
```
|
||||
|
|
|
|||
|
|
@ -55,6 +55,16 @@ public:
|
|||
return fields;
|
||||
}
|
||||
|
||||
void setFields(dv::value&& table, bool clear) {
|
||||
if (clear) {
|
||||
fields = std::move(table);
|
||||
return;
|
||||
}
|
||||
for (auto&& [key, value] : table.asObject()) {
|
||||
fields[std::move(key)] = std::move(value);
|
||||
}
|
||||
}
|
||||
|
||||
bool hasFields() const {
|
||||
return fields != nullptr;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -237,6 +237,14 @@ static int l_get_all_data(lua::State* L, ItemStack& stack) {
|
|||
return lua::pushvalue(L, stack.getFields());
|
||||
}
|
||||
|
||||
static int l_set_all_data(lua::State* L, ItemStack& stack) {
|
||||
if (!lua::istable(L, 3)) {
|
||||
throw std::runtime_error("table expected as argument 1");
|
||||
}
|
||||
stack.setFields(lua::tovalue(L, 3), lua::toboolean(L, 4));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_has_data(lua::State* L, ItemStack& stack) {
|
||||
auto key = lua::tostring(L, 3);
|
||||
if (key == nullptr) {
|
||||
|
|
@ -267,6 +275,7 @@ const luaL_Reg inventorylib[] = {
|
|||
{"get_data", lua::wrap<wrap_slot<l_get_data>>},
|
||||
{"set_data", lua::wrap<wrap_slot<l_set_data>>},
|
||||
{"get_all_data", lua::wrap<wrap_slot<l_get_all_data>>},
|
||||
{"set_all_data", lua::wrap<wrap_slot<l_set_all_data>>},
|
||||
{"has_data", lua::wrap<wrap_slot<l_has_data>>},
|
||||
{"create", lua::wrap<l_create>},
|
||||
{"remove", lua::wrap<l_remove>},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue