Mercurial > wow > hotcorners
comparison Libs/AceTimer-3.0/AceTimer-3.0.lua @ 20:9ad7f3c634f1 v8.0.1.020
- Updated Libraries.
| author | Tercio |
|---|---|
| date | Fri, 20 Jul 2018 19:13:08 -0300 |
| parents | c31ee4251181 |
| children |
comparison
equal
deleted
inserted
replaced
| 19:817b319cd8ce | 20:9ad7f3c634f1 |
|---|---|
| 13 -- and can be accessed directly, without having to explicitly call AceTimer itself.\\ | 13 -- and can be accessed directly, without having to explicitly call AceTimer itself.\\ |
| 14 -- It is recommended to embed AceTimer, otherwise you'll have to specify a custom `self` on all calls you | 14 -- It is recommended to embed AceTimer, otherwise you'll have to specify a custom `self` on all calls you |
| 15 -- make into AceTimer. | 15 -- make into AceTimer. |
| 16 -- @class file | 16 -- @class file |
| 17 -- @name AceTimer-3.0 | 17 -- @name AceTimer-3.0 |
| 18 -- @release $Id: AceTimer-3.0.lua 1119 2014-10-14 17:23:29Z nevcairiel $ | 18 -- @release $Id: AceTimer-3.0.lua 1170 2018-03-29 17:38:58Z funkydude $ |
| 19 | 19 |
| 20 local MAJOR, MINOR = "AceTimer-3.0", 17 -- Bump minor on changes | 20 local MAJOR, MINOR = "AceTimer-3.0", 17 -- Bump minor on changes |
| 21 local AceTimer, oldminor = LibStub:NewLibrary(MAJOR, MINOR) | 21 local AceTimer, oldminor = LibStub:NewLibrary(MAJOR, MINOR) |
| 22 | 22 |
| 23 if not AceTimer then return end -- No upgrade needed | 23 if not AceTimer then return end -- No upgrade needed |
| 32 local function new(self, loop, func, delay, ...) | 32 local function new(self, loop, func, delay, ...) |
| 33 if delay < 0.01 then | 33 if delay < 0.01 then |
| 34 delay = 0.01 -- Restrict to the lowest time that the C_Timer API allows us | 34 delay = 0.01 -- Restrict to the lowest time that the C_Timer API allows us |
| 35 end | 35 end |
| 36 | 36 |
| 37 local timer = {...} | 37 local timer = { |
| 38 timer.object = self | 38 object = self, |
| 39 timer.func = func | 39 func = func, |
| 40 timer.looping = loop | 40 looping = loop, |
| 41 timer.argsCount = select("#", ...) | 41 argsCount = select("#", ...), |
| 42 timer.delay = delay | 42 delay = delay, |
| 43 timer.ends = GetTime() + delay | 43 ends = GetTime() + delay, |
| 44 ... | |
| 45 } | |
| 44 | 46 |
| 45 activeTimers[timer] = timer | 47 activeTimers[timer] = timer |
| 46 | 48 |
| 47 -- Create new timer closure to wrap the "timer" object | 49 -- Create new timer closure to wrap the "timer" object |
| 48 timer.callback = function() | 50 timer.callback = function() |
| 154 end | 156 end |
| 155 end | 157 end |
| 156 | 158 |
| 157 --- Cancels all timers registered to the current addon object ('self') | 159 --- Cancels all timers registered to the current addon object ('self') |
| 158 function AceTimer:CancelAllTimers() | 160 function AceTimer:CancelAllTimers() |
| 159 for k,v in pairs(activeTimers) do | 161 for k,v in next, activeTimers do |
| 160 if v.object == self then | 162 if v.object == self then |
| 161 AceTimer.CancelTimer(self, k) | 163 AceTimer.CancelTimer(self, k) |
| 162 end | 164 end |
| 163 end | 165 end |
| 164 end | 166 end |
| 185 -- disable old timer logic | 187 -- disable old timer logic |
| 186 AceTimer.frame:SetScript("OnUpdate", nil) | 188 AceTimer.frame:SetScript("OnUpdate", nil) |
| 187 AceTimer.frame:SetScript("OnEvent", nil) | 189 AceTimer.frame:SetScript("OnEvent", nil) |
| 188 AceTimer.frame:UnregisterAllEvents() | 190 AceTimer.frame:UnregisterAllEvents() |
| 189 -- convert timers | 191 -- convert timers |
| 190 for object,timers in pairs(AceTimer.selfs) do | 192 for object,timers in next, AceTimer.selfs do |
| 191 for handle,timer in pairs(timers) do | 193 for handle,timer in next, timers do |
| 192 if type(timer) == "table" and timer.callback then | 194 if type(timer) == "table" and timer.callback then |
| 193 local newTimer | 195 local newTimer |
| 194 if timer.delay then | 196 if timer.delay then |
| 195 newTimer = AceTimer.ScheduleRepeatingTimer(timer.object, timer.callback, timer.delay, timer.arg) | 197 newTimer = AceTimer.ScheduleRepeatingTimer(timer.object, timer.callback, timer.delay, timer.arg) |
| 196 else | 198 else |
| 212 AceTimer.frame = nil | 214 AceTimer.frame = nil |
| 213 local oldTimers = AceTimer.activeTimers | 215 local oldTimers = AceTimer.activeTimers |
| 214 -- Clear old timer table and update upvalue | 216 -- Clear old timer table and update upvalue |
| 215 AceTimer.activeTimers = {} | 217 AceTimer.activeTimers = {} |
| 216 activeTimers = AceTimer.activeTimers | 218 activeTimers = AceTimer.activeTimers |
| 217 for handle, timer in pairs(oldTimers) do | 219 for handle, timer in next, oldTimers do |
| 218 local newTimer | 220 local newTimer |
| 219 -- Stop the old timer animation | 221 -- Stop the old timer animation |
| 220 local duration, elapsed = timer:GetDuration(), timer:GetElapsed() | 222 local duration, elapsed = timer:GetDuration(), timer:GetElapsed() |
| 221 timer:GetParent():Stop() | 223 timer:GetParent():Stop() |
| 222 if timer.looping then | 224 if timer.looping then |
| 230 newTimer.handle = handle | 232 newTimer.handle = handle |
| 231 end | 233 end |
| 232 | 234 |
| 233 -- Migrate transitional handles | 235 -- Migrate transitional handles |
| 234 if oldminor < 13 and AceTimer.hashCompatTable then | 236 if oldminor < 13 and AceTimer.hashCompatTable then |
| 235 for handle, id in pairs(AceTimer.hashCompatTable) do | 237 for handle, id in next, AceTimer.hashCompatTable do |
| 236 local t = activeTimers[id] | 238 local t = activeTimers[id] |
| 237 if t then | 239 if t then |
| 238 activeTimers[id] = nil | 240 activeTimers[id] = nil |
| 239 activeTimers[handle] = t | 241 activeTimers[handle] = t |
| 240 t.handle = handle | 242 t.handle = handle |
| 255 "TimeLeft" | 257 "TimeLeft" |
| 256 } | 258 } |
| 257 | 259 |
| 258 function AceTimer:Embed(target) | 260 function AceTimer:Embed(target) |
| 259 AceTimer.embeds[target] = true | 261 AceTimer.embeds[target] = true |
| 260 for _,v in pairs(mixins) do | 262 for _,v in next, mixins do |
| 261 target[v] = AceTimer[v] | 263 target[v] = AceTimer[v] |
| 262 end | 264 end |
| 263 return target | 265 return target |
| 264 end | 266 end |
| 265 | 267 |
| 269 -- cancel all timers registered for the object | 271 -- cancel all timers registered for the object |
| 270 function AceTimer:OnEmbedDisable(target) | 272 function AceTimer:OnEmbedDisable(target) |
| 271 target:CancelAllTimers() | 273 target:CancelAllTimers() |
| 272 end | 274 end |
| 273 | 275 |
| 274 for addon in pairs(AceTimer.embeds) do | 276 for addon in next, AceTimer.embeds do |
| 275 AceTimer:Embed(addon) | 277 AceTimer:Embed(addon) |
| 276 end | 278 end |
