1.0.2
This commit is contained in:
41
utils/Keypad.lua
Normal file
41
utils/Keypad.lua
Normal file
@@ -0,0 +1,41 @@
|
||||
-- 猫猫虫的 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
|
||||
79
utils/Speed.lua
Normal file
79
utils/Speed.lua
Normal file
@@ -0,0 +1,79 @@
|
||||
-- 猫猫虫的 LuaEngine 工具模块:Speed
|
||||
-- @version: 1.0.0
|
||||
|
||||
local Speed = {
|
||||
lock = nil,
|
||||
instance = nil
|
||||
}
|
||||
Speed.__index = Speed
|
||||
|
||||
function Speed:new(playerData)
|
||||
if self.instance ~= nil then
|
||||
self.instance.playerData = playerData
|
||||
return self.instance
|
||||
end
|
||||
|
||||
local instance = setmetatable({
|
||||
playerData = playerData
|
||||
}, Speed)
|
||||
self.instance = instance
|
||||
return self.instance
|
||||
end
|
||||
|
||||
function Speed:setSpeed(speed)
|
||||
self.playerData.Frame.frameSpeedMultiplies = speed
|
||||
end
|
||||
|
||||
function Speed:resetSpeed()
|
||||
self.playerData.Frame.frameSpeedMultiplies = 1
|
||||
end
|
||||
|
||||
function Speed:withSpeed(speed, func)
|
||||
if speed == nil or func == nil then
|
||||
return
|
||||
end
|
||||
|
||||
self:setSpeed(speed)
|
||||
func()
|
||||
self:resetSpeed()
|
||||
end
|
||||
|
||||
function Speed:checkAndReleaseLock(lockID)
|
||||
if self.lock == nil then
|
||||
return true
|
||||
end
|
||||
if self.lock == lockID then
|
||||
self.lock = nil
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function Speed:checkAndSetupLock(lockID)
|
||||
if self.lock == nil then
|
||||
self.lock = lockID
|
||||
return true
|
||||
end
|
||||
if self.lock == lockID then
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function Speed:setSpeedMutex(speed, lockID)
|
||||
if self:checkAndSetupLock(lockID) then
|
||||
self:setSpeed(speed)
|
||||
end
|
||||
end
|
||||
|
||||
function Speed:resetSpeedMutex(lockID)
|
||||
if self:checkAndReleaseLock(lockID) then
|
||||
self:resetSpeed()
|
||||
end
|
||||
end
|
||||
|
||||
function Speed:forceReleaseLock()
|
||||
self.lock = nil
|
||||
end
|
||||
|
||||
return Speed
|
||||
Reference in New Issue
Block a user