Compare with Previous | Blame | View Log
local wombat = LibStub:NewLibrary("LibWombat",20080809); if (not wombat) then LIBWOMBAT_GLOBAL = {}; local wombat = LIBWOMBAT_GLOBAL; end ---------------------------------------------------------------------------------------------------- local watcher = getglobal("LibWombatWatcherFrame") or CreateFrame("Frame","LibWombatWatcherFrame"); watcher:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED"); wombat.parser = wombat.parser or {}; local CleanParser = function() for event,list in pairs(wombat.parser) do local exists = false; for serial,callback in pairs(list) do exists = true; end if (not exists) then wombat.parser[event] = nil; end end end; wombat.StartParsing = function(self,event,method) if (type(event) ~= "string") or (type(method) ~= "function") then return; end wombat.parser[event] = wombat.parser[event] or {}; wombat.parser[event][self] = method; end; wombat.StopParsing = function(self,event) if (not wombat.parser[event]) then return; end wombat.parser[event][self] = nil; CleanParser(); end; wombat.StopAllParsing = function(self) for event,list in pairs(wombat.parser) do if (list[self]) then wombat.parser[event][self] = nil; end end CleanParser(); end; ---------------------------------------------------------------------------------------------------- function wombat:NewParser(target) target.StartParsing = wombat.StartParsing; target.StopParsing = wombat.StopParsing; target.StopAllParsing = wombat.StopAllParsing; end ---------------------------------------------------------------------------------------------------- watcher:SetScript("OnEvent",function(__,event,when,what,srcGUID,srcNAME,srcFLAGS,destGUID,destNAME,destFLAGS,...) if (event == "COMBAT_LOG_EVENT_UNFILTERED") then if (wombat.parser[what]) then for k,callback in pairs(wombat.parser[what]) do callback(when,what,srcGUID,srcNAME,srcFLAGS,destGUID,destNAME,destFLAGS,...); end end end end); ---------------------------------------------------------------------------------------------------- --[[ some usage examples local MyAddon = {}; wombat:NewParser(MyAddon); MyAddon:StartParsing("SWING_DAMAGE",function(when,what,sGUID,sNAME) DEFAULT_CHAT_FRAME:AddMessage("SWING_DAMAGE ("..sNAME..")"); end); ]]