Refactor encounter handling and placeholder logic
All checks were successful
forgejo/Czech Quests/addon/pipeline/head This commit looks good
All checks were successful
forgejo/Czech Quests/addon/pipeline/head This commit looks good
This commit is contained in:
parent
c2eda51d7d
commit
a32b698ebf
10 changed files with 278 additions and 421 deletions
43
Addon/Code/Shared.lua
Normal file
43
Addon/Code/Shared.lua
Normal file
|
@ -0,0 +1,43 @@
|
|||
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
|
Loading…
Add table
Add a link
Reference in a new issue