59 lines
1.5 KiB
Lua
59 lines
1.5 KiB
Lua
local lib = LibStub:NewLibrary("LibCombatLog_data", 1)
|
|
if not lib then return end
|
|
local LibGUID = LibStub("LibGUID"):Embed()
|
|
local mixins = {'CreateDataObject'}
|
|
local data_methods = data_methods or {}
|
|
lib.mixinTargets = lib.mixinTargets or {}
|
|
function lib:CreateDataObject(data, prefix, suffix)
|
|
if(data) then
|
|
if(not prefix or not suffix) then
|
|
prefix, suffix = unpack(LibStub("LibCombatLog"):SplitCLEvent(data[3]))
|
|
end
|
|
data['prefix'] = prefix
|
|
data['suffix'] = suffix
|
|
for k, v in pairs(data_methods) do
|
|
data[k] = v
|
|
end
|
|
end
|
|
end
|
|
function data_methods:Get(key)
|
|
return self['db'][key]
|
|
end
|
|
function data_methods:Set(key, value)
|
|
self['db'][key] = value
|
|
end
|
|
function data_methods:HasSource()
|
|
return LibGUID:IsGUID(self[5])
|
|
end
|
|
function data_methods:HasDestination()
|
|
return LibGUID:IsGUID(self[9])
|
|
end
|
|
function data_methods:HasExtraSource()
|
|
return LibGUID:IsGUID(self[16])
|
|
end
|
|
function data_methods:GetSource()
|
|
if(self:HasSource()) then
|
|
return { self[5], self[6], self[7] }
|
|
end
|
|
end
|
|
function data_methods:GetDestination()
|
|
if(self:HasDestination()) then
|
|
return { self[9], self[10], self[11] }
|
|
end
|
|
end
|
|
function data_methods:GetExtraSource()
|
|
if(self:HasExtraSource()) then
|
|
return { self[16], self[17], self[18] }
|
|
end
|
|
end
|
|
function lib:Embed(target)
|
|
target = target or CreateFrame("FRAME")
|
|
for _,name in pairs(mixins) do
|
|
target[name] = lib[name]
|
|
end
|
|
lib.mixinTargets[target] = true
|
|
return target
|
|
end
|
|
for target, _ in pairs(lib.mixinTargets) do
|
|
lib:Embed(target)
|
|
end |