mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 03:29:51 +02:00
feat: use new tankopedia
This commit is contained in:
1 parent
c5214f8d89
commit
bdc7132337
20 files changed
+78
-74
No files matched your search
@@ -1,11 +1,11 @@
|
||||
import { TreeTypeEnum } from '../../components/Tanks';
|
||||
import { tankopedia } from '../blitzstars/tankopedia';
|
||||
import { tankopedia } from '../blitzkrieg/tankopedia';
|
||||
|
||||
export default async function getTreeType(id: number) {
|
||||
const entry = (await tankopedia)[id];
|
||||
|
||||
if (entry?.is_collectible) return TreeTypeEnum.Collector;
|
||||
if (entry?.is_premium) return TreeTypeEnum.Premium;
|
||||
if (entry.tree_type === 'collector') return TreeTypeEnum.Collector;
|
||||
if (entry.tree_type === 'premium') return TreeTypeEnum.Premium;
|
||||
|
||||
return TreeTypeEnum.TechTree;
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import { go } from 'fuzzysort';
|
||||
import { TANKS, tankopedia } from '../blitzkrieg/tankopedia';
|
||||
import { UserError } from '../blitzkrieg/userError';
|
||||
import { TANKS, tankopedia } from '../blitzstars/tankopedia';
|
||||
|
||||
export default async function resolveTankId(tank: string | number) {
|
||||
const number = typeof tank === 'string' ? parseInt(tank) : tank;
|
||||
@@ -16,7 +16,7 @@ export default async function resolveTankId(tank: string | number) {
|
||||
cause: `Could not find tank by the name "${tank}".`,
|
||||
});
|
||||
} else {
|
||||
return searchResult[0].obj.tank_id;
|
||||
return searchResult[0].obj.id;
|
||||
}
|
||||
} else {
|
||||
if ((await tankopedia)[number]) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { tankopedia } from '../blitzstars/tankopedia';
|
||||
import { tankopedia } from '../blitzkrieg/tankopedia';
|
||||
|
||||
export default async function resolveTankName(tankId: number) {
|
||||
const tankopediaName = (await tankopedia)[tankId]?.name;
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
export function asset(path: string) {
|
||||
return `https://raw.githubusercontent.com/tresabhi/blitzkrieg-assets/main/${path}`;
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
import { TREE_TYPE_NAMES } from '../../components/Tanks';
|
||||
import resolveTankName from '../blitz/resolveTankName';
|
||||
import { tankopediaInfo } from '../blitz/tankopediaInfo';
|
||||
import { TIER_ROMAN_NUMERALS, Tier } from '../blitzstars/tankopedia';
|
||||
import { StatFilters } from '../statistics/filterStats';
|
||||
import { TIER_ROMAN_NUMERALS, Tier } from './tankopedia';
|
||||
|
||||
export async function filtersToDescription({
|
||||
nation,
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
import { asset } from './asset';
|
||||
|
||||
export function tankIcon(id: number, size: 'big' | 'small' = 'big') {
|
||||
return asset(`icons/${size}/${id}.webp`);
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import { deburr } from 'lodash';
|
||||
import { context } from '../blitzkrieg/context';
|
||||
import { TreeTypeString } from '../../components/Tanks';
|
||||
import { asset } from './asset';
|
||||
|
||||
export interface TankopediaEntry {
|
||||
name: string;
|
||||
@@ -17,30 +18,36 @@ export interface Tankopedia {
|
||||
[id: number]: TankopediaEntry | undefined;
|
||||
}
|
||||
|
||||
export const tankopedia = fetch(
|
||||
context === 'website'
|
||||
? '/api/tankopedia'
|
||||
: 'https://www.blitzstars.com/bs-tankopedia.json',
|
||||
)
|
||||
.then(async (response) => response.json())
|
||||
.then((wrapperTankopedia) =>
|
||||
context === 'server'
|
||||
? (wrapperTankopedia as { data: Tankopedia }).data
|
||||
: (wrapperTankopedia as Tankopedia),
|
||||
);
|
||||
const entries = new Promise<TankopediaEntry[]>(async (resolve) => {
|
||||
export interface BlitzkriegTankopediaEntry {
|
||||
id: number;
|
||||
nation: string;
|
||||
name: string;
|
||||
name_short?: string;
|
||||
tree_type: TreeTypeString;
|
||||
tier: Tier;
|
||||
type: string;
|
||||
}
|
||||
|
||||
export type BlitzkriegTankopedia = Record<number, BlitzkriegTankopediaEntry>;
|
||||
|
||||
export const tankopedia = fetch(asset('tankopedia.json')).then(
|
||||
async (response) => response.json() as Promise<BlitzkriegTankopedia>,
|
||||
);
|
||||
const entries = new Promise<BlitzkriegTankopediaEntry[]>(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 TANKS = new Promise<BlitzkriegTankopediaEntry[]>(
|
||||
async (resolve) => {
|
||||
resolve((await entries).map((entry) => entry));
|
||||
},
|
||||
);
|
||||
export const TANK_NAMES = new Promise<string[]>(async (resolve) => {
|
||||
resolve((await entries).map(({ name }) => name));
|
||||
});
|
||||
export const TANK_NAMES_DIACRITICS = TANK_NAMES.then((tankNames) =>
|
||||
Promise.all(
|
||||
tankNames.map(async (tankName, index) => {
|
||||
const id = (await TANKS)[index].tank_id;
|
||||
const { id } = (await TANKS)[index];
|
||||
const name = tankName ?? `Unknown Tank ${id}`;
|
||||
const diacriticless = deburr(name);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { AllStats } from '../blitz/getAccountInfo';
|
||||
import { context } from '../blitzkrieg/context';
|
||||
import { tankopedia } from './tankopedia';
|
||||
import { tankopedia } from '../blitzkrieg/tankopedia';
|
||||
|
||||
export interface SpecialStats {
|
||||
winrate: number;
|
||||
|
||||
@@ -4,7 +4,7 @@ import {
|
||||
CacheType,
|
||||
} from 'discord.js';
|
||||
import { go } from 'fuzzysort';
|
||||
import { TANK_NAMES_DIACRITICS } from '../blitzstars/tankopedia';
|
||||
import { TANK_NAMES_DIACRITICS } from '../blitzkrieg/tankopedia';
|
||||
import {
|
||||
DISCORD_CHOICES_MAX_NAME_SIZE,
|
||||
OVERFLOW_SUFFIX,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { TreeTypeString } from '../../components/Tanks';
|
||||
import { tankopedia } from '../blitzkrieg/tankopedia';
|
||||
import { DiffedTankStats } from '../blitzstars/getStatsInPeriod';
|
||||
import { tankAverages } from '../blitzstars/tankAverages';
|
||||
import { tankopedia } from '../blitzstars/tankopedia';
|
||||
import calculateWN8 from './calculateWN8';
|
||||
import sumStats from './sumStats';
|
||||
|
||||
@@ -31,14 +31,11 @@ export async function filterStats(
|
||||
(filters.tier === undefined || entry.tier === filters.tier) &&
|
||||
(filters.tankType === undefined || entry.type === filters.tankType) &&
|
||||
(filters.treeType === undefined ||
|
||||
(filters.treeType === 'collector' && entry.is_collectible) ||
|
||||
(filters.treeType === 'premium' &&
|
||||
entry.is_premium &&
|
||||
!entry.is_collectible) ||
|
||||
(filters.treeType === 'collector' && entry.tree_type === 'collector') ||
|
||||
(filters.treeType === 'premium' && entry.tree_type === 'premium') ||
|
||||
(filters.treeType === 'tech-tree' &&
|
||||
!entry.is_collectible &&
|
||||
!entry.is_premium)) &&
|
||||
(filters.tank === undefined || entry.tank_id === filters.tank)
|
||||
entry.tree_type === 'tech-tree')) &&
|
||||
(filters.tank === undefined || entry.id === filters.tank)
|
||||
);
|
||||
});
|
||||
const stats = sumStats(filteredOrder.map((id) => diff[id]));
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { TierWeightsRecord } from '../../components/TierWeights';
|
||||
import { AllStats } from '../blitz/getAccountInfo';
|
||||
import { tankopedia } from '../blitzstars/tankopedia';
|
||||
import { tankopedia } from '../blitzkrieg/tankopedia';
|
||||
|
||||
export async function getTierWeights(
|
||||
stats: Record<number, AllStats>,
|
||||
@@ -9,7 +9,7 @@ export async function getTierWeights(
|
||||
const awaitedTankopedia = await tankopedia;
|
||||
const tierWeights: TierWeightsRecord = {};
|
||||
|
||||
order.map((id) => {
|
||||
order.forEach((id) => {
|
||||
const entry = awaitedTankopedia[id];
|
||||
|
||||
if (!entry) return;
|
||||
|
||||
Reference in new issue
Block a user