Keybindings: move input_service:get(special_key) calls out of the loop.
The function is called whenever a key is pressed, therefore we only need to check for ctrl, alt and shift once. Each of them was called twice, nested inside two loops. The same thing can be found in Custom Menus, the same block of three lines and six conditionals. Good target for refactoring.
This commit is contained in:
parent
d9f3dd6c55
commit
a1124e3519
2 changed files with 14 additions and 6 deletions
|
@ -127,13 +127,17 @@ vmf.check_pressed_keybinds = function()
|
||||||
end
|
end
|
||||||
|
|
||||||
local key_has_active_keybind = false
|
local key_has_active_keybind = false
|
||||||
|
local input_ctrl = input_service:get("ctrl")
|
||||||
|
local input_shift = input_service:get("shift")
|
||||||
|
local input_alt = input_service:get("alt")
|
||||||
|
|
||||||
for key, key_bindings in pairs(_optimized_keybinds) do
|
for key, key_bindings in pairs(_optimized_keybinds) do
|
||||||
if input_service:get(key) then
|
if input_service:get(key) then
|
||||||
|
|
||||||
for _, binding_info in ipairs(key_bindings) do
|
for _, binding_info in ipairs(key_bindings) do
|
||||||
if (not binding_info[3] and not input_service:get("ctrl") or binding_info[3] and input_service:get("ctrl")) and
|
if (not binding_info[3] and not input_ctrl or binding_info[3] and input_ctrl) and
|
||||||
(not binding_info[4] and not input_service:get("alt") or binding_info[4] and input_service:get("alt")) and
|
(not binding_info[4] and not input_alt or binding_info[4] and input_alt) and
|
||||||
(not binding_info[5] and not input_service:get("shift") or binding_info[5] and input_service:get("shift")) then
|
(not binding_info[5] and not input_shift or binding_info[5] and input_shift) then
|
||||||
|
|
||||||
local mod = get_mod(binding_info[1])
|
local mod = get_mod(binding_info[1])
|
||||||
|
|
||||||
|
|
|
@ -138,12 +138,16 @@ vmf.check_custom_menus_close_keybinds = function()
|
||||||
opening_keybind_is_pressed = false
|
opening_keybind_is_pressed = false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local input_ctrl = input_service:get("ctrl")
|
||||||
|
local input_shift = input_service:get("shift")
|
||||||
|
local input_alt = input_service:get("alt")
|
||||||
|
|
||||||
local close_menu = false
|
local close_menu = false
|
||||||
if not opening_keybind_is_pressed then
|
if not opening_keybind_is_pressed then
|
||||||
if input_service:get(close_keybind[1]) and
|
if input_service:get(close_keybind[1]) and
|
||||||
(not close_keybind[2] and not input_service:get("ctrl") or close_keybind[2] and input_service:get("ctrl")) and
|
(not close_keybind[2] and not input_ctrl or close_keybind[2] and input_ctrl) and
|
||||||
(not close_keybind[3] and not input_service:get("alt") or close_keybind[3] and input_service:get("alt")) and
|
(not close_keybind[3] and not input_alt or close_keybind[3] and input_alt) and
|
||||||
(not close_keybind[4] and not input_service:get("shift") or close_keybind[4] and input_service:get("shift")) then
|
(not close_keybind[4] and not input_shift or close_keybind[4] and input_shift) then
|
||||||
|
|
||||||
close_menu = not ingame_ui.views[ingame_ui.current_view]:input_service():is_blocked()
|
close_menu = not ingame_ui.views[ingame_ui.current_view]:input_service():is_blocked()
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue