added item.description() to itemlib, and update docs
This commit is contained in:
parent
b4d41a59e4
commit
59d706323a
@ -98,6 +98,13 @@ inventory.set_all_data(...)
|
||||
```
|
||||
for moving is inefficient, use inventory.move or inventory.move_range.
|
||||
```lua
|
||||
-- Get item caption
|
||||
inventory.get_caption(
|
||||
-- id of inventory
|
||||
invid: int,
|
||||
-- slot id
|
||||
slot: int
|
||||
)
|
||||
-- Set item caption
|
||||
inventory.set_caption(
|
||||
-- id of inventory
|
||||
@ -107,6 +114,13 @@ inventory.set_caption(
|
||||
-- Item Caption
|
||||
caption: string
|
||||
)
|
||||
-- Get item description
|
||||
inventory.get_description(
|
||||
-- id of inventory
|
||||
invid: int,
|
||||
-- slot id
|
||||
slot: int
|
||||
)
|
||||
-- Set item description
|
||||
inventory.set_description(
|
||||
-- id of inventory
|
||||
|
||||
@ -95,6 +95,13 @@ inventory.set_all_data(...)
|
||||
```
|
||||
для перемещения вляется неэффективным, используйте inventory.move или inventory.move_range.
|
||||
```lua
|
||||
-- Получает имя предмета в слоте
|
||||
inventory.get_caption(
|
||||
-- id инвентаря
|
||||
invid: int,
|
||||
-- индекс слота
|
||||
slot: int
|
||||
)
|
||||
-- Задает имя предмету в слоте
|
||||
inventory.set_caption(
|
||||
-- id инвентаря
|
||||
@ -104,6 +111,13 @@ inventory.set_caption(
|
||||
-- Имя предмета
|
||||
caption: string
|
||||
)
|
||||
-- Получает описание предмета в слоте
|
||||
inventory.get_description(
|
||||
-- id инвентаря
|
||||
invid: int,
|
||||
-- индекс слота
|
||||
slot: int
|
||||
)
|
||||
-- Задает описание предмету в слоте
|
||||
inventory.set_description(
|
||||
-- id инвентаря
|
||||
|
||||
@ -10,6 +10,9 @@ item.index(name: str) -> int
|
||||
-- Возвращает название предмета, отображаемое в интерфейсе.
|
||||
item.caption(itemid: int) -> str
|
||||
|
||||
-- Возвращает описание предмета, отображаемое в интерфейсе.
|
||||
item.description(itemid: int) -> str
|
||||
|
||||
-- Возвращает максимальный размер стопки для предмета.
|
||||
item.stack_size(itemid: int) -> int
|
||||
|
||||
|
||||
@ -128,6 +128,14 @@ function inventory.decrement(invid, slot, count)
|
||||
end
|
||||
end
|
||||
|
||||
function inventory.get_caption(invid, slot)
|
||||
local item_id, count = inventory.get(invid, slot)
|
||||
local caption = inventory.get_data(invid, slot, "caption")
|
||||
if not caption then return item.caption(item_id) end
|
||||
|
||||
return caption
|
||||
end
|
||||
|
||||
function inventory.set_caption(invid, slot, caption)
|
||||
local itemid, itemcount = inventory.get(invid, slot)
|
||||
if itemid == 0 then
|
||||
@ -139,6 +147,14 @@ function inventory.set_caption(invid, slot, caption)
|
||||
inventory.set_data(invid, slot, "caption", caption)
|
||||
end
|
||||
|
||||
function inventory.get_description(invid, slot)
|
||||
local item_id, count = inventory.get(invid, slot)
|
||||
local description = inventory.get_data(invid, slot, "description")
|
||||
if not description then return item.description(item_id) end
|
||||
|
||||
return description
|
||||
end
|
||||
|
||||
function inventory.set_description(invid, slot, description)
|
||||
local itemid, itemcount = inventory.get(invid, slot)
|
||||
if itemid == 0 then
|
||||
|
||||
@ -57,6 +57,13 @@ static int l_caption(lua::State* L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_description(lua::State* L) {
|
||||
if (auto def = get_item_def(L, 1)) {
|
||||
return lua::pushstring(L, def->description);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_placing_block(lua::State* L) {
|
||||
if (auto def = get_item_def(L, 1)) {
|
||||
return lua::pushinteger(L, def->rt.placingBlock);
|
||||
@ -108,6 +115,7 @@ const luaL_Reg itemlib[] = {
|
||||
{"defs_count", lua::wrap<l_defs_count>},
|
||||
{"icon", lua::wrap<l_get_icon>},
|
||||
{"caption", lua::wrap<l_caption>},
|
||||
{"description", lua::wrap<l_description>},
|
||||
{"placing_block", lua::wrap<l_placing_block>},
|
||||
{"model_name", lua::wrap<l_model_name>},
|
||||
{"emission", lua::wrap<l_emission>},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user