Exposing the zoom key to Lua API (#9903)
authorLars Müller <34514239+appgurueu@users.noreply.github.com>
Sat, 13 Jun 2020 20:46:20 +0000 (22:46 +0200)
committerGitHub <noreply@github.com>
Sat, 13 Jun 2020 20:46:20 +0000 (22:46 +0200)
Co-authored-by: Raul Ferriz <raul.ferriz@gmail.com>
doc/lua_api.txt
src/client/game.cpp
src/network/serverpackethandler.cpp
src/script/lua_api/l_object.cpp

index cb968958ff9d2209c507561680061e57036540f9..07e9698e8c1100098bdfe6d85271ac59b4a28a6e 100644 (file)
@@ -6106,13 +6106,14 @@ object you are working with still exists.
 * `get_formspec_prepend(formspec)`: returns a formspec string.
 * `get_player_control()`: returns table with player pressed keys
     * The table consists of fields with boolean value representing the pressed
-      keys, the fields are jump, right, left, LMB, RMB, sneak, aux1, down, up.
+      keys, the fields are jump, right, left, LMB, RMB, sneak, aux1, down, up, zoom.
     * example: `{jump=false, right=true, left=false, LMB=false, RMB=false,
-      sneak=true, aux1=false, down=false, up=false}`
+      sneak=true, aux1=false, down=false, up=false, zoom=false}`
+    * The `zoom` field is available since 5.3
 * `get_player_control_bits()`: returns integer with bit packed player pressed
   keys.
     * bit nr/meaning: 0/up, 1/down, 2/left, 3/right, 4/jump, 5/aux1, 6/sneak,
-      7/LMB, 8/RMB
+      7/LMB, 8/RMB, 9/zoom (zoom available since 5.3)
 * `set_physics_override(override_table)`
     * `override_table` is a table with the following fields:
         * `speed`: multiplier to default walking speed value (default: `1`)
index 139742cecbc6eac7f1d76a9bc7ce5b545dc7c054..069c482caae5a548347271704d1ed91138e4c7b0 100644 (file)
@@ -2490,7 +2490,7 @@ void Game::updatePlayerControl(const CameraOrientation &cam)
                input->joystick.getAxisWithoutDead(JA_FORWARD_MOVE)
        );
 
-       u32 keypress_bits =
+       u32 keypress_bits = (
                        ( (u32)(isKeyDown(KeyType::FORWARD)                       & 0x1) << 0) |
                        ( (u32)(isKeyDown(KeyType::BACKWARD)                      & 0x1) << 1) |
                        ( (u32)(isKeyDown(KeyType::LEFT)                          & 0x1) << 2) |
@@ -2499,7 +2499,8 @@ void Game::updatePlayerControl(const CameraOrientation &cam)
                        ( (u32)(isKeyDown(KeyType::SPECIAL1)                      & 0x1) << 5) |
                        ( (u32)(isKeyDown(KeyType::SNEAK)                         & 0x1) << 6) |
                        ( (u32)(input->getLeftState()                             & 0x1) << 7) |
-                       ( (u32)(input->getRightState()                            & 0x1) << 8
+                       ( (u32)(input->getRightState()                            & 0x1) << 8) |
+                       ( (u32)(isKeyDown(KeyType::ZOOM)                          & 0x1) << 9)
                );
 
 #ifdef ANDROID
index fed3b6f851703d33e6ea89be5d20a3af66ec8c88..b3008bb50c22b31ba3f797a454850da111c00a36 100644 (file)
@@ -501,6 +501,7 @@ void Server::process_PlayerPos(RemotePlayer *player, PlayerSAO *playersao,
        player->control.sneak = (keyPressed & 64);
        player->control.LMB = (keyPressed & 128);
        player->control.RMB = (keyPressed & 256);
+       player->control.zoom = (keyPressed & 512);
 
        if (playersao->checkMovementCheat()) {
                // Call callbacks
index 0a9f3117b3d7a41df71535b3b637d82f6bd66a75..e7394133a728766ba0ae1b642cfc280140480ab2 100644 (file)
@@ -1459,6 +1459,8 @@ int ObjectRef::l_get_player_control(lua_State *L)
        lua_setfield(L, -2, "LMB");
        lua_pushboolean(L, control.RMB);
        lua_setfield(L, -2, "RMB");
+       lua_pushboolean(L, control.zoom);
+       lua_setfield(L, -2, "zoom");
        return 1;
 }