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.
59 lines
2.0 KiB
59 lines
2.0 KiB
--[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
|
|
local ____exports = {}
|
|
local _, _Mekanome = ...
|
|
local Mekanome = _Mekanome
|
|
local events = {}
|
|
local frame = CreateFrame("Frame")
|
|
frame:SetScript(
|
|
"OnEvent",
|
|
function(f, event, ...)
|
|
local args = {...}
|
|
local callbacks = events[event]
|
|
if callbacks then
|
|
for ____, cb in pairs(callbacks) do
|
|
cb(nil, args)
|
|
end
|
|
end
|
|
end
|
|
)
|
|
--- Registers an event to listen to.
|
|
--
|
|
-- @param event The name of the wow event.
|
|
-- @param callback The function to call when the event triggers.
|
|
-- @param id The ID specific to this callback, so that multiple handlers can be added per event.
|
|
local function RegisterEventHandler(event, callback, id)
|
|
local existingHandlers = events[event]
|
|
if existingHandlers then
|
|
if existingHandlers[id] ~= nil then
|
|
return
|
|
end
|
|
existingHandlers[id] = callback
|
|
events[event] = existingHandlers
|
|
else
|
|
frame:RegisterEvent(event)
|
|
local handlers = {}
|
|
handlers[id] = callback
|
|
events[event] = handlers
|
|
Mekanome.Print({text = event, prefix = "Registered", level = "info"})
|
|
end
|
|
end
|
|
--- Unregisters a Wow event handler.
|
|
--
|
|
-- @param event The event to unregister from.
|
|
-- @param id The ID of the handler to unregister.
|
|
local function UnregisterEventHandler(event, id)
|
|
local handlers = events[event]
|
|
if handlers and handlers[id] ~= nil then
|
|
handlers[id] = nil
|
|
Mekanome.Print({text = (("Event: " .. event) .. " | ID: ") .. id, prefix = "Handler", level = "error"})
|
|
end
|
|
if handlers and next(handlers) == nil == true then
|
|
events[event] = nil
|
|
frame:UnregisterEvent(event)
|
|
Mekanome.Print({text = event, prefix = "Event", level = "error"})
|
|
end
|
|
end
|
|
local _EventManager = {RegisterEventHandler = RegisterEventHandler, UnregisterEventHandler = UnregisterEventHandler}
|
|
Mekanome.EventManager = _EventManager
|
|
____exports.default = {}
|
|
return ____exports
|
|
|