An open-source, self-hosted replacement for wow.vision. Can be hosted by users or bot creators. Users should utilize the Client branch for whichever unlocker they are using. If you are hosting an OpenVision server, utilize the Server branch.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
983 B

local Tinkr, Vision = ...
local Timer = {
start_events = {},
reset_events = {},
time = 0,
label = nil
}
Timer.__index = Timer
-- Constructor
---@param label String
---@param start Table
---@param reset Table
---@return Timer
function Timer:New(label, start, reset)
local self = setmetatable({}, Timer)
self.start_events = start
self.reset_events = reset
self.time = 0
self.label = label
for _, event in pairs(self.start_events) do
Vision.EventManager:RegisterWoWEvent(event, function()
self.time = GetTime()
end)
end
for _, event in pairs(self.reset_events) do
Vision.EventManager:RegisterWoWEvent(event, function()
self.time = 0
end)
end
return self
end
-- Start Timer
---@return number
function Timer:GetTime()
if self.time == 0 then
return 0
else
return GetTime() - self.time
end
end
return Timer