mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Expose analog joystick input to the Lua API (#14348)
This commit is contained in:
parent
6569fdd4d1
commit
22ef4c8be1
13 changed files with 127 additions and 83 deletions
|
@ -260,12 +260,13 @@ int LuaLocalPlayer::l_get_control(lua_State *L)
|
|||
set("zoom", c.zoom);
|
||||
set("dig", c.dig);
|
||||
set("place", c.place);
|
||||
// Player movement in polar coordinates and non-binary speed
|
||||
lua_pushnumber(L, c.movement_speed);
|
||||
lua_setfield(L, -2, "movement_speed");
|
||||
lua_pushnumber(L, c.movement_direction);
|
||||
lua_setfield(L, -2, "movement_direction");
|
||||
// Provide direction keys to ensure compatibility
|
||||
|
||||
v2f movement = c.getMovement();
|
||||
lua_pushnumber(L, movement.X);
|
||||
lua_setfield(L, -2, "movement_x");
|
||||
lua_pushnumber(L, movement.Y);
|
||||
lua_setfield(L, -2, "movement_y");
|
||||
|
||||
set("up", c.direction_keys & (1 << 0));
|
||||
set("down", c.direction_keys & (1 << 1));
|
||||
set("left", c.direction_keys & (1 << 2));
|
||||
|
|
|
@ -1622,6 +1622,13 @@ int ObjectRef::l_get_player_control(lua_State *L)
|
|||
lua_setfield(L, -2, "dig");
|
||||
lua_pushboolean(L, control.place);
|
||||
lua_setfield(L, -2, "place");
|
||||
|
||||
v2f movement = control.getMovement();
|
||||
lua_pushnumber(L, movement.X);
|
||||
lua_setfield(L, -2, "movement_x");
|
||||
lua_pushnumber(L, movement.Y);
|
||||
lua_setfield(L, -2, "movement_y");
|
||||
|
||||
// Legacy fields to ensure mod compatibility
|
||||
lua_pushboolean(L, control.dig);
|
||||
lua_setfield(L, -2, "LMB");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue