82 lines
2.6 KiB
Lua
82 lines
2.6 KiB
Lua
local NanamiDPS = NanamiDPS
|
|
local DataStore = NanamiDPS.DataStore
|
|
local L = NanamiDPS.L
|
|
|
|
local Activity = {}
|
|
|
|
function Activity:GetName()
|
|
return L["Activity"]
|
|
end
|
|
|
|
function Activity:GetBars(segment)
|
|
if not segment or not segment.data or not segment.data.activity then return {} end
|
|
|
|
local segDuration = segment.duration
|
|
if segDuration <= 0 then
|
|
segDuration = GetTime() - (segment.startTime or GetTime())
|
|
end
|
|
if segDuration <= 0 then segDuration = 1 end
|
|
|
|
local bars = {}
|
|
for name, entry in pairs(segment.data.activity) do
|
|
local class = DataStore:GetClass(name)
|
|
local r, g, b = NanamiDPS.GetClassColor(class)
|
|
if not NanamiDPS.validClasses[class] then
|
|
r, g, b = NanamiDPS.str2rgb(name)
|
|
r = r * 0.6 + 0.4
|
|
g = g * 0.6 + 0.4
|
|
b = b * 0.6 + 0.4
|
|
end
|
|
|
|
local activeTime = entry._activeTime or 0
|
|
local pct = segDuration > 0 and (activeTime / segDuration * 100) or 0
|
|
pct = math.min(pct, 100)
|
|
|
|
table.insert(bars, {
|
|
id = name,
|
|
name = name,
|
|
value = pct,
|
|
class = class,
|
|
r = r, g = g, b = b,
|
|
valueText = NanamiDPS.round(pct, 1) .. "% (" .. NanamiDPS.formatTime(activeTime) .. ")",
|
|
activeTime = activeTime,
|
|
})
|
|
end
|
|
|
|
table.sort(bars, function(a, b) return a.value > b.value end)
|
|
|
|
return bars
|
|
end
|
|
|
|
function Activity:GetTooltip(playerName, segment, tooltip)
|
|
if not segment or not segment.data.activity[playerName] then return end
|
|
local entry = segment.data.activity[playerName]
|
|
|
|
local segDuration = segment.duration
|
|
if segDuration <= 0 then
|
|
segDuration = GetTime() - (segment.startTime or GetTime())
|
|
end
|
|
if segDuration <= 0 then segDuration = 1 end
|
|
|
|
local activeTime = entry._activeTime or 0
|
|
local pct = math.min(activeTime / segDuration * 100, 100)
|
|
|
|
tooltip:AddLine("|cffffd100" .. playerName)
|
|
tooltip:AddDoubleLine("|cffffffff" .. L["Activity"], "|cffffffff" .. NanamiDPS.round(pct, 1) .. "%")
|
|
tooltip:AddDoubleLine("|cffffffff" .. L["Active Time"], "|cffffffff" .. NanamiDPS.formatTime(activeTime))
|
|
tooltip:AddDoubleLine("|cffffffff" .. L["Fight Duration"], "|cffffffff" .. NanamiDPS.formatTime(segDuration))
|
|
end
|
|
|
|
function Activity:GetReportLines(segment, count)
|
|
local bars = self:GetBars(segment)
|
|
local lines = {}
|
|
count = count or 5
|
|
for i = 1, math.min(count, table.getn(bars)) do
|
|
local d = bars[i]
|
|
table.insert(lines, string.format("%d. %s - %.1f%% active", i, d.name, d.value))
|
|
end
|
|
return lines
|
|
end
|
|
|
|
NanamiDPS:RegisterModule("Activity", Activity)
|