Improve tactic data handling and update UI logic.

This commit is contained in:
Roman Jaroš 2025-03-30 17:56:47 +02:00
parent 9fe284c18e
commit 403fe3539f
4 changed files with 108 additions and 11 deletions

View file

@ -13,6 +13,11 @@ const normalizeTranslation = (translation: string | null | undefined) => {
return translation.replace(/\n/g, '\\n').replace(/"/g, "'"); 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) => { const prepareLuaWithFemaleVersion = (quest: Quest, type: keyof Quest, key: string) => {
let text = ''; let text = '';
const value = quest[type] as string; const value = quest[type] as string;
@ -70,6 +75,22 @@ const splitFirst = (text: string, delimiter: string) => {
return text.slice(index + delimiter.length); 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 () => { (async () => {
const args = process.argv.slice(2); const args = process.argv.slice(2);
const addonDir = path.join(process.cwd(), `../Addon/Data/${args[0]}`); 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) { for (const tolgeeKey of translations) {
let key = tolgeeKey.keyName; let key = tolgeeKey.keyName;
if (tolgeeKey.keyNamespace === 'tactic') {
key = key.split('_')[0];
}
const instanceName = getSplitByIndexes(tolgeeKey.keyName, [1, 2]).join('_');
addonData[key] = { addonData[key] = {
...addonData[tolgeeKey.keyName], ...addonData[tolgeeKey.keyName],
...(tolgeeKey.keyNamespace === 'name' && { ...(tolgeeKey.keyNamespace === 'name' && {
@ -146,6 +173,25 @@ const splitFirst = (text: string, delimiter: string) => {
tolgeeKey.translations.en.text, 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, name: tolgeeKey.keyDescription,
id: tolgeeKey.keyName.replace('q', '').replace('i', ''), id: tolgeeKey.keyName.replace('q', '').replace('i', ''),
isQuest: tolgeeKey.keyName.startsWith('q'), isQuest: tolgeeKey.keyName.startsWith('q'),
@ -201,6 +247,28 @@ const splitFirst = (text: string, delimiter: string) => {
luaQuestRecord += `}\n`; luaQuestRecord += `}\n`;
fs.appendFileSync(fileName, luaQuestRecord, 'utf8'); 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) { } catch (e) {
@ -210,6 +278,17 @@ const splitFirst = (text: string, delimiter: string) => {
type AddonData = Record<string, Quest>; type AddonData = Record<string, Quest>;
type Tactic = {
summary?: string | null;
tank?: (string | null)[];
healer?: (string | null)[];
dps?: (string | null)[];
};
type InstanceTactic = {
[key: string]: Tactic;
};
type Quest = { type Quest = {
id: string; id: string;
name: string; name: string;
@ -219,6 +298,7 @@ type Quest = {
completions?: (string | null)[]; completions?: (string | null)[];
objectives?: (string | null)[]; objectives?: (string | null)[];
speeches?: (string | null)[]; speeches?: (string | null)[];
tactics?: InstanceTactic;
isQuest: boolean; isQuest: boolean;
isQuestItem: boolean; isQuestItem: boolean;
}; };

View file

@ -32,24 +32,26 @@ end
local function RenderBossTactics(frame, bossName) local function RenderBossTactics(frame, bossName)
HideOtherContent() HideOtherContent()
local bossData = addon.data.tactic[bossName]
local difficulty = 'lfr' -- 17 local difficulty = 'lfg_raid' -- 17
if DIFFICULTY == 14 then if DIFFICULTY == 14 then
difficulty = 'normal' difficulty = 'normal_raid'
elseif DIFFICULTY == 15 then elseif DIFFICULTY == 15 then
difficulty = 'heroic' difficulty = 'heroic_raid'
elseif DIFFICULTY == 16 then elseif DIFFICULTY == 16 then
difficulty = 'mythic' difficulty = 'mythic_raid'
elseif DIFFICULTY == 1 then elseif DIFFICULTY == 1 then
difficulty = 'normal' difficulty = 'normal_dungeon'
elseif DIFFICULTY == 2 then elseif DIFFICULTY == 2 then
difficulty = 'heroic' difficulty = 'heroic_dungeon'
elseif DIFFICULTY == 23 then elseif DIFFICULTY == 23 then
difficulty = 'mythic' difficulty = 'mythic_dungeon'
elseif DIFFICULTY == 8 then
difficulty = 'mythicplus_dungeon'
end 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 if not tactic then
frame.summary:SetText("Boss " .. bossName .. " nemá pro tuto obtížnost přeloženou taktiku.") frame.summary:SetText("Boss " .. bossName .. " nemá pro tuto obtížnost přeloženou taktiku.")
@ -71,6 +73,7 @@ local function RenderBossTactics(frame, bossName)
end end
frame.summary:SetText(tactic.summary) frame.summary:SetText(tactic.summary)
frame.inform:SetText("|cffffffffVždy dodržuj pokyny raid leadera.|r")
local tankHeader = frame:CreateHeader() local tankHeader = frame:CreateHeader()
tankHeader.button.title:SetText("Tank") tankHeader.button.title:SetText("Tank")

View file

@ -39,6 +39,15 @@ function TacticFrame:Init()
frame.summary:SetPoint("TOPLEFT", frame, "TOPLEFT", 2, 0) frame.summary:SetPoint("TOPLEFT", frame, "TOPLEFT", 2, 0)
frame.summary:SetWidth(scrollFrame:GetWidth() - 10) 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") local dropdown = CreateFrame("DropdownButton", nil, EncounterJournal.encounter.info, "WowStyle1DropdownTemplate")
dropdown:SetPoint("BOTTOMRIGHT", EncounterJournal.encounter.info.encounterTitle, "BOTTOMRIGHT", 2, -2) dropdown:SetPoint("BOTTOMRIGHT", EncounterJournal.encounter.info.encounterTitle, "BOTTOMRIGHT", 2, -2)
dropdown:SetWidth(200) dropdown:SetWidth(200)
@ -59,6 +68,12 @@ function TacticFrame:UpdateSettings()
CzechQuestsAddon_Store.config.TACTIC_TEXT_FONT_SIZE 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 for _, header in ipairs(self.headers) do
addon.API.UpdateCzechFont( addon.API.UpdateCzechFont(
header.description, header.description,
@ -182,7 +197,7 @@ end
function TacticFrame:UpdateHeaderPositions() function TacticFrame:UpdateHeaderPositions()
local yOffset = -40 local yOffset = -40
for _, header in ipairs(self.headers) do 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 if header.expanded then
yOffset = yOffset - header.description:GetHeight() - 50 yOffset = yOffset - header.description:GetHeight() - 50
else else

View file

@ -14,7 +14,6 @@ Addon/Data/1.lua
Addon/Data/2.lua Addon/Data/2.lua
Addon/Data/3.lua Addon/Data/3.lua
Addon/Data/4.lua Addon/Data/4.lua
Addon/Data/5.lua
Addon/Data/other.lua Addon/Data/other.lua