Refactor and improve encounter data handling and formatting
All checks were successful
forgejo/Czech Quests/addon/pipeline/head This commit looks good

This commit is contained in:
Roman Jaroš 2025-04-19 00:41:40 +02:00
parent a32b698ebf
commit f37808207e
8 changed files with 226 additions and 83 deletions

View file

@ -1,39 +1,13 @@
local _, addon = ...
local function ClearNumberStringMarks(text)
local function ClearStringFormatMarks(text)
-- Remove colors (|cffffff...)
text = text:gsub("|c%x%x%x%x%x%x%x%x", "")
-- Remove H marks
text = text:gsub("|H.-|h", "")
return text
end
local function FillNumbers(text, sourceText)
local numbers = {}
local currentIndex = 1
local source = ClearNumberStringMarks(sourceText)
for num in source:gmatch("(%d[%d,%.]*)") do
table.insert(numbers, num)
end
local replacedText = text:gsub("#%?", function()
local n = numbers[currentIndex]
currentIndex = currentIndex + 1
if n and source:match("%s+" .. n .. "%s+million") then
return n .. " mil."
elseif n and source:match("%s+" .. n .. "%s+million") then
return n .. " mil."
end
return n or "?"
end)
return replacedText
end
addon.API.FillNumbers = FillNumbers
addon.API.ClearStringFormatMarks = ClearStringFormatMarks
local function ColorSpellNames(text, color)
return text:gsub("%[(.-)%]", function(match)