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,24 +1,8 @@
import { deburr } from 'lodash';
import { TankType, TreeTypeString } from '../../components/Tanks';
import { asset } from './asset';
import { TankType, TreeTypeString } from '../../../components/Tanks';
import { asset } from '../asset';
export interface TankopediaEntry {
name: string;
nation: string;
is_premium: boolean;
is_collectible: boolean;
tier: Tier;
cost: { price_credit: number; price_gold: number };
images: { preview: string; normal: string };
tank_id: number;
type: string;
description: string;
}
export interface Tankopedia {
[id: number]: TankopediaEntry | undefined;
}
export interface BlitzkriegTankopediaEntry {
export interface TankDefinition {
id: number;
nation: string;
name: string;
@@ -28,15 +12,16 @@ export interface BlitzkriegTankopediaEntry {
type: TankType;
}
export type BlitzkriegTankopedia = Record<number, BlitzkriegTankopediaEntry>;
export type TankDefinitions = Record<number, TankDefinition>;
export const tankopedia = fetch(asset('tankopedia.json'), {
export const tankDefinitions = fetch(asset('definitions/tanks.json'), {
cache: 'no-store',
}).then(async (response) => response.json() as Promise<BlitzkriegTankopedia>);
const entries = new Promise<BlitzkriegTankopediaEntry[]>(async (resolve) => {
resolve(Object.entries(await tankopedia).map(([, entry]) => entry));
}).then(async (response) => response.json() as Promise<TankDefinitions>);
const entries = new Promise<TankDefinition[]>(async (resolve) => {
resolve(Object.entries(await tankDefinitions).map(([, entry]) => entry));
});
export const tanks = new Promise<BlitzkriegTankopediaEntry[]>(
export const tanksDefinitionsArray = new Promise<TankDefinition[]>(
async (resolve) => {
resolve((await entries).map((entry) => entry));
},
@@ -47,7 +32,7 @@ export const tankNames = new Promise<string[]>(async (resolve) => {
export const tankNamesDiacritics = tankNames.then((tankNames) =>
Promise.all(
tankNames.map(async (tankName, index) => {
const { id } = (await tanks)[index];
const { id } = (await tanksDefinitionsArray)[index];
const name = tankName ?? `Unknown Tank ${id}`;
const diacriticless = deburr(name);
@@ -99,7 +84,7 @@ export const TIER_ROMAN_NUMERALS: Record<Tier, string> = {
10: 'X',
};
export const NATIONS = tanks.then((tanks) => {
export const NATIONS = tanksDefinitionsArray.then((tanks) => {
const nationsObject: Record<string, true> = {};
tanks.forEach(({ nation }) => {
+5 -5
View File
@@ -1,8 +1,8 @@
import { TREE_TYPE_NAMES } from '../../components/Tanks';
import { encyclopediaInfo } from '../blitz/encyclopediaInfo';
import resolveTankName from '../blitz/resolveTankName';
import { tankopediaInfo } from '../blitz/tankopediaInfo';
import { StatFilters } from '../statistics/filterStats';
import { TIER_ROMAN_NUMERALS, Tier } from './tankopedia';
import { TIER_ROMAN_NUMERALS, Tier } from './definitions/tanks';
export async function filtersToDescription({
nation,
@@ -11,13 +11,13 @@ export async function filtersToDescription({
treeType,
tank,
}: StatFilters) {
const awaitedTankopediaInfo = await tankopediaInfo;
const awaitedEncyclopediaInfo = await encyclopediaInfo;
const info: string[] = [];
if (tank) return await resolveTankName(tank);
if (nation) info.push(awaitedTankopediaInfo.vehicle_nations[nation]);
if (nation) info.push(awaitedEncyclopediaInfo.vehicle_nations[nation]);
if (tier) info.push(`Tier ${TIER_ROMAN_NUMERALS[tier as Tier]}`);
if (tankType) info.push(awaitedTankopediaInfo.vehicle_types[tankType]);
if (tankType) info.push(awaitedEncyclopediaInfo.vehicle_types[tankType]);
if (treeType) info.push(TREE_TYPE_NAMES[treeType]);
return info.length === 0 ? 'No filters' : info.join(', ');