Add initial Timer to repo

Bradley 2 years ago
parent aa5889fb12
commit 3ff653d33a
  1. 46
      Vision/Timer/Timer.lua

@ -0,0 +1,46 @@
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
Loading…
Cancel
Save