Skip to content

Commit e7e065f

Browse files
appgurueuraistlin
andauthoredJun 13, 2020
Exposing the zoom key to Lua API (#9903)
Co-authored-by: Raul Ferriz <raul.ferriz@gmail.com>
1 parent 2424dfe commit e7e065f

File tree

4 files changed

+10
-5
lines changed

4 files changed

+10
-5
lines changed
 

Diff for: ‎doc/lua_api.txt

+4-3
Original file line numberDiff line numberDiff line change
@@ -6106,13 +6106,14 @@ object you are working with still exists.
61066106
* `get_formspec_prepend(formspec)`: returns a formspec string.
61076107
* `get_player_control()`: returns table with player pressed keys
61086108
* The table consists of fields with boolean value representing the pressed
6109-
keys, the fields are jump, right, left, LMB, RMB, sneak, aux1, down, up.
6109+
keys, the fields are jump, right, left, LMB, RMB, sneak, aux1, down, up, zoom.
61106110
* example: `{jump=false, right=true, left=false, LMB=false, RMB=false,
6111-
sneak=true, aux1=false, down=false, up=false}`
6111+
sneak=true, aux1=false, down=false, up=false, zoom=false}`
6112+
* The `zoom` field is available since 5.3
61126113
* `get_player_control_bits()`: returns integer with bit packed player pressed
61136114
keys.
61146115
* bit nr/meaning: 0/up, 1/down, 2/left, 3/right, 4/jump, 5/aux1, 6/sneak,
6115-
7/LMB, 8/RMB
6116+
7/LMB, 8/RMB, 9/zoom (zoom available since 5.3)
61166117
* `set_physics_override(override_table)`
61176118
* `override_table` is a table with the following fields:
61186119
* `speed`: multiplier to default walking speed value (default: `1`)

Diff for: ‎src/client/game.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -2490,7 +2490,7 @@ void Game::updatePlayerControl(const CameraOrientation &cam)
24902490
input->joystick.getAxisWithoutDead(JA_FORWARD_MOVE)
24912491
);
24922492

2493-
u32 keypress_bits =
2493+
u32 keypress_bits = (
24942494
( (u32)(isKeyDown(KeyType::FORWARD) & 0x1) << 0) |
24952495
( (u32)(isKeyDown(KeyType::BACKWARD) & 0x1) << 1) |
24962496
( (u32)(isKeyDown(KeyType::LEFT) & 0x1) << 2) |
@@ -2499,7 +2499,8 @@ void Game::updatePlayerControl(const CameraOrientation &cam)
24992499
( (u32)(isKeyDown(KeyType::SPECIAL1) & 0x1) << 5) |
25002500
( (u32)(isKeyDown(KeyType::SNEAK) & 0x1) << 6) |
25012501
( (u32)(input->getLeftState() & 0x1) << 7) |
2502-
( (u32)(input->getRightState() & 0x1) << 8
2502+
( (u32)(input->getRightState() & 0x1) << 8) |
2503+
( (u32)(isKeyDown(KeyType::ZOOM) & 0x1) << 9)
25032504
);
25042505

25052506
#ifdef ANDROID

Diff for: ‎src/network/serverpackethandler.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,7 @@ void Server::process_PlayerPos(RemotePlayer *player, PlayerSAO *playersao,
501501
player->control.sneak = (keyPressed & 64);
502502
player->control.LMB = (keyPressed & 128);
503503
player->control.RMB = (keyPressed & 256);
504+
player->control.zoom = (keyPressed & 512);
504505

505506
if (playersao->checkMovementCheat()) {
506507
// Call callbacks

Diff for: ‎src/script/lua_api/l_object.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -1459,6 +1459,8 @@ int ObjectRef::l_get_player_control(lua_State *L)
14591459
lua_setfield(L, -2, "LMB");
14601460
lua_pushboolean(L, control.RMB);
14611461
lua_setfield(L, -2, "RMB");
1462+
lua_pushboolean(L, control.zoom);
1463+
lua_setfield(L, -2, "zoom");
14621464
return 1;
14631465
}
14641466

0 commit comments

Comments
 (0)
Please sign in to comment.