feat: move tankopedia to tankDefinitions

This commit is contained in:
TrèsAbhi committed 2023-12-05 17:36:18 -06:00
1 parent cfe71e15a4
commit ad0fc69596
25 files changed
+270 -295

No files matched your search

@@ -1,7 +1,7 @@
import { WARGAMING_APPLICATION_ID } from '../../constants/wargamingApplicationID';
import fetchBlitz from './fetchBlitz';
export interface TankopediaInfo {
export interface EncyclopediaInfo {
achievement_sections: Record<string, { name: string; order: number }>;
tanks_updated_at: number;
languages: Record<string, string>;
@@ -10,6 +10,6 @@ export interface TankopediaInfo {
game_version: string;
}
export const tankopediaInfo = fetchBlitz<TankopediaInfo>(
export const encyclopediaInfo = fetchBlitz<EncyclopediaInfo>(
`https://api.wotblitz.com/wotb/encyclopedia/info/?application_id=${WARGAMING_APPLICATION_ID}`,
);
+2 -2
View File
@@ -1,8 +1,8 @@
import { TreeTypeEnum } from '../../components/Tanks';
import { tankopedia } from '../blitzkrieg/tankopedia';
import { tankDefinitions } from '../blitzkrieg/definitions/tanks';
export default async function getTreeType(id: number) {
const entry = (await tankopedia)[id];
const entry = (await tankDefinitions)[id];
if (entry.tree_type === 'collector') return TreeTypeEnum.Collector;
if (entry.tree_type === 'premium') return TreeTypeEnum.Premium;
+6 -3
View File
@@ -1,12 +1,15 @@
import { go } from 'fuzzysort';
import { tankopedia, tanks } from '../blitzkrieg/tankopedia';
import {
tankDefinitions,
tanksDefinitionsArray,
} from '../blitzkrieg/definitions/tanks';
import { UserError } from '../blitzkrieg/userError';
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, {
const searchResult = go(`${tank}`, await tanksDefinitionsArray, {
keys: ['name'],
limit: 1,
});
@@ -19,7 +22,7 @@ export default async function resolveTankId(tank: string | number) {
return searchResult[0].obj.id;
}
} else {
if ((await tankopedia)[number]) {
if ((await tankDefinitions)[number]) {
return number;
} else {
throw new UserError('Tank not found', {
+3 -3
View File
@@ -1,8 +1,8 @@
import { tankopedia } from '../blitzkrieg/tankopedia';
import { tankDefinitions } from '../blitzkrieg/definitions/tanks';
export default async function resolveTankName(tankId: number) {
const awaitedTankopedia = await tankopedia;
const entry = awaitedTankopedia[tankId];
const awaitedTankDefinitions = await tankDefinitions;
const entry = awaitedTankDefinitions[tankId];
return entry?.name_short ?? entry?.name ?? `Unknown Tank ${tankId}`;
}