add item.get_placing_block

This commit is contained in:
MihailRis 2024-10-28 13:07:10 +03:00
parent db1387d977
commit 751f8a7544
3 changed files with 27 additions and 13 deletions

View File

@ -18,4 +18,7 @@ item.defs_count() -> int
-- Returns item icon name to use in 'src' property of an image element
item.icon(itemid: int) -> str
-- Returns the integer id 'placing-block' or 0
item.get_placing_block(itemid: int) -> int
```

View File

@ -8,7 +8,7 @@ item.name(itemid: int) -> str
item.index(name: str) -> int
-- Возвращает название предмета, отображаемое в интерфейсе.
item.caption(blockid: int) -> str
item.caption(itemid: int) -> str
-- Возвращает максимальный размер стопки для предмета.
item.stack_size(itemid: int) -> int
@ -18,6 +18,9 @@ item.defs_count() -> int
-- Возвращает имя иконки предмета для использования в свойстве 'src' элемента image
item.icon(itemid: int) -> str
-- Возвращает числовой id блока, назначенного как 'placing-block' или 0
item.get_placing_block(itemid: int) -> int
```

View File

@ -10,30 +10,30 @@ static const ItemDef* get_item_def(lua::State* L, int idx) {
return indices->items.get(id);
}
static int l_item_name(lua::State* L) {
static int l_name(lua::State* L) {
if (auto def = get_item_def(L, 1)) {
return lua::pushstring(L, def->name);
}
return 0;
}
static int l_item_index(lua::State* L) {
static int l_index(lua::State* L) {
auto name = lua::require_string(L, 1);
return lua::pushinteger(L, content->items.require(name).rt.id);
}
static int l_item_stack_size(lua::State* L) {
static int l_stack_size(lua::State* L) {
if (auto def = get_item_def(L, 1)) {
return lua::pushinteger(L, def->stackSize);
}
return 0;
}
static int l_item_defs_count(lua::State* L) {
static int l_defs_count(lua::State* L) {
return lua::pushinteger(L, indices->items.count());
}
static int l_item_get_icon(lua::State* L) {
static int l_get_icon(lua::State* L) {
if (auto def = get_item_def(L, 1)) {
switch (def->iconType) {
case ItemIconType::NONE:
@ -47,18 +47,26 @@ static int l_item_get_icon(lua::State* L) {
return 0;
}
static int l_item_caption(lua::State* L) {
static int l_caption(lua::State* L) {
if (auto def = get_item_def(L, 1)) {
return lua::pushstring(L, def->caption);
}
return 0;
}
static int l_get_placing_block(lua::State* L) {
if (auto def = get_item_def(L, 1)) {
return lua::pushinteger(L, def->rt.placingBlock);
}
return 0;
}
const luaL_Reg itemlib[] = {
{"index", lua::wrap<l_item_index>},
{"name", lua::wrap<l_item_name>},
{"stack_size", lua::wrap<l_item_stack_size>},
{"defs_count", lua::wrap<l_item_defs_count>},
{"icon", lua::wrap<l_item_get_icon>},
{"caption", lua::wrap<l_item_caption>},
{"index", lua::wrap<l_index>},
{"name", lua::wrap<l_name>},
{"stack_size", lua::wrap<l_stack_size>},
{"defs_count", lua::wrap<l_defs_count>},
{"icon", lua::wrap<l_get_icon>},
{"caption", lua::wrap<l_caption>},
{"get_placing_block", lua::wrap<l_get_placing_block>},
{NULL, NULL}};