Refactor Encounters, use new translations format for save space

This commit is contained in:
Roman Jaroš 2025-04-17 19:04:49 +02:00
parent 7d9f58650a
commit 908f45eb9b
59 changed files with 103852 additions and 58396 deletions

View file

@ -0,0 +1,10 @@
import { TolgeeKey } from '../../types';
import { writeAlsoFemaleTranslation } from '../translation';
export const writeBook = (tolgeeKey: TolgeeKey): string => {
let luaRecord = '';
luaRecord += `addon.data.book["${tolgeeKey.keyName}"] = {\n`;
luaRecord += writeAlsoFemaleTranslation(tolgeeKey.translations);
luaRecord += `}\n`;
return luaRecord;
};

View file

@ -0,0 +1,61 @@
import { TolgeeKey, TreeNode } from '../../types';
import { writeAlsoFemaleTranslation } from '../translation';
export function buildTree(inputs: string[], layer = ''): TreeNode[] {
const root: TreeNode[] = [];
inputs
.filter((input) => new RegExp(`_(${layer})([0-9]{2})$`).test(input))
.forEach((input) => {
const layerIndex = input.split('_').at(-1);
root.push({
key: input,
children: buildTree(inputs, layerIndex),
});
});
return root;
}
export const getEncounterKey = (tolgeeKey: TolgeeKey): string => {
const [, difficulty, instance, type, key] = tolgeeKey.keyName.split('_');
return [tolgeeKey.keyDescription, difficulty, instance, type, key].join('_');
};
export const getEncounterGroupKey = (tolgeeKey: TolgeeKey): string => {
const [, difficulty, instance] = tolgeeKey.keyName.split('_');
return [tolgeeKey.keyDescription, difficulty, instance].join('_');
};
export const writeEncounter = (tolgeeKey: TolgeeKey): string => {
let luaRecord = '';
const keyName = getEncounterKey(tolgeeKey);
luaRecord += `addon.data.encounter["${keyName}"] = {\n`;
luaRecord += writeAlsoFemaleTranslation(tolgeeKey.translations);
luaRecord += `}\n`;
return luaRecord;
};
const writeStructure = (structure: TreeNode[], layer = 0): string => {
let luaRecord = '';
const tab = '\t'.repeat(layer);
const layerIndex = layer + 1;
structure.forEach((node) => {
const hasEmptyChildren = node.children.length === 0;
luaRecord += `${tab}{\n`;
luaRecord += `\t${tab}key = "${node.key}",\n`;
luaRecord += `\t${tab}children = {${hasEmptyChildren ? '' : '\n'}`;
luaRecord += `${writeStructure(node.children, layerIndex)}`;
luaRecord += `${hasEmptyChildren ? '' : `\t${tab}`}},\n`;
luaRecord += `${tab}},\n`;
});
return luaRecord;
};
export const writeEncounterStructure = (key: string, structure: TreeNode[]): string => {
let luaRecord = '';
luaRecord += `addon.data.encounter["${key}"] = {\n`;
luaRecord += writeStructure(structure);
luaRecord += `}\n`;
return luaRecord;
};

View file

@ -0,0 +1,10 @@
import { TolgeeKey } from '../../types';
import { writeAlsoFemaleTranslation } from '../translation';
export const writeQuest = (tolgeeKey: TolgeeKey): string => {
let luaRecord = '';
luaRecord += `addon.data.quest["${tolgeeKey.keyName}"] = {\n`;
luaRecord += writeAlsoFemaleTranslation(tolgeeKey.translations);
luaRecord += `}\n`;
return luaRecord;
};

View file

@ -0,0 +1,10 @@
import { TolgeeKey } from '../../types';
import { normalize, writeMaleTranslation } from '../translation';
export const writeSpeech = (tolgeeKey: TolgeeKey): string => {
let luaRecord = '';
luaRecord += `addon.data.speech["${normalize(tolgeeKey.keyDescription)}_${tolgeeKey.keyName}"] = {\n`;
luaRecord += writeMaleTranslation(tolgeeKey.translations);
luaRecord += `}\n`;
return luaRecord;
};