2023-08-10 01:46:39 +00:00
|
|
|
import { deburr } from 'lodash';
|
2023-08-04 02:13:21 +00:00
|
|
|
import { secrets } from '../node/secrets';
|
|
|
|
|
import getWargamingResponse from './getWargamingResponse';
|
|
|
|
|
|
2023-08-10 01:03:53 +00:00
|
|
|
export type TankType = 'AT-SPG' | 'lightTank' | 'mediumTank' | 'heavyTank';
|
|
|
|
|
|
2023-06-03 18:25:33 +00:00
|
|
|
export interface TankopediaEntry {
|
2023-07-08 19:47:21 +00:00
|
|
|
name: string;
|
2023-07-09 00:51:53 +00:00
|
|
|
nation: string;
|
2023-07-08 19:47:21 +00:00
|
|
|
is_premium: boolean;
|
2023-07-10 18:16:33 +00:00
|
|
|
is_collectible: boolean;
|
2023-07-09 00:51:53 +00:00
|
|
|
tier: number;
|
|
|
|
|
cost: { price_credit: number; price_gold: number };
|
2023-07-08 19:47:21 +00:00
|
|
|
images: { preview: string; normal: string };
|
2023-07-09 00:51:53 +00:00
|
|
|
tank_id: number;
|
2023-08-10 01:03:53 +00:00
|
|
|
type: TankType;
|
2023-07-09 00:51:53 +00:00
|
|
|
description: string;
|
2023-06-03 18:25:33 +00:00
|
|
|
}
|
2023-05-30 18:42:34 +00:00
|
|
|
|
|
|
|
|
export interface Tankopedia {
|
2023-07-07 01:08:00 +00:00
|
|
|
[id: number]: TankopediaEntry | undefined;
|
2023-05-30 18:42:34 +00:00
|
|
|
}
|
|
|
|
|
|
2023-07-05 02:09:36 +00:00
|
|
|
console.log('Caching tankopedia...');
|
2023-07-09 00:51:53 +00:00
|
|
|
export const tankopedia = fetch('https://www.blitzstars.com/bs-tankopedia.json')
|
|
|
|
|
.then((response) => response.json())
|
|
|
|
|
.then((wrapperTankopedia) => {
|
|
|
|
|
console.log('Tankopedia cached');
|
|
|
|
|
return (wrapperTankopedia as { data: Tankopedia }).data;
|
|
|
|
|
});
|
2023-07-05 17:42:14 +00:00
|
|
|
const entries = new Promise<TankopediaEntry[]>(async (resolve) => {
|
|
|
|
|
resolve(Object.entries(await tankopedia).map(([, entry]) => entry));
|
|
|
|
|
});
|
|
|
|
|
export const TANKS = new Promise<TankopediaEntry[]>(async (resolve) => {
|
|
|
|
|
resolve((await entries).map((entry) => entry));
|
|
|
|
|
});
|
|
|
|
|
export const TANK_NAMES = new Promise<string[]>(async (resolve) => {
|
|
|
|
|
resolve((await entries).map(({ name }) => name));
|
|
|
|
|
});
|
2023-08-10 01:46:39 +00:00
|
|
|
export const TANK_NAMES_DIACRITICS = TANK_NAMES.then((tankNames) =>
|
|
|
|
|
Promise.all(
|
|
|
|
|
tankNames.map(async (tankName, index) => {
|
|
|
|
|
const name = tankName ?? `Unknown Tank ${(await TANKS)[index].tank_id}`;
|
|
|
|
|
const diacriticless = deburr(name);
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
original: name,
|
|
|
|
|
diacriticless,
|
|
|
|
|
combined: `${name}${diacriticless}`,
|
|
|
|
|
};
|
|
|
|
|
}),
|
|
|
|
|
),
|
|
|
|
|
);
|
2023-05-30 18:42:34 +00:00
|
|
|
|
2023-08-04 02:13:21 +00:00
|
|
|
export interface TankopediaInfo {
|
|
|
|
|
achievement_sections: Record<string, { name: string; order: number }>;
|
|
|
|
|
tanks_updated_at: number;
|
|
|
|
|
languages: Record<string, string>;
|
|
|
|
|
vehicle_types: Record<string, string>;
|
|
|
|
|
vehicle_nations: Record<string, string>;
|
|
|
|
|
game_version: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// this is blocking because info is needed for command creation
|
|
|
|
|
console.log('Caching tankopedia info...');
|
|
|
|
|
export const tankopediaInfo = getWargamingResponse<TankopediaInfo>(
|
|
|
|
|
`https://api.wotblitz.com/wotb/encyclopedia/info/?application_id=${secrets.WARGAMING_APPLICATION_ID}`,
|
|
|
|
|
);
|
|
|
|
|
console.log('Cached tankopedia info');
|
|
|
|
|
|
2023-08-10 01:03:53 +00:00
|
|
|
export const TANK_ICONS: Record<TankType, string> = {
|
2023-06-05 18:47:00 +00:00
|
|
|
'AT-SPG': 'https://i.imgur.com/BIHSEH0.png',
|
|
|
|
|
lightTank: 'https://i.imgur.com/CSNha5V.png',
|
|
|
|
|
mediumTank: 'https://i.imgur.com/wvf3ltm.png',
|
|
|
|
|
heavyTank: 'https://i.imgur.com/ECeqlZa.png',
|
|
|
|
|
};
|
|
|
|
|
|
2023-08-10 01:03:53 +00:00
|
|
|
export const TANK_ICONS_PREMIUM: Record<TankType, string> = {
|
2023-07-09 00:47:03 +00:00
|
|
|
'AT-SPG': 'https://i.imgur.com/TCu3EdR.png',
|
|
|
|
|
lightTank: 'https://i.imgur.com/zdkpTRb.png',
|
|
|
|
|
mediumTank: 'https://i.imgur.com/3z7eHX6.png',
|
|
|
|
|
heavyTank: 'https://i.imgur.com/P3vbmyA.png',
|
|
|
|
|
};
|
|
|
|
|
|
2023-08-10 01:03:53 +00:00
|
|
|
export const TANK_ICONS_COLLECTOR: Record<TankType, string> = {
|
2023-07-10 18:16:33 +00:00
|
|
|
'AT-SPG': 'https://i.imgur.com/WTjeirB.png',
|
|
|
|
|
lightTank: 'https://i.imgur.com/EwhtKkU.png',
|
|
|
|
|
mediumTank: 'https://i.imgur.com/u8YDMBh.png',
|
|
|
|
|
heavyTank: 'https://i.imgur.com/8xRf3nc.png',
|
|
|
|
|
};
|
|
|
|
|
|
2023-06-19 18:08:34 +00:00
|
|
|
export type Tier = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10;
|
|
|
|
|
|
|
|
|
|
export const TIER_ROMAN_NUMERALS: Record<Tier, string> = {
|
2023-06-05 18:47:00 +00:00
|
|
|
1: 'I',
|
|
|
|
|
2: 'II',
|
|
|
|
|
3: 'III',
|
|
|
|
|
4: 'IV',
|
|
|
|
|
5: 'V',
|
|
|
|
|
6: 'VI',
|
|
|
|
|
7: 'VII',
|
|
|
|
|
8: 'VIII',
|
|
|
|
|
9: 'IX',
|
|
|
|
|
10: 'X',
|
2023-05-30 18:42:34 +00:00
|
|
|
};
|