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

@ -6,6 +6,23 @@ local function BuildIndex(text)
return normalized
end
local function FillNumbers(text, sourceText)
local numbers = {}
local currentIndex = 1
for num in sourceText:gmatch("%d+%.?%d*") do
table.insert(numbers, num)
end
local replacedText = text:gsub("#%?", function()
local n = numbers[currentIndex]
currentIndex = currentIndex + 1
return n or "?"
end)
return replacedText
end
local function FillPlaceholders(text)
if text == nil then
return text
@ -24,9 +41,7 @@ local function GetSpeech(message)
local speech = addon.data.speech[index];
local text = speech and speech.m or nil
if text then
return FillPlaceholders(
addon.API.FillNumbers(text, message)
)
return FillPlaceholders(FillNumbers(text, message))
else
return nil
end