38 lines
991 B
Lua
38 lines
991 B
Lua
-- 猫猫虫的 LuaEngine 工具模块:Keypad
|
||
-- @version: 1.0.1
|
||
local Keypad = {}
|
||
|
||
--- 带计时器的按键触发操作
|
||
---@param keypadID number|string|table
|
||
---@param chrono number
|
||
---@param handler fun()
|
||
---@param xbox boolean|nil
|
||
function Keypad.UseChronoscope(keypadID, chrono, handler, xbox)
|
||
if not keypadID or not chrono or not handler then
|
||
return
|
||
end
|
||
if chrono < 0 then
|
||
return
|
||
end
|
||
if type(xbox) ~= "boolean" then
|
||
xbox = nil
|
||
end
|
||
|
||
local keypadIDStr = keypadID
|
||
if type(keypadID) == "number" then
|
||
keypadIDStr = tostring(keypadID)
|
||
elseif type(keypadID) == "table" then
|
||
keypadIDStr = table.concat(keypadID, ",")
|
||
end
|
||
local keypadShortcut = "keypad_keyCD_" .. keypadIDStr
|
||
|
||
if engine.keypad(keypadID, xbox) and
|
||
(CheckChronoscope(keypadShortcut) or not CheckPresenceChronoscope(keypadShortcut)) then
|
||
|
||
AddChronoscope(chrono, keypadShortcut)
|
||
handler()
|
||
end
|
||
end
|
||
|
||
return Keypad
|