feat: resolving lines

This commit is contained in:
TrèsAbhi committed 2024-03-14 16:43:28 -05:00
1 parent 5372068830
commit 43e1d53d39
9 files changed
+149 -14

No files matched your search

+19
View File
@@ -0,0 +1,19 @@
import { resolveAncestry } from './resolveAncestry';
import { tankDefinitions } from './tankDefinitions';
export async function buildTechTreeLine(start: number, end: number) {
const awaitedTankDefinitions = await tankDefinitions;
const endTank = awaitedTankDefinitions[end];
if (!endTank.ancestors) throw new Error('End tank has no ancestors');
const line = [end];
if (start === end) return line;
for (const ancestorId of endTank.ancestors) {
if ((await resolveAncestry(ancestorId)).includes(start)) {
line.push(...(await buildTechTreeLine(start, ancestorId)));
break;
}
}
return line;
}
+25
View File
@@ -0,0 +1,25 @@
import { tankDefinitions } from './tankDefinitions';
export async function resolveAncestry(id: number) {
const awaitedTankDefinitions = await tankDefinitions;
const tank = awaitedTankDefinitions[id];
const ancestors: number[] = [];
if (tank.ancestors) {
for (const ancestor of tank.ancestors) {
if (!ancestors.includes(ancestor)) {
ancestors.push(ancestor);
for (const ancestorLayer2 of await resolveAncestry(ancestor)) {
if (!ancestors.includes(ancestorLayer2)) {
ancestors.push(ancestorLayer2);
}
}
}
}
}
return ancestors.sort(
(a, b) => awaitedTankDefinitions[b].tier - awaitedTankDefinitions[a].tier,
);
}
+9 -4
View File
@@ -1,8 +1,8 @@
import { readFile } from 'fs/promises';
import { deburr } from 'lodash';
import { Vector2Tuple } from 'three';
import { TankClass, TreeType } from '../../../components/Tanks';
import { asset } from '../asset';
import { fetchCdonLz4 } from '../fetchCdonLz4';
import { superDecompress } from '../superDecompress';
import { TIERS } from './constants';
export type ShellType = 'ap' | 'ap_cr' | 'hc' | 'he';
@@ -137,8 +137,12 @@ export type ShellDefinition = {
explosionRadius?: number;
};
export const tankDefinitions = fetchCdonLz4<TankDefinitions>(
asset('definitions/tanks.cdon.lz4'),
// export const tankDefinitions = fetchCdonLz4<TankDefinitions>(
// asset('definitions/tanks.cdon.lz4'),
// );
export const tankDefinitions = readFile('test.tanks.cdon.lz4').then((data) =>
superDecompress<TankDefinitions>(data.buffer),
);
const entries = new Promise<TankDefinition[]>(async (resolve) => {
@@ -158,6 +162,7 @@ export const tankNames = tanksDefinitionsArray.then((tanks) =>
id,
original: tank.name,
combined: `${tank.name}${deburr(tank.name)}${tank.nameFull ? `${tank.nameFull}${deburr(tank.nameFull)}` : ''}`,
treeType: tank.treeType,
};
}),
),
+13 -4
View File
@@ -10,8 +10,13 @@ import {
OVERFLOW_SUFFIX,
} from './autocompleteClan/constants';
const tankNamesTechTreeOnly = tankNames.then((names) =>
names.filter((tank) => tank.treeType === 'researchable'),
);
export default async function autocompleteTanks(
interaction: AutocompleteInteraction<CacheType>,
techTreeOnly = false,
) {
const focusedOption = interaction.options.getFocused(true);
if (focusedOption.name !== 'tank') return;
@@ -19,10 +24,14 @@ export default async function autocompleteTanks(
await interaction.respond(
focusedOption.value
? await Promise.all(
go(focusedOption.value, await tankNames, {
keys: ['combined'],
limit: 10,
}).map(async (item) => {
go(
focusedOption.value,
await (techTreeOnly ? tankNamesTechTreeOnly : tankNames),
{
keys: ['combined'],
limit: 10,
},
).map(async (item) => {
let name = item.obj.original;
if (name.length > DISCORD_CHOICES_MAX_NAME_SIZE) {