Code:
function()
local GetDpsForUnit = function(unitName)
return Details.UnitDamage(unitName) / Details.SegmentElapsedTime()
end
local GetDpsTable = function(unitNames)
local dpsTable = {}
for _, unitName in ipairs(unitNames) do
local dps = GetDpsForUnit(unitName)
table.insert(dpsTable, {name=unitName, dps=dps})
end
table.sort(dpsTable, function(a, b) return a.dps > b.dps end)
return dpsTable
end
local RoundDps = function(dps)
local roundedDps
if dps >= 1000 then
local numDecimalPlaces = 1
local mult = 10 ^ numDecimalPlaces
roundedDps = math.floor((dps / 1000) * mult + 0.5) / mult
else
roundedDps = math.floor(dps)
end
return roundedDps
end
local BuildGroupDpsText = function(dpsTable)
local text = ""
for rank, tableEntry in ipairs(dpsTable) do
local roundedDps = RoundDps(tableEntry.dps)
local dpsString = roundedDps
if tableEntry.dps >= 1000 then
dpsString = dpsString .. "K"
end
-- Hardcode the class icon for testing
local classIcon = "|TInterface\\Icons\\ClassIcon_Paladin:16:16|t" -- Test icon here
text = text .. rank .. ". " .. classIcon .. " " .. tableEntry.name .. ": " .. dpsString .. "\n"
end
return text
end
if not aura_env.last or aura_env.last < GetTime() - 0.5 then
aura_env.last = GetTime()
aura_env.cachedText = "No data"
local unitNames = Details.SegmentDamagingUnits()
if #unitNames > 0 then
local dpsTable = GetDpsTable(unitNames)
aura_env.cachedText = BuildGroupDpsText(dpsTable)
end
end
return aura_env.cachedText
end