EigeenLoader/utils/Speed.lua

80 lines
1.5 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- 猫猫虫的 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