Use CallbackHandler-1.0
This commit is contained in:
parent
11219e3ffe
commit
ac37d0f1b7
|
@ -1,3 +1,6 @@
|
|||
[submodule "LibStub"]
|
||||
path = LibStub
|
||||
url = https://git.grml.de/rilgamon/LibStub.git
|
||||
[submodule "CallbackHandler-1.0"]
|
||||
path = CallbackHandler-1.0
|
||||
url = https://git.grml.de/rilgamon/CallbackHandler-1.0.git
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Subproject commit f5358335353e48e96706dbbf4936b24eca0a3176
|
|
@ -1,12 +1,12 @@
|
|||
local lib = LibStub:NewLibrary("LibCombatLog", 18)
|
||||
local lib = LibStub:NewLibrary("LibCombatLog", 19)
|
||||
if not lib then return end
|
||||
if not lib['cb'] then
|
||||
lib['cb'] = LibStub("CallbackHandler-1.0"):New(lib)
|
||||
end
|
||||
local CombatLogGetCurrentEventInfo, pairs, unpack, type = CombatLogGetCurrentEventInfo, pairs, unpack, type
|
||||
lib.mixinTargets = lib.mixinTargets or {}
|
||||
local mixins = {"RegisterCLEvent", "UnRegisterCLEvent", "RegisterCLSuffix", "UnRegisterCLSuffix", "RegisterCLStatus", "UnRegisterCLStatus","SplitCLEvent"}
|
||||
lib['regs'] = lib['regs'] or {
|
||||
['PLAYER_REGEN'] = {},
|
||||
}
|
||||
lib['regs']['PLAYER_REGEN'] = lib['regs']['PLAYER_REGEN'] or {}
|
||||
|
||||
local allPrefix = {
|
||||
'SWING', 'RANGE', 'SPELL_PERIODIC', 'SPELL_BUILDING', 'SPELL', 'ENVIRONMENTAL', 'UNIT', 'PARTY', 'ENCHANT'
|
||||
}
|
||||
|
@ -41,21 +41,10 @@ local function OnEvent2(self, event)
|
|||
if(event == 'COMBAT_LOG_EVENT_UNFILTERED') then
|
||||
local data = { event, CombatLogGetCurrentEventInfo()}
|
||||
local prefix, suffix = unpack(splitEvent(data[3]))
|
||||
if(lib['regs'][data[3]]) then
|
||||
for k, v in pairs(lib['regs'][data[3]]) do
|
||||
k[v](k, data, prefix, suffix)
|
||||
end
|
||||
end
|
||||
if(suffix) then
|
||||
lib['regs'][suffix] = lib['regs'][suffix] or {}
|
||||
for k, v in pairs(lib['regs'][suffix]) do
|
||||
k[v](k, data, prefix, suffix)
|
||||
end
|
||||
end
|
||||
lib['cb']:Fire(data[3], data, prefix, suffix)
|
||||
lib['cb']:Fire(suffix, data, prefix, suffix)
|
||||
elseif(event == 'PLAYER_REGEN_DISABLED' or event == 'PLAYER_REGEN_ENABLED') then
|
||||
for k, v in pairs(lib['regs']['PLAYER_REGEN']) do
|
||||
k[v](k, event)
|
||||
end
|
||||
lib['cb']:Fire(event)
|
||||
else
|
||||
print('unknown',event)
|
||||
end
|
||||
|
@ -76,57 +65,47 @@ function lib:SplitCLEvent(event)
|
|||
return splitEvent(event)
|
||||
end
|
||||
function lib:RegisterCLSuffix(suffix, funcName)
|
||||
if(type(suffix) ~= "string" and funcName) then
|
||||
funcName = funcName or suffix[1]
|
||||
if(type(suffix) == "table") then
|
||||
for _,v in pairs(suffix) do
|
||||
self:RegisterCLSuffix(v, funcName)
|
||||
end
|
||||
else
|
||||
funcName = funcName or suffix
|
||||
lib['regs'][suffix] = lib['regs'][suffix] or {}
|
||||
lib['regs'][suffix][self] = funcName
|
||||
lib['RegisterCallback'](self, suffix, funcName)
|
||||
end
|
||||
end
|
||||
function lib:UnregisterCLSuffix(suffix)
|
||||
if(type(suffix) ~= "string" and funcName) then
|
||||
if(type(suffix) == "table") then
|
||||
for _,v in pairs(suffix) do
|
||||
self:UnregisterCLSuffix(v)
|
||||
end
|
||||
return
|
||||
else
|
||||
if(lib['regs'][suffix]) then
|
||||
lib['regs'][suffix][self] = nil
|
||||
end
|
||||
lib['UnregisterCallback'](self, suffix)
|
||||
end
|
||||
end
|
||||
function lib:RegisterCLEvent(event,funcName)
|
||||
if(type(event) ~= "string" and funcName) then
|
||||
funcName = funcName or event[1]
|
||||
function lib:RegisterCLEvent(event, funcName)
|
||||
if(type(event) == "table") then
|
||||
for _,v in pairs(event) do
|
||||
self:RegisterCLEvent(v, funcName)
|
||||
end
|
||||
else
|
||||
funcName = funcName or event
|
||||
lib['regs'][event] = lib['regs'][event] or {}
|
||||
lib['regs'][event][self] = funcName
|
||||
lib['RegisterCallback'](self, event, funcName)
|
||||
end
|
||||
end
|
||||
function lib:RegisterCLStatus(funcName)
|
||||
lib['regs']['PLAYER_REGEN'][self] = funcName
|
||||
lib['RegisterCallback'](self, 'PLAYER_REGEN', funcName)
|
||||
end
|
||||
function lib:UnregisterCLStatus()
|
||||
lib['regs']['PLAYER_REGEN'][self] = nil
|
||||
lib['UnregisterCallback'](self, 'PLAYER_REGEN')
|
||||
end
|
||||
function lib:UnregisterCLEvent(event)
|
||||
if(type(event) ~= "string" and funcName) then
|
||||
if(type(event) == "table") then
|
||||
for _,v in pairs(event) do
|
||||
self:UnregisterCLEvent(v)
|
||||
end
|
||||
return
|
||||
else
|
||||
if(lib['regs'][event]) then
|
||||
lib['regs'][event][self] = nil
|
||||
end
|
||||
lib['UnregisterCallback'](self, event)
|
||||
end
|
||||
end
|
||||
function lib:Embed(target)
|
||||
|
|
|
@ -2,5 +2,6 @@
|
|||
## Name: LibCombatlog
|
||||
## Description: Register combat events
|
||||
## X-Repository: https://git.grml.de/rilgamon/LibCombatlog.git
|
||||
LibStub/LibStub.lua
|
||||
LibStub\LibStub.lua
|
||||
CallbackHandler-1.0\CallbackHandler-1.0.xml
|
||||
LibCombatlog.lua
|
Loading…
Reference in New Issue