Refactor Encounters, use new translations format for save space
This commit is contained in:
parent
7d9f58650a
commit
908f45eb9b
59 changed files with 103852 additions and 58396 deletions
61
.support/utils/entities/encounter.ts
Normal file
61
.support/utils/entities/encounter.ts
Normal 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;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue