Improve tactic data handling and update UI logic.
All checks were successful
forgejo/Czech Quests/addon/pipeline/head This commit looks good

This commit is contained in:
Roman Jaroš 2025-03-30 17:56:47 +02:00
parent 9fe284c18e
commit 3cb2ed503f
9 changed files with 1116 additions and 1019 deletions

View file

@ -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<string, Quest>;
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;
};