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
|
@ -6,23 +6,6 @@ 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
|
||||
|
@ -41,7 +24,9 @@ local function GetSpeech(message)
|
|||
local speech = addon.data.speech[index];
|
||||
local text = speech and speech.m or nil
|
||||
if text then
|
||||
return FillPlaceholders(FillNumbers(text, message))
|
||||
return FillPlaceholders(
|
||||
addon.API.FillNumbers(text, message)
|
||||
)
|
||||
else
|
||||
return nil
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue