Merge pull request #300 from argonui/stat-counter

Chaos Token Stat Tracker: sorted printing
This commit is contained in:
Chr1Z 2023-06-13 12:06:23 +02:00 committed by GitHub
commit 656764e174
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -122,6 +122,7 @@ function onLoad(savedData)
if obj ~= nil then obj.interactable = false end
end
resetChaosTokenStatTracker()
getModVersion()
math.randomseed(os.time())
end
@ -353,42 +354,67 @@ end
-- Left-click: print stats, Right-click: reset stats
function handleStatTrackerClick(_, _, isRightClick)
if isRightClick then
for key, _ in pairs(tokenDrawingStats) do
tokenDrawingStats[key] = {}
end
resetChaosTokenStatTracker()
else
local squidKing = "Nobody"
local maxSquid = 0
local playerColor, playerName
for key, personalStats in pairs(tokenDrawingStats) do
if personalStats ~= {} then
if key == "Overall" then
playerColor = "White"
playerName = "Overall"
else
playerColor = playmatApi.getPlayerColor(MAT_GUID_TO_COLOR[key])
playerName = Player[playerColor].steam_name or playerColor
local foundAnyStats = false
local playerSquidCount = personalStats["Auto-fail"] or 0
if playerSquidCount > maxSquid then
squidKing = playerName
maxSquid = playerSquidCount
end
for key, personalStats in pairs(tokenDrawingStats) do
local playerColor, playerName
if key == "Overall" then
playerColor = "White"
playerName = "Overall"
else
playerColor = playmatApi.getPlayerColor(MAT_GUID_TO_COLOR[key])
playerName = Player[playerColor].steam_name or playerColor
local playerSquidCount = personalStats["Auto-fail"]
if playerSquidCount > maxSquid then
squidKing = playerName
maxSquid = playerSquidCount
end
end
-- get the total count of drawn tokens for the player
local totalCount = 0
for tokenName, value in pairs(personalStats) do
totalCount = totalCount + value
end
-- only print the personal stats if any tokens were drawn
if totalCount > 0 then
foundAnyStats = true
printToAll("------------------------------")
printToAll(playerName .. " Stats", playerColor)
for tokenName, value in pairs(personalStats) do
if value then
if value ~= 0 then
printToAll(tokenName .. ': ' .. tostring(value))
end
end
printToAll('Total: ' .. tostring(totalCount))
end
end
printToAll("------------------------------")
printToAll(squidKing .. " is an auto-fail magnet.", {255, 0, 0})
-- detect if any player drew tokens
if foundAnyStats then
printToAll("------------------------------")
printToAll(squidKing .. " is an auto-fail magnet.", {255, 0, 0})
else
printToAll("No tokens have been drawn yet.", "Yellow")
end
end
end
-- resets the count for each token to 0
function resetChaosTokenStatTracker()
for key, _ in pairs(tokenDrawingStats) do
tokenDrawingStats[key] = {}
for _, token in pairs(ID_URL_MAP) do
tokenDrawingStats[key][token.name] = 0
end
end
end