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