mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 19:49:50 +02:00
feat: move tankopedia to tankDefinitions
This commit is contained in:
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}`,
|
||||
);
|
||||
@@ -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;
|
||||
|
||||
@@ -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', {
|
||||
|
||||
@@ -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}`;
|
||||
}
|
||||
Reference in new issue
Block a user