1.0.6 支持模块热重载

This commit is contained in:
2023-12-28 22:42:34 +08:00
parent a8a29f6430
commit 8348dd2a36
4 changed files with 59 additions and 18 deletions

View File

@@ -1,15 +1,14 @@
-- 猫猫虫的 LuaEngine 工具模块Keypad
-- @version: 1.0.0
-- @version: 1.0.1
local Keypad = {}
--- 带计时器的按键触发操作(注:暂不支持组合键)
---@param keypadID number|string
--- 带计时器的按键触发操作
---@param keypadID number|string|table
---@param chrono number
---@param func fun()
---@param handler fun()
---@param xbox boolean|nil
function Keypad.UseChronoscope(keypadID, chrono, func, xbox)
if keypadID == nil or chrono == nil or func == nil then
function Keypad.UseChronoscope(keypadID, chrono, handler, xbox)
if not keypadID or not chrono or not handler then
return
end
if chrono < 0 then
@@ -19,23 +18,20 @@ function Keypad.UseChronoscope(keypadID, chrono, func, xbox)
xbox = nil
end
-- TODO: 暂不支持组合键
if type(keypadID) == "table" then
return
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
local keypadShortcut = "keypad_keyCD_" .. keypadIDStr
if engine.keypad(keypadID, xbox) and (CheckChronoscope(keypadShortcut) or
not CheckPresenceChronoscope(keypadShortcut)) then
if engine.keypad(keypadID, xbox) and
(CheckChronoscope(keypadShortcut) or not CheckPresenceChronoscope(keypadShortcut)) then
AddChronoscope(chrono, keypadShortcut)
func()
handler()
end
end
return Keypad
return Keypad

12
utils/Utils.lua Normal file
View File

@@ -0,0 +1,12 @@
local Utils = {}
function Utils:IsIn(table, element)
for key, value in pairs(table) do
if element == value then
return true
end
end
return false
end
return Utils