Fix numbers in bubble text
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
ca7603458c
commit
269ab6486b
4 changed files with 63 additions and 66 deletions
|
@ -1,5 +1,27 @@
|
|||
local _, addon = ...
|
||||
|
||||
local function BuildIndex(text)
|
||||
local numberMarks = text:gsub("%d+%.?%d*", "#?")
|
||||
return numberMarks
|
||||
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
|
||||
|
@ -16,8 +38,13 @@ local function FillPlaceholders(text)
|
|||
end
|
||||
|
||||
local function GetSpeech(message)
|
||||
local speech = addon.data.speech[message];
|
||||
local index = BuildIndex(message)
|
||||
local speech = addon.data.speech[index];
|
||||
local text = speech and speech.text or nil
|
||||
return FillPlaceholders(text)
|
||||
if text then
|
||||
return FillPlaceholders(FillNumbers(text, message))
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
addon.API.GetSpeech = GetSpeech
|
Loading…
Add table
Add a link
Reference in a new issue