1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Add shorthand form for touch_interaction

This commit is contained in:
Gregor Parzefall 2024-02-04 19:13:29 +01:00 committed by grorp
parent 8935f2af3c
commit e79587c934
2 changed files with 24 additions and 17 deletions

View file

@ -156,17 +156,24 @@ void read_item_definition(lua_State* L, int index,
getboolfield(L, index, "wallmounted_rotate_vertical", def.wallmounted_rotate_vertical);
TouchInteraction &inter = def.touch_interaction;
lua_getfield(L, index, "touch_interaction");
if (!lua_isnil(L, -1)) {
luaL_checktype(L, -1, LUA_TTABLE);
TouchInteraction &inter = def.touch_interaction;
if (lua_istable(L, -1)) {
inter.pointed_nothing = (TouchInteractionMode)getenumfield(L, -1, "pointed_nothing",
es_TouchInteractionMode, inter.pointed_nothing);
inter.pointed_node = (TouchInteractionMode)getenumfield(L, -1, "pointed_node",
es_TouchInteractionMode, inter.pointed_node);
inter.pointed_object = (TouchInteractionMode)getenumfield(L, -1, "pointed_object",
es_TouchInteractionMode, inter.pointed_object);
} else if (lua_isstring(L, -1)) {
int value;
if (string_to_enum(es_TouchInteractionMode, value, lua_tostring(L, -1))) {
inter.pointed_nothing = (TouchInteractionMode)value;
inter.pointed_node = (TouchInteractionMode)value;
inter.pointed_object = (TouchInteractionMode)value;
}
} else if (!lua_isnil(L, -1)) {
throw LuaError("invalid type for 'touch_interaction'");
}
lua_pop(L, 1);
}