Skip to content

Commit

Permalink
Add LuaLS types to ProcessText
Browse files Browse the repository at this point in the history
  • Loading branch information
raethkcj committed Dec 1, 2024
1 parent 574604d commit 10d0e84
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
10 changes: 8 additions & 2 deletions RatingBuster.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2192,6 +2192,11 @@ end

local escaped_large_number_sep = LARGE_NUMBER_SEPERATOR:gsub("[-.]", "%%%1")

---@param text string
---@param link string
---@param color ColorMixin
---@param statModContext StatModContext
---@return string
function RatingBuster:ProcessText(text, link, color, statModContext)
-- Convert text to lower so we don't have to worry about same ratings with different cases
local lowerText = text:lower()
Expand All @@ -2203,6 +2208,7 @@ function RatingBuster:ProcessText(text, link, color, statModContext)
-- Capture the stat name
for _, statPattern in ipairs(L["statList"]) do
local pattern, stat = unpack(statPattern)
---@cast pattern string
if lowerText:find(pattern) then
value = value:gsub(escaped_large_number_sep, "")
value = tonumber(value)
Expand All @@ -2212,7 +2218,7 @@ function RatingBuster:ProcessText(text, link, color, statModContext)
local effects = {}
-- Group effects with identical values
for statID, effect in pairs(infoTable) do
if type(statID) == "table" and statID.isPercent or statID == "Spell" then
if type(statID) == "table" and statID.isPercent or statID == "Spell" then
effect = ("%+.2f"):format(effect):gsub("(%.%d-)0+$", "%1"):trim(".") .. "%"
effects[effect] = effects[effect] or {}
tinsert(effects[effect], S[statID])
Expand Down Expand Up @@ -2756,7 +2762,7 @@ EventUtil.ContinueOnAddOnLoaded("Blizzard_ReforgingUI", function()
profile = db:GetCurrentProfile(),
spec = RatingBuster:GetDisplayedSpec()
})
og_SetText(self, RatingBuster:ProcessText(text, nil, nil, statModContext), ...)
og_SetText(self, RatingBuster:ProcessText(text, "", {}, statModContext), ...)
end
end

Expand Down
12 changes: 2 additions & 10 deletions libs/StatLogic/StatLogic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -186,19 +186,11 @@ local function newPooledTable(...)
end

-- New stat table
local function newStatTable(...)
---@return StatTable
local function newStatTable()
local t = next(pool) or {}
pool[t] = nil
setmetatable(t, statTableMetatable)

for i = 1, select('#', ...), 2 do
local k = select(i, ...)
if k then
t[k] = select(i+1, ...)
else
break
end
end
return t
end

Expand Down

0 comments on commit 10d0e84

Please sign in to comment.