41 lines
1.0 KiB
Lua
41 lines
1.0 KiB
Lua
-- 猫猫虫的 LuaEngine 工具模块:Keypad
|
||
-- @version: 1.0.0
|
||
|
||
local Keypad = {}
|
||
|
||
--- 带计时器的按键触发操作(注:暂不支持组合键)
|
||
---@param keypadID number|string
|
||
---@param chrono number
|
||
---@param func fun()
|
||
---@param xbox boolean|nil
|
||
function Keypad.UseChronoscope(keypadID, chrono, func, xbox)
|
||
if keypadID == nil or chrono == nil or func == nil then
|
||
return
|
||
end
|
||
if chrono < 0 then
|
||
return
|
||
end
|
||
if xbox ~= true and xbox ~= false then
|
||
xbox = nil
|
||
end
|
||
|
||
-- TODO: 暂不支持组合键
|
||
if type(keypadID) == "table" then
|
||
return
|
||
end
|
||
|
||
local keypadIDStr = keypadID
|
||
if type(keypadID) == "number" then
|
||
keypadIDStr = tostring(keypadID)
|
||
end
|
||
local keypadShortcut = "keypad_keyCD_"..keypadIDStr
|
||
|
||
if engine.keypad(keypadID, xbox) and (CheckChronoscope(keypadShortcut) or
|
||
not CheckPresenceChronoscope(keypadShortcut)) then
|
||
|
||
AddChronoscope(chrono, keypadShortcut)
|
||
func()
|
||
end
|
||
end
|
||
|
||
return Keypad |