refactor(addKeybind): move RegisterCommand to top

This commit is contained in:
Linden
2022-10-25 02:58:39 +11:00
parent 7c566719ad
commit 541e708970

View File

@@ -22,10 +22,7 @@ local IsPauseMenuActive = IsPauseMenuActive
---@param data KeybindProps ---@param data KeybindProps
---@return CKeybind ---@return CKeybind
function lib.addKeybind(data) function lib.addKeybind(data)
data.defaultKey = data.defaultKey or '' if not data.defaultKey then data.defaultKey = '' end
data.currentKey = GetControlInstructionalButton(0, joaat('+' .. data.name) | 0x80000000, true):sub(3)
data.disabled = data.disabled or false
data.disable = disableKeybind
RegisterCommand('+' .. data.name, function() RegisterCommand('+' .. data.name, function()
if not data.onPressed or data.disabled or IsPauseMenuActive() then return end if not data.onPressed or data.disabled or IsPauseMenuActive() then return end
@@ -44,6 +41,9 @@ function lib.addKeybind(data)
TriggerEvent('chat:removeSuggestion', ('/-%s'):format(data.name)) TriggerEvent('chat:removeSuggestion', ('/-%s'):format(data.name))
end) end)
data.currentKey = GetControlInstructionalButton(0, joaat('+' .. data.name) | 0x80000000, true):sub(3)
data.disabled = data.disabled or false
data.disable = disableKeybind
keybinds[data.name] = data keybinds[data.name] = data
---@cast data -KeybindProps ---@cast data -KeybindProps
return data return data