addon/Addon/Code/SpeechDataApi.lua
Roman Jaroš d1fa5a6bc7
All checks were successful
forgejo/Czech Quests/addon/pipeline/head This commit looks good
Remove responsive speech frame width, fix generator
2025-03-20 20:18:54 +01:00

49 lines
No EOL
1.1 KiB
Lua
Executable file

local _, addon = ...
local function BuildIndex(text)
local numberMarks = text:gsub("%d+%.?%d*", "#?")
local normalized = numberMarks:gsub('"', "'")
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
end
local playerName = UnitName("player")
local formatted = text;
formatted = string.gsub(formatted, '<name>', playerName);
return formatted
end
local function GetSpeech(message)
local index = BuildIndex(message)
local speech = addon.data.speech[index];
local text = speech and speech.text or nil
if text then
return FillPlaceholders(FillNumbers(text, message))
else
return nil
end
end
addon.API.GetSpeech = GetSpeech