Add coloring to riochecker

This commit is contained in:
2024-06-05 17:29:21 +02:00
parent 69278e7736
commit 312cff3f68
3 changed files with 139 additions and 11 deletions

View File

@@ -3,6 +3,117 @@ aura_env.reading = false
aura_env.fullMessage = {}
aura_env.displayString = ""
---@class ScoreColorer
---@field colors table<number, Color>
---@field breakpoints table<number>
aura_env.ScoreColorer = {
--- Make sure colors and breakpoints always have the same number of entries! VERY IMPORTANT!
---@type table<number, Color>
colors = {
{ r = 0.62, g = 0.62, b = 0.62 }, -- Grey
{ r = 1, g = 1, b = 1 }, -- White
{ r = 0.12, g = 1, b = 0 }, -- Green
{ r = 0, g = 0.44, b = 0.87 }, -- Blue
{ r = 0.64, g = 0.21, b = 0.93 }, -- Purple
{ r = 1, g = 0.5, b = 0 }, -- Orange
{ r = 1, g = 0.2, b = 0.23 },
{ r = 0, g = 0.8, b = 1.0 }, -- Blizzard Blue
},
breakpoints = { 0, 100, 200, 300, 400, 550, 750, 9999 },
---@param value number
---@return Color, nil|string
Interpolate = function(value)
local color = { r = 0, g = 0, b = 0 }
---@type table<number, table<number, number>>
local bracket = { { 0, 0 }, { 1, 1 } }
for i = 1, #aura_env.ScoreColorer.breakpoints do
if value < aura_env.ScoreColorer.breakpoints[i] then
bracket[2] = { i, aura_env.ScoreColorer.breakpoints[i] }
break
end
bracket[1] = { i, aura_env.ScoreColorer.breakpoints[i] }
end
---@type Color
local startColor = aura_env.ScoreColorer.colors[bracket[1][1]]
---@type Color
local endColor = aura_env.ScoreColorer.colors[bracket[2][1]]
local fraction = (value - bracket[1][2]) / (bracket[2][2] - bracket[1][2])
for k, v in pairs(startColor) do
color[k] = aura_env.ScoreColorer.lerp(v, endColor[k], fraction)
end
return color, nil
end,
---@param a number
---@param b number
---@param t number
---@return number
lerp = function(a, b, t)
return a * (1 - t) + b * t
end
}
---@class KeyLevel
---@field colors table<number, Color>
---@field breakpoints table<number>
aura_env.KeyLevel = {
--- Make sure colors and breakpoints always have the same number of entries! VERY IMPORTANT!
---@type table<number, Color>
colors = {
{ r = 0.62, g = 0.62, b = 0.62 }, -- Grey
{ r = 1, g = 1, b = 1 }, -- White
{ r = 0.12, g = 1, b = 0 }, -- Green
{ r = 0, g = 0.44, b = 0.87 }, -- Blue
{ r = 0.64, g = 0.21, b = 0.93 }, -- Purple
{ r = 1, g = 0.5, b = 0 }, -- Orange
{ r = 1, g = 0.2, b = 0.23 },
{ r = 0, g = 0.8, b = 1.0 }, -- Blizzard Blue
},
breakpoints = { 1, 10, 15, 20, 25, 29, 33, 9999 },
---@param value number
---@return Color, nil|string
Interpolate = function(value)
local color = { r = 0, g = 0, b = 0 }
---@type table<number, table<number, number>>
local bracket = { { 0, 0 }, { 1, 1 } }
for i = 1, #aura_env.KeyLevel.breakpoints do
if value < aura_env.KeyLevel.breakpoints[i] then
bracket[2] = { i, aura_env.KeyLevel.breakpoints[i] }
break
end
bracket[1] = { i, aura_env.KeyLevel.breakpoints[i] }
end
---@type Color
local startColor = aura_env.KeyLevel.colors[bracket[1][1]]
---@type Color
local endColor = aura_env.KeyLevel.colors[bracket[2][1]]
local fraction = (value - bracket[1][2]) / (bracket[2][2] - bracket[1][2])
for k, v in pairs(startColor) do
color[k] = aura_env.KeyLevel.lerp(v, endColor[k], fraction)
end
return color, nil
end,
---@param a number
---@param b number
---@param t number
---@return number
lerp = function(a, b, t)
return a * (1 - t) + b * t
end
}
if not WeakAurasSaved.Cyka then WeakAurasSaved.Cyka = {} end
if not WeakAurasSaved.Cyka.MData then WeakAurasSaved.Cyka.MData = {} end
@@ -11,7 +122,7 @@ if not WeakAurasSaved.Cyka.MData then WeakAurasSaved.Cyka.MData = {} end
---@field role string
---@field level string
---@field time string
---@field score string
---@field score number
Key = {
---@return Key
---@param name string
@@ -23,14 +134,30 @@ Key = {
local self = setmetatable({}, {
__index = Key,
__tostring = function(self)
return string.format("%-30s %-8s %-8s %-10s %-10s", self.name, self.role, self.level, self.time, self.score)
local score = self.score
local keyLevel = tonumber(self.level:match("%d+$")) or 0
local formattedScore, err = aura_env.ScoreColorer.Interpolate(self.score)
if not err then
score = string.format("|cff%02x%02x%02x%d|r", formattedScore.r * 255, formattedScore.g * 255,
formattedScore.b * 255, self.score)
end
local formattedLevel, err = aura_env.KeyLevel.Interpolate(keyLevel)
if not err then
level = string.format("|cff%02x%02x%02x%s|r", formattedLevel.r * 255, formattedLevel.g * 255,
formattedLevel.b * 255, self.level)
end
return string.format("%-30s %-8s %-8s %-10s %-10s", self.name, self.role, level, self.time,
score)
end,
})
self.name = name
self.role = role
self.level = level
self.time = time
self.score = score
self.score = tonumber(score) or 0
return self
end,
---@return string