Skip to content

Commit 20dcae1

Browse files
committed
Top Character statistic
1 parent 4ce2771 commit 20dcae1

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

RepHub.lua

+29-1
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,33 @@ function RepHub:GetFactionAdditionalInfo(factionName)
420420
return factionAdditionalInfo
421421
end
422422

423+
function RepHub:GetTopCharacter()
424+
local topCharacterTable, topCharacterName, topCharacterReputationsCount = {}, "", 0
425+
table.foreach(
426+
self.db.global.reputationList,
427+
function(_, factionData)
428+
table.foreach(
429+
factionData.standings,
430+
function(characterName, standing)
431+
topCharacterTable[characterName] = (topCharacterTable[characterName] or 0) + 1
432+
end
433+
)
434+
end
435+
)
436+
437+
table.foreach(
438+
topCharacterTable,
439+
function(characterName, reputationsCount)
440+
if reputationsCount > topCharacterReputationsCount then
441+
topCharacterName = characterName
442+
topCharacterReputationsCount = reputationsCount
443+
end
444+
end
445+
)
446+
447+
return topCharacterName, topCharacterReputationsCount
448+
end
449+
423450
-- GUI
424451

425452
function RepHub:CreateRepHubFrame()
@@ -464,7 +491,8 @@ function RepHub:CreateRepHubFrame()
464491
-- Stats
465492
local StatsLabel = AceGUI:Create("Label")
466493
StatsLabel:SetFullWidth(true)
467-
StatsLabel:SetText("Total reputations: " .. RepHub:GetTableLength(self.db.global.reputationList) .. " | Total characters: " .. #self.db.global.characterNames)
494+
local topCharacterName, topCharacterReputationsCount = RepHub:GetTopCharacter()
495+
StatsLabel:SetText("Total reputations: " .. RepHub:GetTableLength(self.db.global.reputationList) .. " | Total characters: " .. #self.db.global.characterNames .. " | Top character: " .. topCharacterName .. " (" .. topCharacterReputationsCount .. ")")
468496
RepHubFrame:AddChild(StatsLabel)
469497

470498
-- Search

0 commit comments

Comments
 (0)