local QuestTextMethod = { Description = GetQuestText, Objective = GetObjectiveText, }; local function GetQuestText(method) local text = QuestTextMethod[method](); if text then return text else return "" end end local function GetQuestLogQuestIndex(questID) local numEntries = C_QuestLog.GetNumQuestLogEntries() for questLogIndex = 1, numEntries do local info = C_QuestLog.GetInfo(questLogIndex) if info and info.questID == questID then return questLogIndex end end return nil end local function ApplyQuestPlaceholders(text) if text == nil then return text end local playerName = UnitName("player") local _, playerClass = UnitClass("player") local _, playerRace = UnitRace("player") local class = CzechQuestsAddon:GetData("class", playerClass); local race = CzechQuestsAddon:GetData("race", playerRace); local formatted = text; formatted = string.gsub(formatted, '', playerName); formatted = string.gsub(formatted, '', class.f0); formatted = string.gsub(formatted, '', class.f1); formatted = string.gsub(formatted, '', class.f2); formatted = string.gsub(formatted, '', class.f3); formatted = string.gsub(formatted, '', class.f4); formatted = string.gsub(formatted, '', class.f5); formatted = string.gsub(formatted, '', class.m0); formatted = string.gsub(formatted, '', class.m1); formatted = string.gsub(formatted, '', class.m2); formatted = string.gsub(formatted, '', class.m3); formatted = string.gsub(formatted, '', class.m4); formatted = string.gsub(formatted, '', class.p0); formatted = string.gsub(formatted, '', class.p1); formatted = string.gsub(formatted, '', class.m3); formatted = string.gsub(formatted, '', race.f0); formatted = string.gsub(formatted, '', race.f1); formatted = string.gsub(formatted, '', race.f2); formatted = string.gsub(formatted, '', race.f3); formatted = string.gsub(formatted, '', race.f4); formatted = string.gsub(formatted, '', race.f5); formatted = string.gsub(formatted, '', race.m0); formatted = string.gsub(formatted, '', race.m1); formatted = string.gsub(formatted, '', race.m2); formatted = string.gsub(formatted, '', race.m3); formatted = string.gsub(formatted, '', race.m4); formatted = string.gsub(formatted, '', race.p0); formatted = string.gsub(formatted, '', race.p1); formatted = string.gsub(formatted, '', race.p3); return formatted end local function TransformQuestText(text) return ApplyQuestPlaceholders(text) end local function ResolveGender(maleVersion, femaleVersion) local gender = UnitSex("player") if gender == 2 then return TransformQuestText(maleVersion) else return femaleVersion == nil and TransformQuestText(maleVersion) or TransformQuestText(femaleVersion) end end local function GetQuest(id) local quest = CzechQuestsAddon.data.quest[id]; if quest then local description = "" local objective = "" if QuestMapDetailsScrollFrame and QuestMapDetailsScrollFrame:IsVisible() then local index = GetQuestLogQuestIndex(id) description, objective = GetQuestLogQuestText(index) else description = GetQuestText("Description") objective = GetQuestText("Objective") end return { title = ResolveGender(quest.titleMale, quest.titleFemale), objective = CzechQuestsAddon:TransformIntoParagraphs( objective, ResolveGender(quest.objectiveMale, quest.objectiveFemale) ), description = CzechQuestsAddon:TransformIntoParagraphs( description, ResolveGender(quest.descriptionMale, quest.descriptionFemale) ), progress = ResolveGender(quest.progressMale, quest.progressFemale), completion = ResolveGender(quest.completionMale, quest.completionFemale), } end end local function ApplySpeechPlaceholders(text) if text == nil then return text end local playerName = UnitName("player") local formatted = text; formatted = string.gsub(formatted, '', playerName); formatted = string.gsub(formatted, 'Champions', playerName); return formatted end local function GetSpeech(message) local speech = CzechQuestsAddon.data.speech[message]; local text = speech and speech.text or nil return ApplySpeechPlaceholders(text) end function CzechQuestsAddon:GetData(key, id) if CzechQuestsAddon.data[key] then if key == "quest" then return GetQuest(id) elseif key == "speech" then return GetSpeech(id) elseif CzechQuestsAddon.data[key][id] then return CzechQuestsAddon.data[key][id] end end return nil end