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
|
@ -24,6 +24,8 @@ local TAG_TO_ICON = {
|
|||
enrage = 11
|
||||
}
|
||||
|
||||
local ORIGINALS = {}
|
||||
|
||||
local function HideOtherContent()
|
||||
local frames = { "overviewScroll", "LootContainer", 'detailsScroll', 'model' }
|
||||
for _, frame in ipairs(frames) do
|
||||
|
@ -67,15 +69,6 @@ local function SetAbilityIcon(header, tags)
|
|||
EncounterJournal_SetFlagIcon(tex, index)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
||||
local function ColorSpellNames(text, color)
|
||||
return text:gsub("%[(.-)%]", function(match)
|
||||
return string.format("|c%s[%s]|r", color or "FF0000FF", match)
|
||||
end)
|
||||
end
|
||||
|
||||
local function RenderBossAbilities(data, parent, layer)
|
||||
|
@ -86,10 +79,10 @@ local function RenderBossAbilities(data, parent, layer)
|
|||
end
|
||||
|
||||
for _, node in ipairs(data) do
|
||||
local abilityValue = addon.API.ResolveGender(addon.API.GetEncounterAbility(node.key))
|
||||
local abilityValue = addon.API.GetEncounterAbility(node.key)
|
||||
|
||||
if abilityValue then
|
||||
local abilityParts = addon.API.SplitAbilityParts(abilityValue, "|")
|
||||
local abilityParts = addon.API.ParseAbilities(abilityValue, "|")
|
||||
local name = abilityParts[1]
|
||||
local tag = abilityParts[3]
|
||||
local description = abilityParts[5]
|
||||
|
@ -104,7 +97,7 @@ local function RenderBossAbilities(data, parent, layer)
|
|||
end
|
||||
|
||||
header.description:SetWidth(header:GetWidth() - 20)
|
||||
header.description:SetText(description)
|
||||
header.description:SetText(addon.API.SetAbilityDescription(description, ORIGINALS[name]))
|
||||
if description == "" then header.empty = true end
|
||||
|
||||
table.insert(parent.children, header)
|
||||
|
@ -119,49 +112,34 @@ local function RenderBossAbilities(data, parent, layer)
|
|||
end
|
||||
end
|
||||
|
||||
local function RenderBossEncounter(bossName, bossKey)
|
||||
local function RenderBossEncounter(bossKey, bossName)
|
||||
local frame = addon.EncounterFrame
|
||||
HideOtherContent()
|
||||
|
||||
local bossData = CzechQuestsAddon:GetData('encounter', bossKey)
|
||||
|
||||
local function CreateHeaderDescription(data)
|
||||
local value = addon.API.ResolveGender(data)
|
||||
local result = {}
|
||||
for part in string.gmatch(value, "([^\n]+)") do
|
||||
table.insert(result, part)
|
||||
end
|
||||
local description = ""
|
||||
for i, part in pairs(result) do
|
||||
description = description
|
||||
.. "- "
|
||||
.. ColorSpellNames(part)
|
||||
.. (i == #result and "" or "\n\n")
|
||||
end
|
||||
return description
|
||||
end
|
||||
|
||||
frame.summary:SetText(
|
||||
ColorSpellNames(
|
||||
addon.API.ResolveGender(bossData.overview)
|
||||
)
|
||||
addon.API.SetAbilityDescription(bossData.overview, ORIGINALS['Overview'])
|
||||
)
|
||||
|
||||
local tankHeader = frame:CreateHeader()
|
||||
tankHeader.button.title:SetText("Tank")
|
||||
tankHeader.description:SetText(CreateHeaderDescription(bossData.tank))
|
||||
local tankDescription = addon.API.SetSummaryDescription(bossData.tank, ORIGINALS['Tanks'])
|
||||
tankHeader.description:SetText(tankDescription)
|
||||
table.insert(frame.headers, tankHeader)
|
||||
SetAbilityIcon(tankHeader, 'tank')
|
||||
|
||||
local healHeader = frame:CreateHeader()
|
||||
healHeader.button.title:SetText("Healer")
|
||||
healHeader.description:SetText(CreateHeaderDescription(bossData.healer))
|
||||
local healerDescription = addon.API.SetSummaryDescription(bossData.healer, ORIGINALS['Healers'])
|
||||
healHeader.description:SetText(healerDescription)
|
||||
table.insert(frame.headers, healHeader)
|
||||
SetAbilityIcon(healHeader, 'healer')
|
||||
|
||||
local dpsHeader = frame:CreateHeader()
|
||||
dpsHeader.button.title:SetText("Damage Dealer")
|
||||
dpsHeader.description:SetText(CreateHeaderDescription(bossData.dps))
|
||||
local dpsDescription = addon.API.SetSummaryDescription(bossData.dps, ORIGINALS['Damage Dealers'])
|
||||
dpsHeader.description:SetText(dpsDescription)
|
||||
table.insert(frame.headers, dpsHeader)
|
||||
SetAbilityIcon(dpsHeader, 'dps')
|
||||
|
||||
|
@ -169,16 +147,31 @@ local function RenderBossEncounter(bossName, bossKey)
|
|||
bossHeader.button.title:SetText(bossName)
|
||||
bossHeader.empty = true
|
||||
table.insert(frame.headers, bossHeader)
|
||||
|
||||
-- abilities
|
||||
RenderBossAbilities(bossData.abilities, bossHeader, 1)
|
||||
|
||||
frame:GetParent():Show()
|
||||
frame:UpdateHeaderPositions()
|
||||
end
|
||||
end
|
||||
|
||||
local function StoreBossAbilities()
|
||||
ORIGINALS = {}
|
||||
local stack, _, _, _, curSectionID = {}, EJ_GetEncounterInfo(ENCOUNTER_ID)
|
||||
repeat
|
||||
local info = C_EncounterJournal.GetSectionInfo(curSectionID)
|
||||
if not info.filteredByDifficulty then
|
||||
ORIGINALS[info.title] = info.description
|
||||
end
|
||||
table.insert(stack, info.siblingSectionID)
|
||||
if not info.filteredByDifficulty then
|
||||
table.insert(stack, info.firstChildSectionID)
|
||||
end
|
||||
curSectionID = table.remove(stack)
|
||||
until not curSectionID
|
||||
end
|
||||
|
||||
local function DetectBossToRender()
|
||||
local frame = addon.EncounterFrame
|
||||
|
||||
local encounterName = EJ_GetEncounterInfo(ENCOUNTER_ID)
|
||||
|
||||
local difficulty = 'lfg_raid' -- 17
|
||||
|
@ -196,14 +189,12 @@ local function DetectBossToRender()
|
|||
difficulty = 'mythic_dungeon'
|
||||
end
|
||||
|
||||
local bossName = nil
|
||||
local bossKey = nil
|
||||
for i = 1, 10 do
|
||||
local id, name = EJ_GetCreatureInfo(i);
|
||||
if id then
|
||||
local key = name .. "_" .. difficulty
|
||||
if addon.data.encounter[key] then
|
||||
bossName = name
|
||||
bossKey = key
|
||||
break
|
||||
end
|
||||
|
@ -211,7 +202,8 @@ local function DetectBossToRender()
|
|||
end
|
||||
|
||||
if bossKey then
|
||||
RenderBossEncounter(bossName, bossKey)
|
||||
StoreBossAbilities()
|
||||
RenderBossEncounter(bossKey, encounterName)
|
||||
end
|
||||
|
||||
if bossKey == nil then
|
||||
|
@ -220,11 +212,11 @@ local function DetectBossToRender()
|
|||
end
|
||||
end
|
||||
|
||||
local function HideEncounterFrame()
|
||||
local function HideEncounterContent()
|
||||
addon.EncounterFrame:GetParent():Hide()
|
||||
end
|
||||
|
||||
local function ShowEncounterFrame()
|
||||
local function ShowEncounterContent()
|
||||
CURRENT_TAB_ID = ENCOUNTER_TAB_ID
|
||||
HideOtherContent()
|
||||
|
||||
|
@ -240,7 +232,7 @@ end
|
|||
|
||||
local function SetupCustomTab()
|
||||
addon.EncounterFrame.tab:SetScript("OnClick", function()
|
||||
ShowEncounterFrame()
|
||||
ShowEncounterContent()
|
||||
end)
|
||||
|
||||
hooksecurefunc("EncounterJournal_DisplayEncounter", function(encounterID)
|
||||
|
@ -248,7 +240,7 @@ local function SetupCustomTab()
|
|||
addon.EncounterFrame.tab:SetActive(true);
|
||||
|
||||
if CURRENT_TAB_ID == ENCOUNTER_TAB_ID then
|
||||
ShowEncounterFrame()
|
||||
ShowEncounterContent()
|
||||
end
|
||||
end)
|
||||
|
||||
|
@ -263,19 +255,19 @@ local function SetupCustomTab()
|
|||
|
||||
PREVIOUS_TAB_ID = CURRENT_TAB_ID
|
||||
CURRENT_TAB_ID = tabId
|
||||
HideEncounterFrame()
|
||||
HideEncounterContent()
|
||||
end)
|
||||
|
||||
hooksecurefunc("EncounterJournalBossButton_OnClick", function(encounterID)
|
||||
if PREVIOUS_TAB_ID == ENCOUNTER_TAB_ID then
|
||||
ShowEncounterFrame()
|
||||
ShowEncounterContent()
|
||||
end
|
||||
end)
|
||||
|
||||
hooksecurefunc("EncounterJournal_UpdateDifficulty", function(difficulty)
|
||||
DIFFICULTY = difficulty
|
||||
if PREVIOUS_TAB_ID == ENCOUNTER_TAB_ID and ENCOUNTER_ID then
|
||||
ShowEncounterFrame()
|
||||
ShowEncounterContent()
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
@ -283,7 +275,6 @@ end
|
|||
local function InitEncounters()
|
||||
local frame = addon.EncounterFrame
|
||||
|
||||
-- Register EncounterJournal events
|
||||
frame:RegisterEvent("ADDON_LOADED")
|
||||
|
||||
frame:SetScript("OnEvent", function(self, event, addonName)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
local _, addon = ...
|
||||
|
||||
local function SplitAbilityParts(input, delimiter)
|
||||
local function ParseAbilities(input, delimiter)
|
||||
local result = {}
|
||||
local pattern = "([^" .. delimiter .. "]*)"
|
||||
local normalizedAbility = string.gsub(input, "||", "|???|")
|
||||
|
@ -17,21 +17,46 @@ local function SplitAbilityParts(input, delimiter)
|
|||
|
||||
return result
|
||||
end
|
||||
addon.API.SplitAbilityParts = SplitAbilityParts
|
||||
addon.API.ParseAbilities = ParseAbilities
|
||||
|
||||
local function SetAbilityDescription(text, original)
|
||||
local withNumbers = addon.API.FillNumbers(text, original)
|
||||
return addon.API.ColorSpellNames(withNumbers)
|
||||
end
|
||||
addon.API.SetAbilityDescription = SetAbilityDescription
|
||||
|
||||
local function SetSummaryDescription(text, original)
|
||||
local withNumbers = addon.API.FillNumbers(text, original)
|
||||
|
||||
local lines = {}
|
||||
for part in string.gmatch(withNumbers, "([^\n]+)") do
|
||||
table.insert(lines, part)
|
||||
end
|
||||
|
||||
local description = ""
|
||||
for i, line in pairs(lines) do
|
||||
description = description
|
||||
.. "- "
|
||||
.. addon.API.ColorSpellNames(line)
|
||||
.. (i == #lines and "" or "\n\n")
|
||||
end
|
||||
|
||||
return description
|
||||
end
|
||||
addon.API.SetSummaryDescription = SetSummaryDescription
|
||||
|
||||
local function GetEncounterAbility(abilityKey)
|
||||
return addon.data.encounter[abilityKey] or nil
|
||||
return addon.data.encounter[abilityKey].m or nil
|
||||
end
|
||||
addon.API.GetEncounterAbility = GetEncounterAbility
|
||||
|
||||
local function GetEncounter(bossKey)
|
||||
return {
|
||||
abilities = addon.data.encounter[bossKey] or nil,
|
||||
overview = addon.data.encounter[bossKey .. "_summary_instance"] or nil,
|
||||
tank = addon.data.encounter[bossKey .. "_summary_tank"] or nil,
|
||||
healer = addon.data.encounter[bossKey .. "_summary_healer"] or nil,
|
||||
dps = addon.data.encounter[bossKey .. "_summary_dps"] or nil,
|
||||
overview = addon.data.encounter[bossKey .. "_summary_instance"].m or nil,
|
||||
tank = addon.data.encounter[bossKey .. "_summary_tank"].m or nil,
|
||||
healer = addon.data.encounter[bossKey .. "_summary_healer"].m or nil,
|
||||
dps = addon.data.encounter[bossKey .. "_summary_dps"].m or nil,
|
||||
}
|
||||
end
|
||||
addon.API.GetEncounter = GetEncounter
|
|
@ -120,7 +120,7 @@ function EncounterFrame:CreateHeader()
|
|||
HeaderFrame.expanded = false
|
||||
HeaderFrame.empty = false
|
||||
|
||||
HeaderFrame.button.title:SetPoint("TOPLEFT", HeaderFrame, "TOPLEFT", 40, -7);
|
||||
HeaderFrame.button.title:SetPoint("TOPLEFT", HeaderFrame, "TOPLEFT", 30, -7);
|
||||
HeaderFrame.button.title:SetWidth(self:GetParent():GetWidth() - 110)
|
||||
|
||||
for i = 1, #HeaderFrame.Bullets do
|
||||
|
@ -229,24 +229,16 @@ end
|
|||
function EncounterFrame:ClearHeaders()
|
||||
local function clear(headers)
|
||||
for _, header in ipairs(headers) do
|
||||
-- Skrytí aktuálního záhlaví
|
||||
header:Hide()
|
||||
header:SetParent(nil)
|
||||
|
||||
-- Rekurzivně skrýváme podřízená záhlaví
|
||||
if header.children and #header.children > 0 then
|
||||
clear(header.children)
|
||||
end
|
||||
|
||||
-- Vymazání záhlaví
|
||||
header = nil
|
||||
end
|
||||
|
||||
-- Vyprázdnění seznamu
|
||||
wipe(headers)
|
||||
end
|
||||
|
||||
-- Vymazání všech hlavních záhlaví
|
||||
clear(self.headers)
|
||||
end
|
||||
|
||||
|
|
43
Addon/Code/Shared.lua
Normal file
43
Addon/Code/Shared.lua
Normal file
|
@ -0,0 +1,43 @@
|
|||
local _, addon = ...
|
||||
|
||||
local function ClearNumberStringMarks(text)
|
||||
-- Remove colors (|cffffff...)
|
||||
text = text:gsub("|c%x%x%x%x%x%x%x%x", "")
|
||||
-- Remove H marks
|
||||
text = text:gsub("|H.-|h", "")
|
||||
return text
|
||||
end
|
||||
|
||||
local function FillNumbers(text, sourceText)
|
||||
local numbers = {}
|
||||
local currentIndex = 1
|
||||
|
||||
local source = ClearNumberStringMarks(sourceText)
|
||||
|
||||
for num in source:gmatch("(%d[%d,%.]*)") do
|
||||
table.insert(numbers, num)
|
||||
end
|
||||
|
||||
local replacedText = text:gsub("#%?", function()
|
||||
local n = numbers[currentIndex]
|
||||
currentIndex = currentIndex + 1
|
||||
|
||||
if n and source:match("%s+" .. n .. "%s+million") then
|
||||
return n .. " mil."
|
||||
elseif n and source:match("%s+" .. n .. "%s+million") then
|
||||
return n .. " mil."
|
||||
end
|
||||
|
||||
return n or "?"
|
||||
end)
|
||||
|
||||
return replacedText
|
||||
end
|
||||
addon.API.FillNumbers = FillNumbers
|
||||
|
||||
local function ColorSpellNames(text, color)
|
||||
return text:gsub("%[(.-)%]", function(match)
|
||||
return string.format("|c%s[%s]|r", color or "FF0000FF", match)
|
||||
end)
|
||||
end
|
||||
addon.API.ColorSpellNames = ColorSpellNames
|
|
@ -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