forked from Lombra/Critline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBroker.lua
80 lines (73 loc) · 2.15 KB
/
Broker.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
local addonName, addon = ...
local L = addon.L
local LDB = LibStub("LibDataBroker-1.1")
local feeds = addon:NewModule("DataBroker")
local msgFormat = format("%s: %%s - %s: %%s", L["Normal"], L["Crit"])
for k, v in pairs(addon.trees) do
feeds[k] = LDB:NewDataObject("Critline "..v.label, {
type = "data source",
label = v.title,
icon = addon.trees[k].icon,
OnClick = function()
if IsShiftKeyDown() then
local normalRecord, critRecord = addon:GetHighest(k)
local normalSpell, critSpell
local spells = addon:GetSpellArray(k)
for i = 1, #spells do
local v = spells[i]
local normal = v.normal
if normal and normal.amount == normalRecord then
normalSpell = v.name
end
local crit = v.crit
if crit and crit.amount == critRecord then
critSpell = v.name
end
if (normalSpell or not normalRecord) and (critSpell or not normalRecord) then
break
end
end
local normal = normalSpell and format("%s (%s)", addon:ShortenNumber(normalRecord), normalSpell) or "-"
local crit = critSpell and format("%s (%s)", addon:ShortenNumber(critRecord), critSpell) or "-"
ChatFrame_OpenChat(format(msgFormat, normal, crit))
else
addon:OpenConfig()
end
end,
OnTooltipShow = function()
addon:ShowTooltip(k)
end
})
end
local function updateRecords(event, tree)
if not tree then
for k in pairs(feeds) do
updateRecords(event, k)
end
return
end
if addon.percharDB.profile[tree] then
local normal, crit = addon:GetHighest(tree)
feeds[tree].text = format("%s/%s", addon:ShortenNumber(normal), addon:ShortenNumber(crit))
end
end
local function onTreeStateChanged(event, tree, enabled)
if tree then
if enabled then
updateRecords(event, tree)
else
feeds[tree].text = L["n/a"]
end
else
for k in pairs(Critline.trees) do
onTreeStateChanged(nil, k, Critline.percharDB.profile[k])
end
end
end
function feeds:OnInitialize()
addon.RegisterCallback(feeds, "OnNewTopRecord", updateRecords)
addon.RegisterCallback(feeds, "FormatChanged", updateRecords)
addon.RegisterCallback(feeds, "OnTreeStateChanged", onTreeStateChanged)
updateRecords()
onTreeStateChanged()
end