43 lines
1.1 KiB
Lua
43 lines
1.1 KiB
Lua
|
local _, addon = ...
|
||
|
|
||
|
local function ClearNumberStringMarks(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
|
||
|
|
||
|
local function ColorSpellNames(text, color)
|
||
|
return text:gsub("%[(.-)%]", function(match)
|
||
|
return string.format("|c%s[%s]|r", color or "FF0000FF", match)
|
||
|
end)
|
||
|
end
|
||
|
addon.API.ColorSpellNames = ColorSpellNames
|