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

Touchscreen: Allow mods to swap the meaning of short and long taps (punch with single tap) (#14087)

This works through a new field "touch_interaction" in item definitions.
The two most important use cases are:
 - Punching players/entities with short tap instead of long tap (enabled by default)
 - Making items usable that require holding the place button (e.g. bows and shields in MC-like games)
This commit is contained in:
grorp 2024-01-21 17:44:08 +01:00 committed by GitHub
parent 8cbd629010
commit 404a063fdf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 288 additions and 108 deletions

View file

@ -138,6 +138,20 @@ void read_item_definition(lua_State* L, int index,
def.place_param2 = rangelim(place_param2, 0, U8_MAX);
getboolfield(L, index, "wallmounted_rotate_vertical", def.wallmounted_rotate_vertical);
lua_getfield(L, index, "touch_interaction");
if (!lua_isnil(L, -1)) {
luaL_checktype(L, -1, LUA_TTABLE);
TouchInteraction &inter = def.touch_interaction;
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);
}
lua_pop(L, 1);
}
/******************************************************************************/
@ -199,6 +213,16 @@ void push_item_definition_full(lua_State *L, const ItemDefinition &i)
lua_setfield(L, -2, "node_placement_prediction");
lua_pushboolean(L, i.wallmounted_rotate_vertical);
lua_setfield(L, -2, "wallmounted_rotate_vertical");
lua_createtable(L, 0, 3);
const TouchInteraction &inter = i.touch_interaction;
lua_pushstring(L, es_TouchInteractionMode[inter.pointed_nothing].str);
lua_setfield(L, -2,"pointed_nothing");
lua_pushstring(L, es_TouchInteractionMode[inter.pointed_node].str);
lua_setfield(L, -2,"pointed_node");
lua_pushstring(L, es_TouchInteractionMode[inter.pointed_object].str);
lua_setfield(L, -2,"pointed_object");
lua_setfield(L, -2, "touch_interaction");
}
/******************************************************************************/