feat: core chunk 5

This commit is contained in:
TrèsAbhi committed 2023-10-14 11:25:42 -05:00
1 parent 9bdb14e13a
commit ed8bab7df8
37 files changed
+91 -165

No files matched your search

+1 -1
View File
@@ -1,5 +1,5 @@
import { TreeTypeEnum } from '../../components/Tanks';
import { tankopedia } from '../../LEGACY_core/blitz/tankopedia';
import { tankopedia } from '../blitzstars/tankopedia';
export default async function getTreeType(id: number) {
const entry = (await tankopedia)[id];
+32
View File
@@ -0,0 +1,32 @@
import { go } from 'fuzzysort';
import throwError from '../../LEGACY_core/node/throwError';
import { TANKS, tankopedia } from '../blitzstars/tankopedia';
export default async function resolveTankId(tank: string | number) {
const number = typeof tank === 'string' ? parseInt(tank) : tank;
if (Number.isNaN(number)) {
const searchResult = go(`${tank}`, await TANKS, {
keys: ['name'],
limit: 1,
});
if (searchResult.length === 0) {
throw throwError(
'Tank not found',
`Could not find tank by the name "${tank}".`,
);
} else {
return searchResult[0].obj.tank_id;
}
} else {
if ((await tankopedia)[number]) {
return number;
} else {
throw throwError(
'Tank not found',
`Could not find tank by the ID "${number}".`,
);
}
}
}
+6
View File
@@ -0,0 +1,6 @@
import { tankopedia } from '../blitzstars/tankopedia';
export default async function resolveTankName(tankId: number) {
const tankopediaName = (await tankopedia)[tankId]?.name;
return tankopediaName ? tankopediaName : `Unknown Tank ${tankId}`;
}