annotate lib/AceEvent-2.0/AceEvent-2.0.lua @ 22:1b9323256a1b

Merging in 1.0 dev tree
author Flick <flickerstreak@gmail.com>
date Fri, 07 Mar 2008 22:10:55 +0000
parents libs/AceEvent-2.0/AceEvent-2.0.lua@c11ca1d8ed91
children
rev   line source
flickerstreak@1 1 --[[
flickerstreak@1 2 Name: AceEvent-2.0
flickerstreak@22 3 Revision: $Rev: 49307 $
flickerstreak@1 4 Developed by: The Ace Development Team (http://www.wowace.com/index.php/The_Ace_Development_Team)
flickerstreak@1 5 Inspired By: Ace 1.x by Turan (turan@gryphon.com)
flickerstreak@1 6 Website: http://www.wowace.com/
flickerstreak@1 7 Documentation: http://www.wowace.com/index.php/AceEvent-2.0
flickerstreak@1 8 SVN: http://svn.wowace.com/root/trunk/Ace2/AceEvent-2.0
flickerstreak@1 9 Description: Mixin to allow for event handling, scheduling, and inter-addon
flickerstreak@1 10 communication.
flickerstreak@1 11 Dependencies: AceLibrary, AceOO-2.0
flickerstreak@22 12 License: LGPL v2.1
flickerstreak@1 13 ]]
flickerstreak@1 14
flickerstreak@1 15 local MAJOR_VERSION = "AceEvent-2.0"
flickerstreak@22 16 local MINOR_VERSION = "$Revision: 49307 $"
flickerstreak@1 17
flickerstreak@1 18 if not AceLibrary then error(MAJOR_VERSION .. " requires AceLibrary") end
flickerstreak@1 19 if not AceLibrary:IsNewVersion(MAJOR_VERSION, MINOR_VERSION) then return end
flickerstreak@1 20
flickerstreak@1 21 if not AceLibrary:HasInstance("AceOO-2.0") then error(MAJOR_VERSION .. " requires AceOO-2.0") end
flickerstreak@1 22
flickerstreak@1 23 local AceOO = AceLibrary:GetInstance("AceOO-2.0")
flickerstreak@1 24 local Mixin = AceOO.Mixin
flickerstreak@1 25 local AceEvent = Mixin {
flickerstreak@22 26 "RegisterEvent",
flickerstreak@22 27 "RegisterAllEvents",
flickerstreak@22 28 "UnregisterEvent",
flickerstreak@22 29 "UnregisterAllEvents",
flickerstreak@22 30 "TriggerEvent",
flickerstreak@22 31 "ScheduleEvent",
flickerstreak@22 32 "ScheduleRepeatingEvent",
flickerstreak@22 33 "CancelScheduledEvent",
flickerstreak@22 34 "CancelAllScheduledEvents",
flickerstreak@22 35 "IsEventRegistered",
flickerstreak@22 36 "IsEventScheduled",
flickerstreak@22 37 "RegisterBucketEvent",
flickerstreak@22 38 "UnregisterBucketEvent",
flickerstreak@22 39 "UnregisterAllBucketEvents",
flickerstreak@22 40 "IsBucketEventRegistered",
flickerstreak@22 41 "ScheduleLeaveCombatAction",
flickerstreak@22 42 "CancelAllCombatSchedules",
flickerstreak@22 43 }
flickerstreak@1 44
flickerstreak@1 45 local weakKey = {__mode="k"}
flickerstreak@1 46
flickerstreak@1 47 local FAKE_NIL
flickerstreak@1 48 local RATE
flickerstreak@1 49
flickerstreak@1 50 local eventsWhichHappenOnce = {
flickerstreak@1 51 PLAYER_LOGIN = true,
flickerstreak@1 52 AceEvent_FullyInitialized = true,
flickerstreak@1 53 VARIABLES_LOADED = true,
flickerstreak@1 54 PLAYER_LOGOUT = true,
flickerstreak@1 55 }
flickerstreak@1 56 local next = next
flickerstreak@1 57 local pairs = pairs
flickerstreak@1 58 local pcall = pcall
flickerstreak@1 59 local type = type
flickerstreak@1 60 local GetTime = GetTime
flickerstreak@1 61 local gcinfo = gcinfo
flickerstreak@1 62 local unpack = unpack
flickerstreak@1 63 local geterrorhandler = geterrorhandler
flickerstreak@1 64
flickerstreak@22 65 local build = GetBuildInfo()
flickerstreak@22 66 local useTablesAsIDs = build:find("^2%.0%.") or build:find("^2%.1%.") or build:find("^0%.1%.")
flickerstreak@22 67
flickerstreak@22 68 local new, del
flickerstreak@22 69 do
flickerstreak@22 70 local cache = setmetatable({}, {__mode='k'})
flickerstreak@22 71 function new(...)
flickerstreak@22 72 local t = next(cache)
flickerstreak@22 73 if t then
flickerstreak@22 74 cache[t] = nil
flickerstreak@22 75 for i = 1, select('#', ...) do
flickerstreak@22 76 t[i] = select(i, ...)
flickerstreak@22 77 end
flickerstreak@22 78 return t
flickerstreak@22 79 else
flickerstreak@22 80 return { ... }
flickerstreak@22 81 end
flickerstreak@22 82 end
flickerstreak@22 83 function del(t)
flickerstreak@22 84 for k in pairs(t) do
flickerstreak@22 85 t[k] = nil
flickerstreak@22 86 end
flickerstreak@22 87 cache[t] = true
flickerstreak@22 88 return nil
flickerstreak@22 89 end
flickerstreak@22 90 end
flickerstreak@22 91
flickerstreak@1 92 local registeringFromAceEvent
flickerstreak@22 93 --[[----------------------------------------------------------------------------------
flickerstreak@22 94 Notes:
flickerstreak@22 95 * Registers the addon with a Blizzard event or a custom AceEvent, which will cause the given method to be called when that is triggered.
flickerstreak@22 96 Arguments:
flickerstreak@22 97 string - name of the event to register
flickerstreak@22 98 [optional] string or function - name of the method or function to call. Default: same name as "event".
flickerstreak@22 99 [optional] boolean - whether to have method called only once. Default: false
flickerstreak@22 100 ------------------------------------------------------------------------------------]]
flickerstreak@1 101 function AceEvent:RegisterEvent(event, method, once)
flickerstreak@1 102 AceEvent:argCheck(event, 2, "string")
flickerstreak@1 103 if self == AceEvent and not registeringFromAceEvent then
flickerstreak@1 104 AceEvent:argCheck(method, 3, "function")
flickerstreak@1 105 self = method
flickerstreak@1 106 else
flickerstreak@1 107 AceEvent:argCheck(method, 3, "string", "function", "nil", "boolean", "number")
flickerstreak@1 108 if type(method) == "boolean" or type(method) == "number" then
flickerstreak@1 109 AceEvent:argCheck(once, 4, "nil")
flickerstreak@1 110 once, method = method, event
flickerstreak@1 111 end
flickerstreak@1 112 end
flickerstreak@1 113 AceEvent:argCheck(once, 4, "number", "boolean", "nil")
flickerstreak@1 114 if eventsWhichHappenOnce[event] then
flickerstreak@1 115 once = true
flickerstreak@1 116 end
flickerstreak@1 117 local throttleRate
flickerstreak@1 118 if type(once) == "number" then
flickerstreak@1 119 throttleRate, once = once
flickerstreak@1 120 end
flickerstreak@1 121 if not method then
flickerstreak@1 122 method = event
flickerstreak@1 123 end
flickerstreak@1 124 if type(method) == "string" and type(self[method]) ~= "function" then
flickerstreak@1 125 AceEvent:error("Cannot register event %q to method %q, it does not exist", event, method)
flickerstreak@1 126 else
flickerstreak@1 127 assert(type(method) == "function" or type(method) == "string")
flickerstreak@1 128 end
flickerstreak@1 129
flickerstreak@1 130 local AceEvent_registry = AceEvent.registry
flickerstreak@1 131 if not AceEvent_registry[event] then
flickerstreak@22 132 AceEvent_registry[event] = new()
flickerstreak@1 133 AceEvent.frame:RegisterEvent(event)
flickerstreak@1 134 end
flickerstreak@1 135
flickerstreak@1 136 local remember = true
flickerstreak@1 137 if AceEvent_registry[event][self] then
flickerstreak@1 138 remember = false
flickerstreak@1 139 end
flickerstreak@1 140 AceEvent_registry[event][self] = method
flickerstreak@1 141
flickerstreak@1 142 local AceEvent_onceRegistry = AceEvent.onceRegistry
flickerstreak@1 143 if once then
flickerstreak@1 144 if not AceEvent_onceRegistry then
flickerstreak@1 145 AceEvent.onceRegistry = {}
flickerstreak@1 146 AceEvent_onceRegistry = AceEvent.onceRegistry
flickerstreak@1 147 end
flickerstreak@1 148 if not AceEvent_onceRegistry[event] then
flickerstreak@22 149 AceEvent_onceRegistry[event] = new()
flickerstreak@1 150 end
flickerstreak@1 151 AceEvent_onceRegistry[event][self] = true
flickerstreak@1 152 else
flickerstreak@1 153 if AceEvent_onceRegistry and AceEvent_onceRegistry[event] then
flickerstreak@1 154 AceEvent_onceRegistry[event][self] = nil
flickerstreak@1 155 if not next(AceEvent_onceRegistry[event]) then
flickerstreak@22 156 AceEvent_onceRegistry[event] = del(AceEvent_onceRegistry[event])
flickerstreak@1 157 end
flickerstreak@1 158 end
flickerstreak@1 159 end
flickerstreak@1 160
flickerstreak@1 161 local AceEvent_throttleRegistry = AceEvent.throttleRegistry
flickerstreak@1 162 if throttleRate then
flickerstreak@1 163 if not AceEvent_throttleRegistry then
flickerstreak@1 164 AceEvent.throttleRegistry = {}
flickerstreak@1 165 AceEvent_throttleRegistry = AceEvent.throttleRegistry
flickerstreak@1 166 end
flickerstreak@1 167 if not AceEvent_throttleRegistry[event] then
flickerstreak@22 168 AceEvent_throttleRegistry[event] = new()
flickerstreak@1 169 end
flickerstreak@1 170 if AceEvent_throttleRegistry[event][self] then
flickerstreak@1 171 AceEvent_throttleRegistry[event][self] = nil
flickerstreak@1 172 end
flickerstreak@22 173 AceEvent_throttleRegistry[event][self] = setmetatable(new(), weakKey)
flickerstreak@1 174 local t = AceEvent_throttleRegistry[event][self]
flickerstreak@1 175 t[RATE] = throttleRate
flickerstreak@1 176 else
flickerstreak@1 177 if AceEvent_throttleRegistry and AceEvent_throttleRegistry[event] then
flickerstreak@1 178 if AceEvent_throttleRegistry[event][self] then
flickerstreak@1 179 AceEvent_throttleRegistry[event][self] = nil
flickerstreak@1 180 end
flickerstreak@1 181 if not next(AceEvent_throttleRegistry[event]) then
flickerstreak@22 182 AceEvent_throttleRegistry[event] = del(AceEvent_throttleRegistry[event])
flickerstreak@1 183 end
flickerstreak@1 184 end
flickerstreak@1 185 end
flickerstreak@1 186
flickerstreak@1 187 if remember then
flickerstreak@1 188 AceEvent:TriggerEvent("AceEvent_EventRegistered", self, event)
flickerstreak@1 189 end
flickerstreak@1 190 end
flickerstreak@1 191
flickerstreak@1 192 local ALL_EVENTS
flickerstreak@1 193
flickerstreak@22 194 --[[----------------------------------------------------------------------------------
flickerstreak@22 195 Notes:
flickerstreak@22 196 * Registers all events to the given method
flickerstreak@22 197 * To access the current event, check AceEvent.currentEvent
flickerstreak@22 198 * To access the current event's unique identifier, check AceEvent.currentEventUID
flickerstreak@22 199 * This is only for debugging purposes.
flickerstreak@22 200 Arguments:
flickerstreak@22 201 [optional] string or function - name of the method or function to call. Default: same name as "event".
flickerstreak@22 202 ------------------------------------------------------------------------------------]]
flickerstreak@1 203 function AceEvent:RegisterAllEvents(method)
flickerstreak@1 204 if self == AceEvent then
flickerstreak@1 205 AceEvent:argCheck(method, 1, "function")
flickerstreak@1 206 self = method
flickerstreak@1 207 else
flickerstreak@1 208 AceEvent:argCheck(method, 1, "string", "function")
flickerstreak@1 209 if type(method) == "string" and type(self[method]) ~= "function" then
flickerstreak@1 210 AceEvent:error("Cannot register all events to method %q, it does not exist", method)
flickerstreak@1 211 end
flickerstreak@1 212 end
flickerstreak@22 213
flickerstreak@1 214 local AceEvent_registry = AceEvent.registry
flickerstreak@1 215 if not AceEvent_registry[ALL_EVENTS] then
flickerstreak@22 216 AceEvent_registry[ALL_EVENTS] = new()
flickerstreak@1 217 AceEvent.frame:RegisterAllEvents()
flickerstreak@1 218 end
flickerstreak@22 219
flickerstreak@22 220 local remember = not AceEvent_registry[ALL_EVENTS][self]
flickerstreak@1 221 AceEvent_registry[ALL_EVENTS][self] = method
flickerstreak@22 222 if remember then
flickerstreak@22 223 AceEvent:TriggerEvent("AceEvent_EventRegistered", self, "all")
flickerstreak@22 224 end
flickerstreak@1 225 end
flickerstreak@1 226
flickerstreak@22 227 --[[----------------------------------------------------------------------------------
flickerstreak@22 228 Notes:
flickerstreak@22 229 * Trigger a custom AceEvent.
flickerstreak@22 230 * This should never be called to simulate fake Blizzard events.
flickerstreak@22 231 * Custom events should be in the form of AddonName_SpecificEvent
flickerstreak@22 232 Arguments:
flickerstreak@22 233 string - name of the event
flickerstreak@22 234 tuple - list of arguments to pass along
flickerstreak@22 235 ------------------------------------------------------------------------------------]]
flickerstreak@1 236 function AceEvent:TriggerEvent(event, ...)
flickerstreak@1 237 if type(event) ~= "string" then
flickerstreak@1 238 DEFAULT_CHAT_FRAME:AddMessage(debugstack())
flickerstreak@1 239 end
flickerstreak@1 240 AceEvent:argCheck(event, 2, "string")
flickerstreak@1 241 local AceEvent_registry = AceEvent.registry
flickerstreak@1 242 if (not AceEvent_registry[event] or not next(AceEvent_registry[event])) and (not AceEvent_registry[ALL_EVENTS] or not next(AceEvent_registry[ALL_EVENTS])) then
flickerstreak@1 243 return
flickerstreak@1 244 end
flickerstreak@1 245 local lastEvent = AceEvent.currentEvent
flickerstreak@1 246 AceEvent.currentEvent = event
flickerstreak@22 247 local lastEventUID = AceEvent.currentEventUID
flickerstreak@22 248 local uid = AceEvent.UID_NUM + 1
flickerstreak@22 249 AceEvent.UID_NUM = uid
flickerstreak@22 250 AceEvent.currentEventUID = uid
flickerstreak@22 251
flickerstreak@22 252 local tmp = new()
flickerstreak@1 253
flickerstreak@1 254 local AceEvent_onceRegistry = AceEvent.onceRegistry
flickerstreak@1 255 if AceEvent_onceRegistry and AceEvent_onceRegistry[event] then
flickerstreak@1 256 for obj, method in pairs(AceEvent_onceRegistry[event]) do
flickerstreak@1 257 tmp[obj] = AceEvent_registry[event] and AceEvent_registry[event][obj] or nil
flickerstreak@1 258 end
flickerstreak@1 259 local obj = next(tmp)
flickerstreak@1 260 while obj do
flickerstreak@1 261 local method = tmp[obj]
flickerstreak@1 262 AceEvent.UnregisterEvent(obj, event)
flickerstreak@1 263 if type(method) == "string" then
flickerstreak@1 264 local obj_method = obj[method]
flickerstreak@1 265 if obj_method then
flickerstreak@1 266 local success, err = pcall(obj_method, obj, ...)
flickerstreak@22 267 if not success then geterrorhandler()(err:find("%.lua:%d+:") and err or (debugstack():match("(.-: )in.-\n") or "") .. err) end
flickerstreak@1 268 end
flickerstreak@1 269 elseif method then -- function
flickerstreak@1 270 local success, err = pcall(method, ...)
flickerstreak@22 271 if not success then geterrorhandler()(err:find("%.lua:%d+:") and err or (debugstack():match("(.-: )in.-\n") or "") .. err) end
flickerstreak@1 272 end
flickerstreak@1 273 tmp[obj] = nil
flickerstreak@1 274 obj = next(tmp)
flickerstreak@1 275 end
flickerstreak@1 276 end
flickerstreak@1 277
flickerstreak@1 278 local AceEvent_throttleRegistry = AceEvent.throttleRegistry
flickerstreak@1 279 local throttleTable = AceEvent_throttleRegistry and AceEvent_throttleRegistry[event]
flickerstreak@1 280 if AceEvent_registry[event] then
flickerstreak@1 281 for obj, method in pairs(AceEvent_registry[event]) do
flickerstreak@1 282 tmp[obj] = method
flickerstreak@1 283 end
flickerstreak@1 284 local obj = next(tmp)
flickerstreak@1 285 while obj do
flickerstreak@1 286 local method = tmp[obj]
flickerstreak@1 287 local continue = false
flickerstreak@1 288 if throttleTable and throttleTable[obj] then
flickerstreak@1 289 local a1 = ...
flickerstreak@1 290 if a1 == nil then
flickerstreak@1 291 a1 = FAKE_NIL
flickerstreak@1 292 end
flickerstreak@1 293 if not throttleTable[obj][a1] or GetTime() - throttleTable[obj][a1] >= throttleTable[obj][RATE] then
flickerstreak@1 294 throttleTable[obj][a1] = GetTime()
flickerstreak@1 295 else
flickerstreak@1 296 continue = true
flickerstreak@1 297 end
flickerstreak@1 298 end
flickerstreak@1 299 if not continue then
flickerstreak@1 300 if type(method) == "string" then
flickerstreak@1 301 local obj_method = obj[method]
flickerstreak@1 302 if obj_method then
flickerstreak@1 303 local success, err = pcall(obj_method, obj, ...)
flickerstreak@22 304 if not success then geterrorhandler()(err:find("%.lua:%d+:") and err or (debugstack():match("(.-: )in.-\n") or "") .. err) end
flickerstreak@1 305 end
flickerstreak@1 306 elseif method then -- function
flickerstreak@1 307 local success, err = pcall(method, ...)
flickerstreak@22 308 if not success then geterrorhandler()(err:find("%.lua:%d+:") and err or (debugstack():match("(.-: )in.-\n") or "") .. err) end
flickerstreak@1 309 end
flickerstreak@1 310 end
flickerstreak@1 311 tmp[obj] = nil
flickerstreak@1 312 obj = next(tmp)
flickerstreak@1 313 end
flickerstreak@1 314 end
flickerstreak@1 315 if AceEvent_registry[ALL_EVENTS] then
flickerstreak@1 316 for obj, method in pairs(AceEvent_registry[ALL_EVENTS]) do
flickerstreak@1 317 tmp[obj] = method
flickerstreak@1 318 end
flickerstreak@1 319 local obj = next(tmp)
flickerstreak@1 320 while obj do
flickerstreak@1 321 local method = tmp[obj]
flickerstreak@1 322 if type(method) == "string" then
flickerstreak@1 323 local obj_method = obj[method]
flickerstreak@1 324 if obj_method then
flickerstreak@1 325 local success, err = pcall(obj_method, obj, ...)
flickerstreak@22 326 if not success then geterrorhandler()(err:find("%.lua:%d+:") and err or (debugstack():match("(.-: )in.-\n") or "") .. err) end
flickerstreak@1 327 end
flickerstreak@1 328 elseif method then -- function
flickerstreak@1 329 local success, err = pcall(method, ...)
flickerstreak@22 330 if not success then geterrorhandler()(err:find("%.lua:%d+:") and err or (debugstack():match("(.-: )in.-\n") or "") .. err) end
flickerstreak@1 331 end
flickerstreak@1 332 tmp[obj] = nil
flickerstreak@1 333 obj = next(tmp)
flickerstreak@1 334 end
flickerstreak@1 335 end
flickerstreak@22 336 tmp = del(tmp)
flickerstreak@1 337 AceEvent.currentEvent = lastEvent
flickerstreak@22 338 AceEvent.currentEventUID = lastEventUID
flickerstreak@1 339 end
flickerstreak@1 340
flickerstreak@1 341 local delayRegistry
flickerstreak@22 342 local OnUpdate
flickerstreak@22 343 do
flickerstreak@22 344 local tmp = {}
flickerstreak@22 345 OnUpdate = function()
flickerstreak@22 346 local t = GetTime()
flickerstreak@22 347 for k,v in pairs(delayRegistry) do
flickerstreak@22 348 tmp[k] = true
flickerstreak@22 349 end
flickerstreak@22 350 for k in pairs(tmp) do
flickerstreak@22 351 local v = delayRegistry[k]
flickerstreak@22 352 if v then
flickerstreak@22 353 local v_time = v.time
flickerstreak@22 354 if not v_time then
flickerstreak@22 355 delayRegistry[k] = nil
flickerstreak@22 356 elseif v_time <= t then
flickerstreak@22 357 local v_repeatDelay = v.repeatDelay
flickerstreak@22 358 if v_repeatDelay then
flickerstreak@22 359 -- use the event time, not the current time, else timing inaccuracies add up over time
flickerstreak@22 360 v.time = v_time + v_repeatDelay
flickerstreak@22 361 end
flickerstreak@22 362 local event = v.event
flickerstreak@22 363 if type(event) == "function" then
flickerstreak@22 364 local uid = AceEvent.UID_NUM + 1
flickerstreak@22 365 AceEvent.UID_NUM = uid
flickerstreak@22 366 AceEvent.currentEventUID = uid
flickerstreak@22 367 local success, err = pcall(event, unpack(v, 1, v.n))
flickerstreak@22 368 if not success then geterrorhandler()(err:find("%.lua:%d+:") and err or (debugstack():match("(.-: )in.-\n") or "") .. err) end
flickerstreak@22 369 AceEvent.currentEventUID = nil
flickerstreak@22 370 else
flickerstreak@22 371 AceEvent:TriggerEvent(event, unpack(v, 1, v.n))
flickerstreak@22 372 end
flickerstreak@22 373 if not v_repeatDelay then
flickerstreak@22 374 local x = delayRegistry[k]
flickerstreak@22 375 if x and x.time == v_time then -- check if it was manually reset
flickerstreak@22 376 if not useTablesAsIDs or type(k) == "string" then
flickerstreak@22 377 del(delayRegistry[k])
flickerstreak@22 378 end
flickerstreak@22 379 delayRegistry[k] = nil
flickerstreak@22 380 end
flickerstreak@1 381 end
flickerstreak@1 382 end
flickerstreak@1 383 end
flickerstreak@1 384 end
flickerstreak@22 385 for k in pairs(tmp) do
flickerstreak@22 386 tmp[k] = nil
flickerstreak@22 387 end
flickerstreak@22 388 if not next(delayRegistry) then
flickerstreak@22 389 AceEvent.frame:Hide()
flickerstreak@22 390 end
flickerstreak@1 391 end
flickerstreak@1 392 end
flickerstreak@1 393
flickerstreak@1 394 local function ScheduleEvent(self, repeating, event, delay, ...)
flickerstreak@1 395 local id
flickerstreak@22 396 if type(event) == "string" or (useTablesAsIDs and type(event) == "table") then
flickerstreak@22 397 if useTablesAsIDs and type(event) == "table" then
flickerstreak@1 398 if not delayRegistry or not delayRegistry[event] then
flickerstreak@1 399 AceEvent:error("Bad argument #2 to `ScheduleEvent'. Improper id table fed in.")
flickerstreak@1 400 end
flickerstreak@1 401 end
flickerstreak@1 402 if type(delay) ~= "number" then
flickerstreak@1 403 id, event, delay = event, delay, ...
flickerstreak@1 404 AceEvent:argCheck(event, 3, "string", "function", --[[ so message is right ]] "number")
flickerstreak@1 405 AceEvent:argCheck(delay, 4, "number")
flickerstreak@1 406 self:CancelScheduledEvent(id)
flickerstreak@1 407 end
flickerstreak@1 408 else
flickerstreak@1 409 AceEvent:argCheck(event, 2, "string", "function")
flickerstreak@1 410 AceEvent:argCheck(delay, 3, "number")
flickerstreak@1 411 end
flickerstreak@1 412
flickerstreak@1 413 if not delayRegistry then
flickerstreak@1 414 AceEvent.delayRegistry = {}
flickerstreak@1 415 delayRegistry = AceEvent.delayRegistry
flickerstreak@1 416 AceEvent.frame:SetScript("OnUpdate", OnUpdate)
flickerstreak@1 417 end
flickerstreak@1 418 local t
flickerstreak@22 419 if useTablesAsIDs and type(id) == "table" then
flickerstreak@1 420 for k in pairs(id) do
flickerstreak@1 421 id[k] = nil
flickerstreak@1 422 end
flickerstreak@1 423 t = id
flickerstreak@1 424 for i = 2, select('#', ...) do
flickerstreak@1 425 t[i-1] = select(i, ...)
flickerstreak@1 426 end
flickerstreak@22 427 t.n = select('#', ...) - 1
flickerstreak@1 428 elseif id then
flickerstreak@22 429 t = new(select(2, ...))
flickerstreak@22 430 t.n = select('#', ...) - 1
flickerstreak@1 431 else
flickerstreak@22 432 t = new(...)
flickerstreak@22 433 t.n = select('#', ...)
flickerstreak@1 434 end
flickerstreak@1 435 t.event = event
flickerstreak@1 436 t.time = GetTime() + delay
flickerstreak@1 437 t.self = self
flickerstreak@1 438 t.id = id or t
flickerstreak@1 439 t.repeatDelay = repeating and delay
flickerstreak@1 440 delayRegistry[t.id] = t
flickerstreak@1 441 AceEvent.frame:Show()
flickerstreak@22 442 if useTablesAsIDs then
flickerstreak@22 443 return t.id
flickerstreak@22 444 else
flickerstreak@22 445 return
flickerstreak@22 446 end
flickerstreak@1 447 end
flickerstreak@1 448
flickerstreak@22 449 --[[----------------------------------------------------------------------------------
flickerstreak@22 450 Notes:
flickerstreak@22 451 * Schedule an event to fire.
flickerstreak@22 452 * To fire on the next frame, specify a delay of 0.
flickerstreak@22 453 Arguments:
flickerstreak@22 454 string or function - name of the event to fire, or a function to call.
flickerstreak@22 455 number - the amount of time to wait until calling.
flickerstreak@22 456 tuple - a list of arguments to pass along.
flickerstreak@22 457 ------------------------------------------------------------------------------------]]
flickerstreak@1 458 function AceEvent:ScheduleEvent(event, delay, ...)
flickerstreak@22 459 if type(event) == "string" or (useTablesAsIDs and type(event) == "table") then
flickerstreak@22 460 if useTablesAsIDs and type(event) == "table" then
flickerstreak@1 461 if not delayRegistry or not delayRegistry[event] then
flickerstreak@1 462 AceEvent:error("Bad argument #2 to `ScheduleEvent'. Improper id table fed in.")
flickerstreak@1 463 end
flickerstreak@1 464 end
flickerstreak@1 465 if type(delay) ~= "number" then
flickerstreak@1 466 AceEvent:argCheck(delay, 3, "string", "function", --[[ so message is right ]] "number")
flickerstreak@1 467 AceEvent:argCheck(..., 4, "number")
flickerstreak@1 468 end
flickerstreak@1 469 else
flickerstreak@1 470 AceEvent:argCheck(event, 2, "string", "function")
flickerstreak@1 471 AceEvent:argCheck(delay, 3, "number")
flickerstreak@1 472 end
flickerstreak@1 473
flickerstreak@1 474 return ScheduleEvent(self, false, event, delay, ...)
flickerstreak@1 475 end
flickerstreak@1 476
flickerstreak@1 477 function AceEvent:ScheduleRepeatingEvent(event, delay, ...)
flickerstreak@22 478 if type(event) == "string" or (useTablesAsIDs and type(event) == "table") then
flickerstreak@22 479 if useTablesAsIDs and type(event) == "table" then
flickerstreak@1 480 if not delayRegistry or not delayRegistry[event] then
flickerstreak@1 481 AceEvent:error("Bad argument #2 to `ScheduleEvent'. Improper id table fed in.")
flickerstreak@1 482 end
flickerstreak@1 483 end
flickerstreak@1 484 if type(delay) ~= "number" then
flickerstreak@1 485 AceEvent:argCheck(delay, 3, "string", "function", --[[ so message is right ]] "number")
flickerstreak@1 486 AceEvent:argCheck(..., 4, "number")
flickerstreak@1 487 end
flickerstreak@1 488 else
flickerstreak@1 489 AceEvent:argCheck(event, 2, "string", "function")
flickerstreak@1 490 AceEvent:argCheck(delay, 3, "number")
flickerstreak@1 491 end
flickerstreak@1 492
flickerstreak@1 493 return ScheduleEvent(self, true, event, delay, ...)
flickerstreak@1 494 end
flickerstreak@1 495
flickerstreak@1 496 function AceEvent:CancelScheduledEvent(t)
flickerstreak@22 497 if useTablesAsIDs then
flickerstreak@22 498 AceEvent:argCheck(t, 2, "string", "table")
flickerstreak@22 499 else
flickerstreak@22 500 AceEvent:argCheck(t, 2, "string")
flickerstreak@22 501 end
flickerstreak@1 502 if delayRegistry then
flickerstreak@1 503 local v = delayRegistry[t]
flickerstreak@1 504 if v then
flickerstreak@22 505 if not useTablesAsIDs or type(t) == "string" then
flickerstreak@22 506 del(delayRegistry[t])
flickerstreak@22 507 end
flickerstreak@1 508 delayRegistry[t] = nil
flickerstreak@1 509 if not next(delayRegistry) then
flickerstreak@1 510 AceEvent.frame:Hide()
flickerstreak@1 511 end
flickerstreak@1 512 return true
flickerstreak@1 513 end
flickerstreak@1 514 end
flickerstreak@1 515 return false
flickerstreak@1 516 end
flickerstreak@1 517
flickerstreak@1 518 function AceEvent:IsEventScheduled(t)
flickerstreak@22 519 if useTablesAsIDs then
flickerstreak@22 520 AceEvent:argCheck(t, 2, "string", "table")
flickerstreak@22 521 else
flickerstreak@22 522 AceEvent:argCheck(t, 2, "string")
flickerstreak@22 523 end
flickerstreak@1 524 if delayRegistry then
flickerstreak@1 525 local v = delayRegistry[t]
flickerstreak@1 526 if v then
flickerstreak@1 527 return true, v.time - GetTime()
flickerstreak@1 528 end
flickerstreak@1 529 end
flickerstreak@1 530 return false, nil
flickerstreak@1 531 end
flickerstreak@1 532
flickerstreak@1 533 function AceEvent:UnregisterEvent(event)
flickerstreak@1 534 AceEvent:argCheck(event, 2, "string")
flickerstreak@1 535 local AceEvent_registry = AceEvent.registry
flickerstreak@1 536 if AceEvent_registry[event] and AceEvent_registry[event][self] then
flickerstreak@1 537 AceEvent_registry[event][self] = nil
flickerstreak@1 538 local AceEvent_onceRegistry = AceEvent.onceRegistry
flickerstreak@1 539 if AceEvent_onceRegistry and AceEvent_onceRegistry[event] and AceEvent_onceRegistry[event][self] then
flickerstreak@1 540 AceEvent_onceRegistry[event][self] = nil
flickerstreak@1 541 if not next(AceEvent_onceRegistry[event]) then
flickerstreak@22 542 AceEvent_onceRegistry[event] = del(AceEvent_onceRegistry[event])
flickerstreak@1 543 end
flickerstreak@1 544 end
flickerstreak@1 545 local AceEvent_throttleRegistry = AceEvent.throttleRegistry
flickerstreak@1 546 if AceEvent_throttleRegistry and AceEvent_throttleRegistry[event] and AceEvent_throttleRegistry[event][self] then
flickerstreak@1 547 AceEvent_throttleRegistry[event][self] = nil
flickerstreak@1 548 if not next(AceEvent_throttleRegistry[event]) then
flickerstreak@22 549 AceEvent_throttleRegistry[event] = del(AceEvent_throttleRegistry[event])
flickerstreak@1 550 end
flickerstreak@1 551 end
flickerstreak@1 552 if not next(AceEvent_registry[event]) then
flickerstreak@22 553 AceEvent_registry[event] = del(AceEvent_registry[event])
flickerstreak@1 554 if not AceEvent_registry[ALL_EVENTS] or not next(AceEvent_registry[ALL_EVENTS]) then
flickerstreak@1 555 AceEvent.frame:UnregisterEvent(event)
flickerstreak@1 556 end
flickerstreak@1 557 end
flickerstreak@1 558 else
flickerstreak@1 559 if self == AceEvent then
flickerstreak@22 560 error(("Cannot unregister event %q. Improperly unregistering from AceEvent-2.0."):format(event), 2)
flickerstreak@1 561 else
flickerstreak@1 562 AceEvent:error("Cannot unregister event %q. %q is not registered with it.", event, self)
flickerstreak@1 563 end
flickerstreak@1 564 end
flickerstreak@1 565 AceEvent:TriggerEvent("AceEvent_EventUnregistered", self, event)
flickerstreak@1 566 end
flickerstreak@1 567
flickerstreak@1 568 function AceEvent:UnregisterAllEvents()
flickerstreak@1 569 local AceEvent_registry = AceEvent.registry
flickerstreak@1 570 if AceEvent_registry[ALL_EVENTS] and AceEvent_registry[ALL_EVENTS][self] then
flickerstreak@1 571 AceEvent_registry[ALL_EVENTS][self] = nil
flickerstreak@1 572 if not next(AceEvent_registry[ALL_EVENTS]) then
flickerstreak@22 573 AceEvent_registry[ALL_EVENTS] = del(AceEvent_registry[ALL_EVENTS])
flickerstreak@1 574 AceEvent.frame:UnregisterAllEvents()
flickerstreak@1 575 for k,v in pairs(AceEvent_registry) do
flickerstreak@22 576 AceEvent.frame:RegisterEvent(k)
flickerstreak@1 577 end
flickerstreak@1 578 end
flickerstreak@1 579 end
flickerstreak@22 580 if AceEvent_registry.AceEvent_EventUnregistered then
flickerstreak@22 581 local event, data = "AceEvent_EventUnregistered", AceEvent_registry.AceEvent_EventUnregistered
flickerstreak@22 582 local x = data[self]
flickerstreak@22 583 data[self] = nil
flickerstreak@22 584 if x then
flickerstreak@22 585 if not next(data) then
flickerstreak@22 586 if not AceEvent_registry[ALL_EVENTS] then
flickerstreak@22 587 AceEvent.frame:UnregisterEvent(event)
flickerstreak@22 588 end
flickerstreak@22 589 AceEvent_registry[event] = del(AceEvent_registry[event])
flickerstreak@22 590 end
flickerstreak@22 591 AceEvent:TriggerEvent("AceEvent_EventUnregistered", self, event)
flickerstreak@22 592 end
flickerstreak@22 593 end
flickerstreak@1 594 for event, data in pairs(AceEvent_registry) do
flickerstreak@1 595 local x = data[self]
flickerstreak@1 596 data[self] = nil
flickerstreak@1 597 if x and event ~= ALL_EVENTS then
flickerstreak@1 598 if not next(data) then
flickerstreak@22 599 if not AceEvent_registry[ALL_EVENTS] then
flickerstreak@1 600 AceEvent.frame:UnregisterEvent(event)
flickerstreak@1 601 end
flickerstreak@22 602 AceEvent_registry[event] = del(AceEvent_registry[event])
flickerstreak@1 603 end
flickerstreak@1 604 AceEvent:TriggerEvent("AceEvent_EventUnregistered", self, event)
flickerstreak@1 605 end
flickerstreak@1 606 end
flickerstreak@1 607 if AceEvent.onceRegistry then
flickerstreak@1 608 for event, data in pairs(AceEvent.onceRegistry) do
flickerstreak@1 609 data[self] = nil
flickerstreak@1 610 end
flickerstreak@1 611 end
flickerstreak@1 612 end
flickerstreak@1 613
flickerstreak@1 614 function AceEvent:CancelAllScheduledEvents()
flickerstreak@1 615 if delayRegistry then
flickerstreak@1 616 for k,v in pairs(delayRegistry) do
flickerstreak@1 617 if v.self == self then
flickerstreak@22 618 if not useTablesAsIDs or type(k) == "string" then
flickerstreak@22 619 del(delayRegistry[k])
flickerstreak@22 620 end
flickerstreak@1 621 delayRegistry[k] = nil
flickerstreak@1 622 end
flickerstreak@1 623 end
flickerstreak@1 624 if not next(delayRegistry) then
flickerstreak@1 625 AceEvent.frame:Hide()
flickerstreak@1 626 end
flickerstreak@1 627 end
flickerstreak@1 628 end
flickerstreak@1 629
flickerstreak@1 630 function AceEvent:IsEventRegistered(event)
flickerstreak@1 631 AceEvent:argCheck(event, 2, "string")
flickerstreak@1 632 local AceEvent_registry = AceEvent.registry
flickerstreak@1 633 if self == AceEvent then
flickerstreak@22 634 return AceEvent_registry[event] and next(AceEvent_registry[event]) or AceEvent_registry[ALL_EVENTS] and next(AceEvent_registry[ALL_EVENTS]) and true or false
flickerstreak@1 635 end
flickerstreak@1 636 if AceEvent_registry[event] and AceEvent_registry[event][self] then
flickerstreak@1 637 return true, AceEvent_registry[event][self]
flickerstreak@1 638 end
flickerstreak@22 639 if AceEvent_registry[ALL_EVENTS] and AceEvent_registry[ALL_EVENTS][self] then
flickerstreak@22 640 return true, AceEvent_registry[ALL_EVENTS][self]
flickerstreak@22 641 end
flickerstreak@1 642 return false, nil
flickerstreak@1 643 end
flickerstreak@1 644
flickerstreak@22 645 local UnitExists = UnitExists
flickerstreak@1 646 local bucketfunc
flickerstreak@22 647 function AceEvent:RegisterBucketEvent(event, delay, method, ...)
flickerstreak@1 648 AceEvent:argCheck(event, 2, "string", "table")
flickerstreak@1 649 if type(event) == "table" then
flickerstreak@1 650 for k,v in pairs(event) do
flickerstreak@1 651 if type(k) ~= "number" then
flickerstreak@1 652 AceEvent:error("All keys to argument #2 to `RegisterBucketEvent' must be numbers.")
flickerstreak@1 653 elseif type(v) ~= "string" then
flickerstreak@1 654 AceEvent:error("All values to argument #2 to `RegisterBucketEvent' must be strings.")
flickerstreak@1 655 end
flickerstreak@1 656 end
flickerstreak@1 657 end
flickerstreak@1 658 AceEvent:argCheck(delay, 3, "number")
flickerstreak@1 659 if AceEvent == self then
flickerstreak@1 660 AceEvent:argCheck(method, 4, "function")
flickerstreak@1 661 self = method
flickerstreak@1 662 else
flickerstreak@1 663 if type(event) == "string" then
flickerstreak@1 664 AceEvent:argCheck(method, 4, "string", "function", "nil")
flickerstreak@1 665 if not method then
flickerstreak@1 666 method = event
flickerstreak@1 667 end
flickerstreak@1 668 else
flickerstreak@1 669 AceEvent:argCheck(method, 4, "string", "function")
flickerstreak@1 670 end
flickerstreak@1 671
flickerstreak@1 672 if type(method) == "string" and type(self[method]) ~= "function" then
flickerstreak@1 673 AceEvent:error("Cannot register event %q to method %q, it does not exist", event, method)
flickerstreak@1 674 end
flickerstreak@1 675 end
flickerstreak@22 676 local buckets = AceEvent.buckets
flickerstreak@22 677 if not buckets[event] then
flickerstreak@22 678 buckets[event] = new()
flickerstreak@1 679 end
flickerstreak@22 680 if not buckets[event][self] then
flickerstreak@22 681 local t = new()
flickerstreak@22 682 t.current = new()
flickerstreak@22 683 t.self = self
flickerstreak@22 684 buckets[event][self] = t
flickerstreak@22 685 else
flickerstreak@22 686 AceEvent.CancelScheduledEvent(self, buckets[event][self].id)
flickerstreak@1 687 end
flickerstreak@22 688 local bucket = buckets[event][self]
flickerstreak@22 689 bucket.method = method
flickerstreak@22 690
flickerstreak@22 691 local n = select('#', ...)
flickerstreak@22 692 if n > 0 then
flickerstreak@22 693 for i = 1, n do
flickerstreak@22 694 bucket[i] = select(i, ...)
flickerstreak@22 695 end
flickerstreak@1 696 end
flickerstreak@22 697 bucket.n = n
flickerstreak@1 698
flickerstreak@1 699 local func = function(arg1)
flickerstreak@1 700 bucket.run = true
flickerstreak@1 701 if arg1 then
flickerstreak@1 702 bucket.current[arg1] = true
flickerstreak@1 703 end
flickerstreak@1 704 end
flickerstreak@22 705 buckets[event][self].func = func
flickerstreak@22 706 local isUnitBucket = true
flickerstreak@1 707 if type(event) == "string" then
flickerstreak@1 708 AceEvent.RegisterEvent(self, event, func)
flickerstreak@22 709 if not event:find("^UNIT_") then
flickerstreak@22 710 isUnitBucket = false
flickerstreak@22 711 end
flickerstreak@1 712 else
flickerstreak@1 713 for _,v in ipairs(event) do
flickerstreak@1 714 AceEvent.RegisterEvent(self, v, func)
flickerstreak@22 715 if isUnitBucket and not v:find("^UNIT_") then
flickerstreak@22 716 isUnitBucket = false
flickerstreak@22 717 end
flickerstreak@1 718 end
flickerstreak@1 719 end
flickerstreak@22 720 bucket.unit = isUnitBucket
flickerstreak@1 721 if not bucketfunc then
flickerstreak@1 722 bucketfunc = function(bucket)
flickerstreak@1 723 local current = bucket.current
flickerstreak@1 724 local method = bucket.method
flickerstreak@1 725 local self = bucket.self
flickerstreak@1 726 if bucket.run then
flickerstreak@22 727 if bucket.unit then
flickerstreak@22 728 for unit in pairs(current) do
flickerstreak@22 729 if not UnitExists(unit) then
flickerstreak@22 730 current[unit] = nil
flickerstreak@22 731 end
flickerstreak@22 732 end
flickerstreak@22 733 end
flickerstreak@1 734 if type(method) == "string" then
flickerstreak@22 735 self[method](self, current, unpack(bucket, 1, bucket.n))
flickerstreak@1 736 elseif method then -- function
flickerstreak@22 737 method(current, unpack(bucket, 1, bucket.n))
flickerstreak@1 738 end
flickerstreak@1 739 for k in pairs(current) do
flickerstreak@1 740 current[k] = nil
flickerstreak@1 741 k = nil
flickerstreak@1 742 end
flickerstreak@1 743 bucket.run = false
flickerstreak@1 744 end
flickerstreak@1 745 end
flickerstreak@1 746 end
flickerstreak@22 747 bucket.id = "AceEvent-Bucket-" .. tostring(bucket)
flickerstreak@22 748 AceEvent.ScheduleRepeatingEvent(self, bucket.id, bucketfunc, delay, bucket)
flickerstreak@1 749 end
flickerstreak@1 750
flickerstreak@1 751 function AceEvent:IsBucketEventRegistered(event)
flickerstreak@1 752 AceEvent:argCheck(event, 2, "string", "table")
flickerstreak@1 753 return AceEvent.buckets and AceEvent.buckets[event] and AceEvent.buckets[event][self]
flickerstreak@1 754 end
flickerstreak@1 755
flickerstreak@1 756 function AceEvent:UnregisterBucketEvent(event)
flickerstreak@1 757 AceEvent:argCheck(event, 2, "string", "table")
flickerstreak@1 758 if not AceEvent.buckets or not AceEvent.buckets[event] or not AceEvent.buckets[event][self] then
flickerstreak@1 759 AceEvent:error("Cannot unregister bucket event %q. %q is not registered with it.", event, self)
flickerstreak@1 760 end
flickerstreak@1 761
flickerstreak@1 762 local bucket = AceEvent.buckets[event][self]
flickerstreak@1 763
flickerstreak@1 764 if type(event) == "string" then
flickerstreak@1 765 AceEvent.UnregisterEvent(self, event)
flickerstreak@1 766 else
flickerstreak@1 767 for _,v in ipairs(event) do
flickerstreak@1 768 AceEvent.UnregisterEvent(self, v)
flickerstreak@1 769 end
flickerstreak@1 770 end
flickerstreak@1 771 AceEvent:CancelScheduledEvent(bucket.id)
flickerstreak@1 772
flickerstreak@22 773 bucket.current = del(bucket.current)
flickerstreak@22 774 AceEvent.buckets[event][self] = del(bucket)
flickerstreak@1 775 if not next(AceEvent.buckets[event]) then
flickerstreak@22 776 AceEvent.buckets[event] = del(AceEvent.buckets[event])
flickerstreak@1 777 end
flickerstreak@1 778 end
flickerstreak@1 779
flickerstreak@1 780 function AceEvent:UnregisterAllBucketEvents()
flickerstreak@1 781 if not AceEvent.buckets or not next(AceEvent.buckets) then
flickerstreak@1 782 return
flickerstreak@1 783 end
flickerstreak@1 784 for k,v in pairs(AceEvent.buckets) do
flickerstreak@1 785 if v == self then
flickerstreak@1 786 AceEvent.UnregisterBucketEvent(self, k)
flickerstreak@1 787 k = nil
flickerstreak@1 788 end
flickerstreak@1 789 end
flickerstreak@1 790 end
flickerstreak@1 791
flickerstreak@22 792 local combatSchedules
flickerstreak@22 793 function AceEvent:CancelAllCombatSchedules()
flickerstreak@22 794 local i = 0
flickerstreak@22 795 while true do
flickerstreak@22 796 i = i + 1
flickerstreak@22 797 if not combatSchedules[i] then
flickerstreak@22 798 break
flickerstreak@22 799 end
flickerstreak@22 800 local v = combatSchedules[i]
flickerstreak@22 801 if v.self == self then
flickerstreak@22 802 v = del(v)
flickerstreak@22 803 table.remove(combatSchedules, i)
flickerstreak@22 804 i = i - 1
flickerstreak@22 805 end
flickerstreak@22 806 end
flickerstreak@22 807 end
flickerstreak@22 808
flickerstreak@22 809 local inCombat = false
flickerstreak@22 810
flickerstreak@22 811 function AceEvent:PLAYER_REGEN_DISABLED()
flickerstreak@22 812 inCombat = true
flickerstreak@22 813 end
flickerstreak@22 814
flickerstreak@22 815 do
flickerstreak@22 816 local tmp = {}
flickerstreak@22 817 function AceEvent:PLAYER_REGEN_ENABLED()
flickerstreak@22 818 inCombat = false
flickerstreak@22 819 for i, v in ipairs(combatSchedules) do
flickerstreak@22 820 tmp[i] = v
flickerstreak@22 821 combatSchedules[i] = nil
flickerstreak@22 822 end
flickerstreak@22 823 for i, v in ipairs(tmp) do
flickerstreak@22 824 local func = v.func
flickerstreak@22 825 if func then
flickerstreak@22 826 local success, err = pcall(func, unpack(v, 1, v.n))
flickerstreak@22 827 if not success then geterrorhandler()(err:find("%.lua:%d+:") and err or (debugstack():match("(.-: )in.-\n") or "") .. err) end
flickerstreak@22 828 else
flickerstreak@22 829 local obj = v.obj or v.self
flickerstreak@22 830 local method = v.method
flickerstreak@22 831 local obj_method = obj[method]
flickerstreak@22 832 if obj_method then
flickerstreak@22 833 local success, err = pcall(obj_method, obj, unpack(v, 1, v.n))
flickerstreak@22 834 if not success then geterrorhandler()(err:find("%.lua:%d+:") and err or (debugstack():match("(.-: )in.-\n") or "") .. err) end
flickerstreak@22 835 end
flickerstreak@22 836 end
flickerstreak@22 837 tmp[i] = del(v)
flickerstreak@22 838 end
flickerstreak@22 839 end
flickerstreak@22 840 end
flickerstreak@22 841
flickerstreak@22 842 function AceEvent:ScheduleLeaveCombatAction(method, ...)
flickerstreak@22 843 local style = type(method)
flickerstreak@22 844 if self == AceEvent then
flickerstreak@22 845 if style == "table" then
flickerstreak@22 846 local func = (...)
flickerstreak@22 847 AceEvent:argCheck(func, 3, "string")
flickerstreak@22 848 if type(method[func]) ~= "function" then
flickerstreak@22 849 AceEvent:error("Cannot schedule a combat action to method %q, it does not exist", func)
flickerstreak@22 850 end
flickerstreak@22 851 else
flickerstreak@22 852 AceEvent:argCheck(method, 2, "function", --[[so message is right]] "table")
flickerstreak@22 853 end
flickerstreak@22 854 self = method
flickerstreak@22 855 else
flickerstreak@22 856 AceEvent:argCheck(method, 2, "function", "string", "table")
flickerstreak@22 857 if style == "string" and type(self[method]) ~= "function" then
flickerstreak@22 858 AceEvent:error("Cannot schedule a combat action to method %q, it does not exist", method)
flickerstreak@22 859 elseif style == "table" then
flickerstreak@22 860 local func = (...)
flickerstreak@22 861 AceEvent:argCheck(func, 3, "string")
flickerstreak@22 862 if type(method[func]) ~= "function" then
flickerstreak@22 863 AceEvent:error("Cannot schedule a combat action to method %q, it does not exist", func)
flickerstreak@22 864 end
flickerstreak@22 865 end
flickerstreak@22 866 end
flickerstreak@22 867
flickerstreak@22 868 if not inCombat then
flickerstreak@22 869 local success, err
flickerstreak@22 870 if type(method) == "function" then
flickerstreak@22 871 success, err = pcall(method, ...)
flickerstreak@22 872 elseif type(method) == "table" then
flickerstreak@22 873 local func = (...)
flickerstreak@22 874 success, err = pcall(method[func], method, select(2, ...))
flickerstreak@22 875 else
flickerstreak@22 876 success, err = pcall(self[method], self, ...)
flickerstreak@22 877 end
flickerstreak@22 878 if not success then geterrorhandler()(err:find("%.lua:%d+:") and err or (debugstack():match("(.-: )in.-\n") or "") .. err) end
flickerstreak@22 879 return
flickerstreak@22 880 end
flickerstreak@22 881 local t
flickerstreak@22 882 local n = select('#', ...)
flickerstreak@22 883 if style == "table" then
flickerstreak@22 884 t = new(select(2, ...))
flickerstreak@22 885 t.obj = method
flickerstreak@22 886 t.method = (...)
flickerstreak@22 887 t.n = n-1
flickerstreak@22 888 else
flickerstreak@22 889 t = new(...)
flickerstreak@22 890 t.n = n
flickerstreak@22 891 if style == "function" then
flickerstreak@22 892 t.func = method
flickerstreak@22 893 else
flickerstreak@22 894 t.method = method
flickerstreak@22 895 end
flickerstreak@22 896 end
flickerstreak@22 897 t.self = self
flickerstreak@22 898 table.insert(combatSchedules, t)
flickerstreak@22 899 end
flickerstreak@22 900
flickerstreak@1 901 function AceEvent:OnEmbedDisable(target)
flickerstreak@1 902 self.UnregisterAllEvents(target)
flickerstreak@1 903
flickerstreak@1 904 self.CancelAllScheduledEvents(target)
flickerstreak@1 905
flickerstreak@1 906 self.UnregisterAllBucketEvents(target)
flickerstreak@22 907
flickerstreak@22 908 self.CancelAllCombatSchedules(target)
flickerstreak@1 909 end
flickerstreak@1 910
flickerstreak@1 911 function AceEvent:IsFullyInitialized()
flickerstreak@1 912 return self.postInit or false
flickerstreak@1 913 end
flickerstreak@1 914
flickerstreak@1 915 function AceEvent:IsPostPlayerLogin()
flickerstreak@22 916 return IsLoggedIn() and true or false
flickerstreak@1 917 end
flickerstreak@1 918
flickerstreak@1 919 local function activate(self, oldLib, oldDeactivate)
flickerstreak@1 920 AceEvent = self
flickerstreak@22 921
flickerstreak@22 922 self.onceRegistry = oldLib and oldLib.onceRegistry or {}
flickerstreak@22 923 self.throttleRegistry = oldLib and oldLib.throttleRegistry or {}
flickerstreak@22 924 self.delayRegistry = oldLib and oldLib.delayRegistry or {}
flickerstreak@22 925 self.buckets = oldLib and oldLib.buckets or {}
flickerstreak@22 926 self.registry = oldLib and oldLib.registry or {}
flickerstreak@22 927 self.frame = oldLib and oldLib.frame or CreateFrame("Frame", "AceEvent20Frame")
flickerstreak@22 928 self.playerLogin = IsLoggedIn() and true
flickerstreak@22 929 self.postInit = oldLib and oldLib.postInit or self.playerLogin and ChatTypeInfo and ChatTypeInfo.WHISPER and ChatTypeInfo.WHISPER.r and true
flickerstreak@22 930 self.ALL_EVENTS = oldLib and oldLib.ALL_EVENTS or _G.newproxy()
flickerstreak@22 931 self.FAKE_NIL = oldLib and oldLib.FAKE_NIL or _G.newproxy()
flickerstreak@22 932 self.RATE = oldLib and oldLib.RATE or _G.newproxy()
flickerstreak@22 933 self.combatSchedules = oldLib and oldLib.combatSchedules or {}
flickerstreak@22 934 self.UID_NUM = oldLib and oldLib.UID_NUM or 0
flickerstreak@22 935
flickerstreak@22 936 -- Delete this down the road. Makes sure that the addonframes from revisions 33121 - 36174 get their events unregistered.
flickerstreak@22 937 local addonframes = oldLib and oldLib.addonframes
flickerstreak@22 938 if addonframes then
flickerstreak@22 939 for _, v in pairs(addonframes) do
flickerstreak@22 940 v:UnregisterAllEvents()
flickerstreak@22 941 end
flickerstreak@1 942 end
flickerstreak@22 943
flickerstreak@22 944 combatSchedules = self.combatSchedules
flickerstreak@1 945 ALL_EVENTS = self.ALL_EVENTS
flickerstreak@1 946 FAKE_NIL = self.FAKE_NIL
flickerstreak@1 947 RATE = self.RATE
flickerstreak@1 948 local inPlw = false
flickerstreak@1 949 local blacklist = {
flickerstreak@1 950 UNIT_INVENTORY_CHANGED = true,
flickerstreak@1 951 BAG_UPDATE = true,
flickerstreak@1 952 ITEM_LOCK_CHANGED = true,
flickerstreak@1 953 ACTIONBAR_SLOT_CHANGED = true,
flickerstreak@1 954 }
flickerstreak@1 955 self.frame:SetScript("OnEvent", function(_, event, ...)
flickerstreak@1 956 if event == "PLAYER_ENTERING_WORLD" then
flickerstreak@1 957 inPlw = false
flickerstreak@1 958 elseif event == "PLAYER_LEAVING_WORLD" then
flickerstreak@1 959 inPlw = true
flickerstreak@1 960 end
flickerstreak@1 961 if event and (not inPlw or not blacklist[event]) then
flickerstreak@1 962 self:TriggerEvent(event, ...)
flickerstreak@1 963 end
flickerstreak@1 964 end)
flickerstreak@1 965 if self.delayRegistry then
flickerstreak@1 966 delayRegistry = self.delayRegistry
flickerstreak@1 967 self.frame:SetScript("OnUpdate", OnUpdate)
flickerstreak@1 968 end
flickerstreak@1 969
flickerstreak@1 970 self:UnregisterAllEvents()
flickerstreak@1 971 self:CancelAllScheduledEvents()
flickerstreak@1 972
flickerstreak@1 973 registeringFromAceEvent = true
flickerstreak@1 974 self:RegisterEvent("LOOT_OPENED", function()
flickerstreak@1 975 SendAddonMessage("LOOT_OPENED", "", "RAID")
flickerstreak@1 976 end)
flickerstreak@1 977 registeringFromAceEvent = nil
flickerstreak@1 978
flickerstreak@22 979 local function handleFullInit()
flickerstreak@22 980 if not self.postInit then
flickerstreak@22 981 local function func()
flickerstreak@22 982 self.postInit = true
flickerstreak@22 983 self:TriggerEvent("AceEvent_FullyInitialized")
flickerstreak@22 984 if self.registry["CHAT_MSG_CHANNEL_NOTICE"] and self.registry["CHAT_MSG_CHANNEL_NOTICE"][self] then
flickerstreak@22 985 self:UnregisterEvent("CHAT_MSG_CHANNEL_NOTICE")
flickerstreak@22 986 end
flickerstreak@22 987 if self.registry["MEETINGSTONE_CHANGED"] and self.registry["MEETINGSTONE_CHANGED"][self] then
flickerstreak@22 988 self:UnregisterEvent("MEETINGSTONE_CHANGED")
flickerstreak@22 989 end
flickerstreak@22 990 if self.registry["MINIMAP_ZONE_CHANGED"] and self.registry["MINIMAP_ZONE_CHANGED"][self] then
flickerstreak@22 991 self:UnregisterEvent("MINIMAP_ZONE_CHANGED")
flickerstreak@22 992 end
flickerstreak@22 993 if self.registry["LANGUAGE_LIST_CHANGED"] and self.registry["LANGUAGE_LIST_CHANGED"][self] then
flickerstreak@22 994 self:UnregisterEvent("LANGUAGE_LIST_CHANGED")
flickerstreak@22 995 end
flickerstreak@22 996 collectgarbage('collect')
flickerstreak@22 997 end
flickerstreak@22 998 registeringFromAceEvent = true
flickerstreak@22 999 local f = function()
flickerstreak@22 1000 self.playerLogin = true
flickerstreak@22 1001 self:ScheduleEvent("AceEvent_FullyInitialized", func, 1)
flickerstreak@22 1002 end
flickerstreak@22 1003 self:RegisterEvent("MEETINGSTONE_CHANGED", f, true)
flickerstreak@22 1004 self:RegisterEvent("CHAT_MSG_CHANNEL_NOTICE", function()
flickerstreak@22 1005 self:ScheduleEvent("AceEvent_FullyInitialized", func, 0.15)
flickerstreak@22 1006 end)
flickerstreak@22 1007 self:RegisterEvent("LANGUAGE_LIST_CHANGED", function()
flickerstreak@22 1008 if self.registry["MEETINGSTONE_CHANGED"] and self.registry["MEETINGSTONE_CHANGED"][self] then
flickerstreak@22 1009 registeringFromAceEvent = true
flickerstreak@22 1010 self:UnregisterEvent("MEETINGSTONE_CHANGED")
flickerstreak@22 1011 self:RegisterEvent("MINIMAP_ZONE_CHANGED", fd, true)
flickerstreak@22 1012 registeringFromAceEvent = nil
flickerstreak@22 1013 end
flickerstreak@22 1014 end)
flickerstreak@22 1015 self:ScheduleEvent("AceEvent_FullyInitialized", func, 10)
flickerstreak@22 1016 registeringFromAceEvent = nil
flickerstreak@22 1017 end
flickerstreak@22 1018 end
flickerstreak@22 1019
flickerstreak@1 1020 if not self.playerLogin then
flickerstreak@1 1021 registeringFromAceEvent = true
flickerstreak@1 1022 self:RegisterEvent("PLAYER_LOGIN", function()
flickerstreak@1 1023 self.playerLogin = true
flickerstreak@22 1024 handleFullInit()
flickerstreak@22 1025 handleFullInit = nil
flickerstreak@22 1026 collectgarbage('collect')
flickerstreak@1 1027 end, true)
flickerstreak@1 1028 registeringFromAceEvent = nil
flickerstreak@22 1029 else
flickerstreak@22 1030 handleFullInit()
flickerstreak@22 1031 handleFullInit = nil
flickerstreak@1 1032 end
flickerstreak@22 1033
flickerstreak@22 1034 if not AceEvent20EditBox then
flickerstreak@22 1035 CreateFrame("Editbox", "AceEvent20EditBox")
flickerstreak@22 1036 end
flickerstreak@22 1037 local editbox = AceEvent20EditBox
flickerstreak@22 1038 function editbox:Execute(line)
flickerstreak@22 1039 local defaulteditbox = DEFAULT_CHAT_FRAME.editBox
flickerstreak@22 1040 self:SetAttribute("chatType", defaulteditbox:GetAttribute("chatType"))
flickerstreak@22 1041 self:SetAttribute("tellTarget", defaulteditbox:GetAttribute("tellTarget"))
flickerstreak@22 1042 self:SetAttribute("channelTarget", defaulteditbox:GetAttribute("channelTarget"))
flickerstreak@22 1043 self:SetText(line)
flickerstreak@22 1044 ChatEdit_SendText(self)
flickerstreak@22 1045 end
flickerstreak@22 1046 editbox:Hide()
flickerstreak@22 1047 _G["SLASH_IN1"] = "/in"
flickerstreak@22 1048 SlashCmdList["IN"] = function(msg)
flickerstreak@22 1049 local seconds, command, rest = msg:match("^([^%s]+)%s+(/[^%s]+)(.*)$")
flickerstreak@22 1050 seconds = tonumber(seconds)
flickerstreak@22 1051 if not seconds then
flickerstreak@22 1052 DEFAULT_CHAT_FRAME:AddMessage("Error, bad arguments to /in. Must be in the form of `/in 5 /say hi'")
flickerstreak@22 1053 return
flickerstreak@1 1054 end
flickerstreak@22 1055 if IsSecureCmd(command) then
flickerstreak@22 1056 DEFAULT_CHAT_FRAME:AddMessage(("Error, /in cannot call secure command: %s"):format(command))
flickerstreak@22 1057 return
flickerstreak@1 1058 end
flickerstreak@22 1059 self:ScheduleEvent("AceEventSlashIn-" .. math.random(1, 1000000000), editbox.Execute, seconds, editbox, command .. rest)
flickerstreak@1 1060 end
flickerstreak@22 1061 registeringFromAceEvent = true
flickerstreak@22 1062 self:RegisterEvent("PLAYER_REGEN_ENABLED")
flickerstreak@22 1063 self:RegisterEvent("PLAYER_REGEN_DISABLED")
flickerstreak@22 1064 inCombat = InCombatLockdown()
flickerstreak@22 1065 registeringFromAceEvent = nil
flickerstreak@22 1066
flickerstreak@22 1067 -- another hack to make sure that we clean up properly from rev 33121 - 36174
flickerstreak@22 1068 if self.registry[ALL_EVENTS] then
flickerstreak@22 1069 self.frame:RegisterAllEvents()
flickerstreak@22 1070 else
flickerstreak@22 1071 for event in pairs(self.registry) do
flickerstreak@22 1072 self.frame:RegisterEvent(event)
flickerstreak@22 1073 end
flickerstreak@22 1074 end
flickerstreak@22 1075
flickerstreak@1 1076 self:activate(oldLib, oldDeactivate)
flickerstreak@1 1077 if oldLib then
flickerstreak@1 1078 oldDeactivate(oldLib)
flickerstreak@1 1079 end
flickerstreak@1 1080 end
flickerstreak@1 1081
flickerstreak@1 1082 AceLibrary:Register(AceEvent, MAJOR_VERSION, MINOR_VERSION, activate)