Refactor and improve encounter data handling and formatting
All checks were successful
forgejo/Czech Quests/addon/pipeline/head This commit looks good

This commit is contained in:
Roman Jaroš 2025-04-19 00:41:40 +02:00
parent a32b698ebf
commit f37808207e
8 changed files with 226 additions and 83 deletions

View file

@ -48,7 +48,7 @@ local function HideOtherContent()
addon.EncounterFrame:ClearHeaders()
end
local function SetAbilityIcon(header, tags)
local function SetAbilityTagIcon(header, tags)
local result = {}
for part in string.gmatch(tags, "([^,]+)") do
table.insert(result, part)
@ -71,6 +71,36 @@ local function SetAbilityIcon(header, tags)
end
end
local function SetAbilityIcon(header, name)
if ORIGINALS[name] == nil then
return
end
local abilityIcon = ORIGINALS[name].abilityIcon or nil
if abilityIcon then
header.button.abilityIcon:SetTexture(abilityIcon)
header.button.abilityIcon:Show()
header.button.title:SetPoint("TOPLEFT", header, "TOPLEFT", 45, -7);
end
end
local function SetEncounterPortraitIcon(header, name)
if ORIGINALS[name] == nil then
return
end
local creatureDisplayID = ORIGINALS[name].creatureDisplayID or 0
local uiModelSceneID = ORIGINALS[name].uiModelSceneID or 0
if creatureDisplayID ~= 0 and uiModelSceneID ~= 0 then
header.button.portrait.displayInfo = creatureDisplayID;
header.button.portrait.uiModelSceneID = uiModelSceneID;
SetPortraitTextureFromCreatureDisplayID(header.button.portrait.icon, creatureDisplayID);
header.button.portrait:Show()
header.button.title:SetPoint("TOPLEFT", header, "TOPLEFT", 50, -7);
end
end
local function RenderBossAbilities(data, parent, layer)
local frame = addon.EncounterFrame
@ -92,12 +122,17 @@ local function RenderBossAbilities(data, parent, layer)
header:SetWidth(frame:GetWidth() - (layer * 20))
header.button.title:SetText(name)
SetAbilityIcon(header, name)
SetEncounterPortraitIcon(header, name)
if tag and tag ~= '???' then
SetAbilityIcon(header, tag)
SetAbilityTagIcon(header, tag)
end
header.description:SetWidth(header:GetWidth() - 20)
header.description:SetText(addon.API.SetAbilityDescription(description, ORIGINALS[name]))
header.description:SetText(
addon.API.FormatEncounterDescription(description, ORIGINALS[name].description)
)
if description == "" then header.empty = true end
table.insert(parent.children, header)
@ -112,41 +147,42 @@ local function RenderBossAbilities(data, parent, layer)
end
end
local function RenderBossEncounter(bossKey, bossName)
local function RenderBossEncounter(bossKey, bossName, encounterName)
local frame = addon.EncounterFrame
HideOtherContent()
local bossData = CzechQuestsAddon:GetData('encounter', bossKey)
frame.summary:SetText(
addon.API.SetAbilityDescription(bossData.overview, ORIGINALS['Overview'])
addon.API.FormatEncounterDescription(bossData.overview, ORIGINALS['Overview'].description)
)
local tankHeader = frame:CreateHeader()
tankHeader.button.title:SetText("Tank")
local tankDescription = addon.API.SetSummaryDescription(bossData.tank, ORIGINALS['Tanks'])
local tankDescription = addon.API.FormatEncounterDescription(bossData.tank, ORIGINALS['Tanks'].description)
tankHeader.description:SetText(tankDescription)
table.insert(frame.headers, tankHeader)
SetAbilityIcon(tankHeader, 'tank')
SetAbilityTagIcon(tankHeader, 'tank')
local healHeader = frame:CreateHeader()
healHeader.button.title:SetText("Healer")
local healerDescription = addon.API.SetSummaryDescription(bossData.healer, ORIGINALS['Healers'])
local healerDescription = addon.API.FormatEncounterDescription(bossData.healer, ORIGINALS['Healers'].description)
healHeader.description:SetText(healerDescription)
table.insert(frame.headers, healHeader)
SetAbilityIcon(healHeader, 'healer')
SetAbilityTagIcon(healHeader, 'healer')
local dpsHeader = frame:CreateHeader()
dpsHeader.button.title:SetText("Damage Dealer")
local dpsDescription = addon.API.SetSummaryDescription(bossData.dps, ORIGINALS['Damage Dealers'])
local dpsDescription = addon.API.FormatEncounterDescription(bossData.dps, ORIGINALS['Damage Dealers'].description)
dpsHeader.description:SetText(dpsDescription)
table.insert(frame.headers, dpsHeader)
SetAbilityIcon(dpsHeader, 'dps')
SetAbilityTagIcon(dpsHeader, 'dps')
local bossHeader = frame:CreateHeader()
bossHeader.button.title:SetText(bossName)
bossHeader.button.title:SetText(encounterName)
bossHeader.empty = true
table.insert(frame.headers, bossHeader)
SetEncounterPortraitIcon(bossHeader, bossName)
RenderBossAbilities(bossData.abilities, bossHeader, 1)
frame:GetParent():Show()
@ -155,16 +191,31 @@ end
local function StoreBossAbilities()
ORIGINALS = {}
local stack, _, _, _, curSectionID = {}, EJ_GetEncounterInfo(ENCOUNTER_ID)
local _, bossName, description, displayInfo, iconImage, uiModelSceneID = EJ_GetCreatureInfo(1, ENCOUNTER_ID)
ORIGINALS[bossName] = {}
ORIGINALS[bossName].description = description
ORIGINALS[bossName].creatureDisplayID = displayInfo
ORIGINALS[bossName].uiModelSceneID = uiModelSceneID
ORIGINALS[bossName].abilityIcon = iconImage
repeat
local info = C_EncounterJournal.GetSectionInfo(curSectionID)
if not info.filteredByDifficulty then
ORIGINALS[info.title] = info.description
ORIGINALS[info.title] = {}
ORIGINALS[info.title].description = info.description
ORIGINALS[info.title].creatureDisplayID = info.creatureDisplayID
ORIGINALS[info.title].uiModelSceneID = info.uiModelSceneID
ORIGINALS[info.title].abilityIcon = info.abilityIcon
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
@ -173,6 +224,7 @@ local function DetectBossToRender()
local frame = addon.EncounterFrame
local encounterName = EJ_GetEncounterInfo(ENCOUNTER_ID)
local _, bossName = EJ_GetCreatureInfo(1, ENCOUNTER_ID)
local difficulty = 'lfg_raid' -- 17
if DIFFICULTY == 14 then
@ -203,11 +255,11 @@ local function DetectBossToRender()
if bossKey then
StoreBossAbilities()
RenderBossEncounter(bossKey, encounterName)
RenderBossEncounter(bossKey, bossName, encounterName)
end
if bossKey == nil then
frame.summary:SetText("V souboji " .. encounterName .. " není tato obtížnost přeložena.")
frame.summary:SetText("Pro souboj " .. encounterName .. " není vytvořen překlad.")
frame:GetParent():Show()
end
end