addon/Addon/Code/SpeechDataApi.lua

50 lines
1.2 KiB
Lua
Raw Normal View History

local _, addon = ...
2025-03-10 13:32:44 +01:00
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
end
local playerName = UnitName("player")
local formatted = text;
formatted = string.gsub(formatted, '<name>', playerName);
formatted = string.gsub(formatted, 'Champions', playerName);
formatted = string.gsub(formatted, 'champions', playerName);
return formatted
end
local function GetSpeech(message)
2025-03-10 13:32:44 +01:00
local index = BuildIndex(message)
local speech = addon.data.speech[index];
local text = speech and speech.text or nil
2025-03-10 13:32:44 +01:00
if text then
return FillPlaceholders(FillNumbers(text, message))
else
return nil
end
end
addon.API.GetSpeech = GetSpeech