From 403fe3539f1b8551d4671958678f9617e5867372 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Jaro=C5=A1?= Date: Sun, 30 Mar 2025 17:56:47 +0200 Subject: [PATCH] Improve tactic data handling and update UI logic. --- .support/index.ts | 80 ++++++++++++++++++++++++++++++++++++++ Addon/Code/Tactic.lua | 21 +++++----- Addon/Code/TacticFrame.lua | 17 +++++++- CzechQuests_Mainline.toc | 1 - 4 files changed, 108 insertions(+), 11 deletions(-) diff --git a/.support/index.ts b/.support/index.ts index 9d1d109..e38fc97 100644 --- a/.support/index.ts +++ b/.support/index.ts @@ -13,6 +13,11 @@ const normalizeTranslation = (translation: string | null | undefined) => { return translation.replace(/\n/g, '\\n').replace(/"/g, "'"); }; +function getSplitByIndexes(input: string, indexes: number[]): string[] { + const parts = input.split('_'); + return indexes.map((index) => parts[index]).filter((item) => item !== undefined); +} + const prepareLuaWithFemaleVersion = (quest: Quest, type: keyof Quest, key: string) => { let text = ''; const value = quest[type] as string; @@ -70,6 +75,22 @@ const splitFirst = (text: string, delimiter: string) => { return text.slice(index + delimiter.length); }; +const generateRoleTactic = (role: (string | null)[]) => { + let luaQuestRecord = ''; + for (const ability of role) { + if (ability == null) continue; + const information = ability.split('\n'); + luaQuestRecord += `\t\t\t{\n`; + luaQuestRecord += `\t\t\t\tname = "${information[0]}",\n`; + luaQuestRecord += `\t\t\t\tphase = "${information[1]}",\n`; + luaQuestRecord += `\t\t\t\tdescription = "${information[2]}",\n`; + luaQuestRecord += `\t\t\t\thowTo = "${information[3]}",\n`; + luaQuestRecord += `\t\t\t\tdangerous = "${information[4]}",\n`; + luaQuestRecord += `\t\t\t},\n`; + } + return luaQuestRecord; +}; + (async () => { const args = process.argv.slice(2); const addonDir = path.join(process.cwd(), `../Addon/Data/${args[0]}`); @@ -94,6 +115,12 @@ const splitFirst = (text: string, delimiter: string) => { for (const tolgeeKey of translations) { let key = tolgeeKey.keyName; + if (tolgeeKey.keyNamespace === 'tactic') { + key = key.split('_')[0]; + } + + const instanceName = getSplitByIndexes(tolgeeKey.keyName, [1, 2]).join('_'); + addonData[key] = { ...addonData[tolgeeKey.keyName], ...(tolgeeKey.keyNamespace === 'name' && { @@ -146,6 +173,25 @@ const splitFirst = (text: string, delimiter: string) => { tolgeeKey.translations.en.text, ], }), + ...(tolgeeKey.keyNamespace === 'tactic' && { + tactics: { + [instanceName]: { + ...(addonData[key]?.tactics?.[instanceName] ?? {}), + ...(tolgeeKey.keyName.endsWith('_summary') && { + summary: tolgeeKey.translations.cs.text, + }), + ...(tolgeeKey.keyName.includes('_tank_') && { + tank: [...(addonData[key].tactics?.[instanceName]?.tank ?? []), tolgeeKey.translations.cs.text], + }), + ...(tolgeeKey.keyName.includes('_healer_') && { + healer: [...(addonData[key].tactics?.[instanceName]?.healer ?? []), tolgeeKey.translations.cs.text], + }), + ...(tolgeeKey.keyName.includes('_dps_') && { + dps: [...(addonData[key].tactics?.[instanceName]?.dps ?? []), tolgeeKey.translations.cs.text], + }), + }, + }, + }), name: tolgeeKey.keyDescription, id: tolgeeKey.keyName.replace('q', '').replace('i', ''), isQuest: tolgeeKey.keyName.startsWith('q'), @@ -201,6 +247,28 @@ const splitFirst = (text: string, delimiter: string) => { luaQuestRecord += `}\n`; fs.appendFileSync(fileName, luaQuestRecord, 'utf8'); } + + if (czechQuest.tactics) { + let luaQuestRecord = ''; + const npcNameKey = normalizeTranslation(czechQuest.name).trim(); + luaQuestRecord += `addon.data.tactic["${npcNameKey}"] = {\n`; + for (const [instance, roles] of Object.entries(czechQuest.tactics)) { + luaQuestRecord += `\t${instance} = {\n`; + luaQuestRecord += `\t\tsummary = "${roles.summary}",\n`; + luaQuestRecord += `\t\ttank = {\n`; + if (roles.tank) luaQuestRecord += generateRoleTactic(roles.tank); + luaQuestRecord += `\t\t},\n`; + luaQuestRecord += `\t\theal = {\n`; + if (roles.healer) luaQuestRecord += generateRoleTactic(roles.healer); + luaQuestRecord += `\t\t},\n`; + luaQuestRecord += `\t\tdps = {\n`; + if (roles.dps) luaQuestRecord += generateRoleTactic(roles.dps); + luaQuestRecord += `\t\t},\n`; + luaQuestRecord += `\t},\n`; + } + luaQuestRecord += `}\n`; + fs.appendFileSync(fileName, luaQuestRecord, 'utf8'); + } } }); } catch (e) { @@ -210,6 +278,17 @@ const splitFirst = (text: string, delimiter: string) => { type AddonData = Record; +type Tactic = { + summary?: string | null; + tank?: (string | null)[]; + healer?: (string | null)[]; + dps?: (string | null)[]; +}; + +type InstanceTactic = { + [key: string]: Tactic; +}; + type Quest = { id: string; name: string; @@ -219,6 +298,7 @@ type Quest = { completions?: (string | null)[]; objectives?: (string | null)[]; speeches?: (string | null)[]; + tactics?: InstanceTactic; isQuest: boolean; isQuestItem: boolean; }; diff --git a/Addon/Code/Tactic.lua b/Addon/Code/Tactic.lua index 04554b1..e13831e 100755 --- a/Addon/Code/Tactic.lua +++ b/Addon/Code/Tactic.lua @@ -32,24 +32,26 @@ end local function RenderBossTactics(frame, bossName) HideOtherContent() - local bossData = addon.data.tactic[bossName] - local difficulty = 'lfr' -- 17 + local difficulty = 'lfg_raid' -- 17 if DIFFICULTY == 14 then - difficulty = 'normal' + difficulty = 'normal_raid' elseif DIFFICULTY == 15 then - difficulty = 'heroic' + difficulty = 'heroic_raid' elseif DIFFICULTY == 16 then - difficulty = 'mythic' + difficulty = 'mythic_raid' elseif DIFFICULTY == 1 then - difficulty = 'normal' + difficulty = 'normal_dungeon' elseif DIFFICULTY == 2 then - difficulty = 'heroic' + difficulty = 'heroic_dungeon' elseif DIFFICULTY == 23 then - difficulty = 'mythic' + difficulty = 'mythic_dungeon' + elseif DIFFICULTY == 8 then + difficulty = 'mythicplus_dungeon' end - local tactic = bossData and bossData[1][difficulty] or nil + local bossData = CzechQuestsAddon:GetData('tactic', bossName) + local tactic = bossData and bossData[difficulty] or nil if not tactic then frame.summary:SetText("Boss " .. bossName .. " nemá pro tuto obtížnost přeloženou taktiku.") @@ -71,6 +73,7 @@ local function RenderBossTactics(frame, bossName) end frame.summary:SetText(tactic.summary) + frame.inform:SetText("|cffffffffVždy dodržuj pokyny raid leadera.|r") local tankHeader = frame:CreateHeader() tankHeader.button.title:SetText("Tank") diff --git a/Addon/Code/TacticFrame.lua b/Addon/Code/TacticFrame.lua index 2edf782..351b830 100755 --- a/Addon/Code/TacticFrame.lua +++ b/Addon/Code/TacticFrame.lua @@ -39,6 +39,15 @@ function TacticFrame:Init() frame.summary:SetPoint("TOPLEFT", frame, "TOPLEFT", 2, 0) frame.summary:SetWidth(scrollFrame:GetWidth() - 10) + frame.inform = addon.API.CreateCzechFont( + frame, + CzechQuestsAddon_Store.config.TACTIC_TEXT_FONT_NAME, + CzechQuestsAddon_Store.config.TACTIC_TEXT_FONT_SIZE + ) + frame.inform:SetTextColor(0.251, 0.145, 0.012) + frame.inform:SetPoint("BOTTOMLEFT", frame.summary, "BOTTOMLEFT", 2, -20) + frame.inform:SetWidth(scrollFrame:GetWidth() - 10) + local dropdown = CreateFrame("DropdownButton", nil, EncounterJournal.encounter.info, "WowStyle1DropdownTemplate") dropdown:SetPoint("BOTTOMRIGHT", EncounterJournal.encounter.info.encounterTitle, "BOTTOMRIGHT", 2, -2) dropdown:SetWidth(200) @@ -59,6 +68,12 @@ function TacticFrame:UpdateSettings() CzechQuestsAddon_Store.config.TACTIC_TEXT_FONT_SIZE ) + addon.API.UpdateCzechFont( + frame.inform, + CzechQuestsAddon_Store.config.TACTIC_TEXT_FONT_NAME, + CzechQuestsAddon_Store.config.TACTIC_TEXT_FONT_SIZE + ) + for _, header in ipairs(self.headers) do addon.API.UpdateCzechFont( header.description, @@ -182,7 +197,7 @@ end function TacticFrame:UpdateHeaderPositions() local yOffset = -40 for _, header in ipairs(self.headers) do - header:SetPoint("BOTTOMLEFT", self.summary, "BOTTOMLEFT", 0, yOffset) + header:SetPoint("BOTTOMLEFT", self.inform, "BOTTOMLEFT", 0, yOffset) if header.expanded then yOffset = yOffset - header.description:GetHeight() - 50 else diff --git a/CzechQuests_Mainline.toc b/CzechQuests_Mainline.toc index 84a05d6..6f66126 100755 --- a/CzechQuests_Mainline.toc +++ b/CzechQuests_Mainline.toc @@ -14,7 +14,6 @@ Addon/Data/1.lua Addon/Data/2.lua Addon/Data/3.lua Addon/Data/4.lua -Addon/Data/5.lua Addon/Data/other.lua