Optimized EventManager?

main
ck 11 months ago
parent fae22d9edc
commit 4a718db43c
  1. 45
      src/EventManager/EventManager.lua

@ -16,8 +16,12 @@ local EventManager = {
events = {}, events = {},
eventHandlers = {}, eventHandlers = {},
wowEventHandlers = {}, wowEventHandlers = {},
selfCombatEventHandlers = {}, selfCombatEventHandlers = {
CombatEventHandlers = {}, ["*"] = {},
},
CombatEventHandlers = {
["*"] = {},
},
} }
EventManager.__index = EventManager EventManager.__index = EventManager
@ -117,18 +121,35 @@ function EventManager:RegisterCombatEvent(subevents, handler)
end end
end end
---@param timestamp number
---@param subevent string
---@param ... any ---@param ... any
function EventManager:CLEUHandler(timestamp, subevent, ...) function EventManager:CLEUHandler(...)
if self.selfCombatEventHandlers[subevent] and self.playerGUID and select(2, ...) == self.playerGUID then ---@type number
for _, callback in ipairs(self.selfCombatEventHandlers[subevent]) do local timestamp = select(1, ...)
callback(timestamp, subevent, ...) ---@type string
local subevent = select(2, ...)
---@type string
local sourceGUID = select(4, ...)
---@type string
local destGUID = select(8, ...)
local keys = {
subevent,
"*"
}
local isSelf = self.playerGUID and sourceGUID == self.playerGUID
for _, key in ipairs(keys) do
if isSelf then
if self.selfCombatEventHandlers[key] then
for _, callback in ipairs(self.selfCombatEventHandlers[key]) do
callback(timestamp, subevent, ...)
end
end
end end
end if self.CombatEventHandlers[key] then
if self.CombatEventHandlers[subevent] then for _, callback in ipairs(self.CombatEventHandlers[key]) do
for _, callback in ipairs(self.CombatEventHandlers[subevent]) do callback(timestamp, subevent, ...)
callback(timestamp, subevent, ...) end
end end
end end
end end

Loading…
Cancel
Save