feat: use new tankopedia

This commit is contained in:
TrèsAbhi committed 2023-11-29 12:17:21 -06:00
1 parent c5214f8d89
commit bdc7132337
20 files changed
+78 -74

No files matched your search

+4 -14
View File
@@ -5,8 +5,8 @@ import { load } from 'js-yaml';
import { argv, env } from 'process'; import { argv, env } from 'process';
import { ElementCompact, xml2js } from 'xml-js'; import { ElementCompact, xml2js } from 'xml-js';
import { parse } from 'yaml'; import { parse } from 'yaml';
import { TreeTypeString } from '../src/components/Tanks';
import { NATION_IDS } from '../src/constants/nations'; import { NATION_IDS } from '../src/constants/nations';
import { BlitzkriegTankopedia, Tier } from '../src/core/blitzkrieg/tankopedia';
import commitMultipleFiles, { FileChange } from './commitMultipleFiles'; import commitMultipleFiles, { FileChange } from './commitMultipleFiles';
const LANGUAGE = 'en'; const LANGUAGE = 'en';
@@ -45,21 +45,11 @@ if (!noRewrite) {
console.log('Creating new tankopedia folder'); console.log('Creating new tankopedia folder');
await mkdir('dist/tankopedia'); await mkdir('dist/tankopedia');
interface BlitzkriegTankopedia {
id: number;
nation: string;
name: string;
name_short?: string;
tree_type: TreeTypeString;
tier: number;
type: string;
}
const strings = await readFile( const strings = await readFile(
`${TEMP}/${directoriesOfInterest.strings}/${LANGUAGE}.yaml`, `${TEMP}/${directoriesOfInterest.strings}/${LANGUAGE}.yaml`,
'utf-8', 'utf-8',
).then((data) => load(data) as Record<string, string>); ).then((data) => load(data) as Record<string, string>);
const tankopedia: Record<number, BlitzkriegTankopedia> = {}; const tankopedia: BlitzkriegTankopedia = {};
const tankIds: number[] = []; const tankIds: number[] = [];
const images: Record<number, { big: string; small: string }> = {}; const images: Record<number, { big: string; small: string }> = {};
const nations = await readdir( const nations = await readdir(
@@ -89,7 +79,7 @@ Promise.all(
const isCollector = vehicleData.sellPrice const isCollector = vehicleData.sellPrice
? 'gold' in vehicleData.sellPrice ? 'gold' in vehicleData.sellPrice
: false; : false;
const tier = parseInt(vehicleData.level._text); const tier = parseInt(vehicleData.level._text) as Tier;
const tags = vehicleData.tags._text.split(' '); const tags = vehicleData.tags._text.split(' ');
const type = tags[0]; const type = tags[0];
@@ -174,7 +164,7 @@ Promise.all(
'blitzkrieg-assets', 'blitzkrieg-assets',
'main', 'main',
new Date().toString(), new Date().toString(),
iconsChange, [tankopediaChange, ...iconsChange],
true, true,
); );
} else { } else {
+1 -1
View File
@@ -1,5 +1,5 @@
import { NextResponse } from 'next/server'; import { NextResponse } from 'next/server';
import { tankopedia } from '../../../core/blitzstars/tankopedia'; import { tankopedia } from '../../../core/blitzkrieg/tankopedia';
export async function GET() { export async function GET() {
return NextResponse.json(await tankopedia); return NextResponse.json(await tankopedia);
+7 -6
View File
@@ -6,11 +6,11 @@ import * as Breakdown from '../../../components/Breakdown';
import { TreeTypeEnum } from '../../../components/Tanks'; import { TreeTypeEnum } from '../../../components/Tanks';
import { WARGAMING_APPLICATION_ID } from '../../../constants/wargamingApplicationID'; import { WARGAMING_APPLICATION_ID } from '../../../constants/wargamingApplicationID';
import fetchBlitz from '../../../core/blitz/fetchBlitz'; import fetchBlitz from '../../../core/blitz/fetchBlitz';
import { tankAverages } from '../../../core/blitzstars/tankAverages';
import { import {
TankopediaEntry, BlitzkriegTankopediaEntry,
tankopedia, tankopedia,
} from '../../../core/blitzstars/tankopedia'; } from '../../../core/blitzkrieg/tankopedia';
import { tankAverages } from '../../../core/blitzstars/tankAverages';
import calculateWN8 from '../../../core/statistics/calculateWN8'; import calculateWN8 from '../../../core/statistics/calculateWN8';
import { deltaTankStats } from '../../../core/statistics/deltaTankStats'; import { deltaTankStats } from '../../../core/statistics/deltaTankStats';
import getWN8Percentile from '../../../core/statistics/getWN8Percentile'; import getWN8Percentile from '../../../core/statistics/getWN8Percentile';
@@ -30,7 +30,7 @@ export default function SessionPage() {
list: { list: {
stats: IndividualTankStats; stats: IndividualTankStats;
tankopedia?: TankopediaEntry; tankopedia?: BlitzkriegTankopediaEntry;
career: IndividualTankStats; career: IndividualTankStats;
currentWN8?: number; currentWN8?: number;
careerWN8?: number; careerWN8?: number;
@@ -299,9 +299,10 @@ export default function SessionPage() {
type="tank" type="tank"
tankType={tankopedia?.type} tankType={tankopedia?.type}
treeType={(() => { treeType={(() => {
if (tankopedia?.is_collectible) if (tankopedia?.tree_type === 'collector')
return TreeTypeEnum.Collector; return TreeTypeEnum.Collector;
if (tankopedia?.is_premium) return TreeTypeEnum.Premium; if (tankopedia?.tree_type === 'premium')
return TreeTypeEnum.Premium;
})()} })()}
stats={session.customColumns.map((customColumn) => { stats={session.customColumns.map((customColumn) => {
const rowStat = rowStats[customColumn.display]; const rowStat = rowStats[customColumn.display];
+1 -1
View File
@@ -10,10 +10,10 @@ import getTankStats from '../core/blitz/getTankStats';
import getTreeType from '../core/blitz/getTreeType'; import getTreeType from '../core/blitz/getTreeType';
import resolveTankName from '../core/blitz/resolveTankName'; import resolveTankName from '../core/blitz/resolveTankName';
import { filtersToDescription } from '../core/blitzkrieg/filtersToDescription'; import { filtersToDescription } from '../core/blitzkrieg/filtersToDescription';
import { tankopedia } from '../core/blitzkrieg/tankopedia';
import { getBlitzStarsLinkButton } from '../core/blitzstars/getBlitzStarsLinkButton'; import { getBlitzStarsLinkButton } from '../core/blitzstars/getBlitzStarsLinkButton';
import getStatsInPeriod from '../core/blitzstars/getStatsInPeriod'; import getStatsInPeriod from '../core/blitzstars/getStatsInPeriod';
import { tankAverages } from '../core/blitzstars/tankAverages'; import { tankAverages } from '../core/blitzstars/tankAverages';
import { tankopedia } from '../core/blitzstars/tankopedia';
import addFilterOptions from '../core/discord/addFilterOptions'; import addFilterOptions from '../core/discord/addFilterOptions';
import addUsernameChoices from '../core/discord/addUsernameChoices'; import addUsernameChoices from '../core/discord/addUsernameChoices';
import autocompleteTanks from '../core/discord/autocompleteTanks'; import autocompleteTanks from '../core/discord/autocompleteTanks';
+1 -1
View File
@@ -2,9 +2,9 @@ import { SlashCommandBuilder } from 'discord.js';
import { getAccountInfo } from '../core/blitz/getAccountInfo'; import { getAccountInfo } from '../core/blitz/getAccountInfo';
import getPeriodNow from '../core/blitzkrieg/getPeriodNow'; import getPeriodNow from '../core/blitzkrieg/getPeriodNow';
import getTimeDaysAgo from '../core/blitzkrieg/getTimeDaysAgo'; import getTimeDaysAgo from '../core/blitzkrieg/getTimeDaysAgo';
import { tankopedia } from '../core/blitzkrieg/tankopedia';
import getStatsInPeriod from '../core/blitzstars/getStatsInPeriod'; import getStatsInPeriod from '../core/blitzstars/getStatsInPeriod';
import { tankAverages } from '../core/blitzstars/tankAverages'; import { tankAverages } from '../core/blitzstars/tankAverages';
import { tankopedia } from '../core/blitzstars/tankopedia';
import addUsernameChoices from '../core/discord/addUsernameChoices'; import addUsernameChoices from '../core/discord/addUsernameChoices';
import embedNegative from '../core/discord/embedNegative'; import embedNegative from '../core/discord/embedNegative';
import embedPositive from '../core/discord/embedPositive'; import embedPositive from '../core/discord/embedPositive';
+13 -12
View File
@@ -10,12 +10,13 @@ import getTreeType from '../core/blitz/getTreeType';
import resolveTankName from '../core/blitz/resolveTankName'; import resolveTankName from '../core/blitz/resolveTankName';
import { tankopediaInfo } from '../core/blitz/tankopediaInfo'; import { tankopediaInfo } from '../core/blitz/tankopediaInfo';
import { emblemIdToURL } from '../core/blitzkrieg/emblemIdToURL'; import { emblemIdToURL } from '../core/blitzkrieg/emblemIdToURL';
import { tankIcon } from '../core/blitzkrieg/tankIcon';
import { import {
BlitzkriegTankopediaEntry,
TIER_ROMAN_NUMERALS, TIER_ROMAN_NUMERALS,
TankopediaEntry,
Tier, Tier,
tankopedia, tankopedia,
} from '../core/blitzstars/tankopedia'; } from '../core/blitzkrieg/tankopedia';
import addTierChoices from '../core/discord/addTierChoices'; import addTierChoices from '../core/discord/addTierChoices';
import addUsernameChoices from '../core/discord/addUsernameChoices'; import addUsernameChoices from '../core/discord/addUsernameChoices';
import autocompleteUsername from '../core/discord/autocompleteUsername'; import autocompleteUsername from '../core/discord/autocompleteUsername';
@@ -42,12 +43,12 @@ export const ownedTanksCommand: CommandRegistry = {
await Promise.all( await Promise.all(
tankStats.map(async (tankData) => ({ tankStats.map(async (tankData) => ({
tankopedia: (await tankopedia)[tankData.tank_id]!, tankopedia: (await tankopedia)[tankData.tank_id]!,
tank_id: tankData.tank_id, id: tankData.tank_id,
})), })),
) )
).filter((tank) => tank.tankopedia?.tier === tier); ).filter((tank) => tank.tankopedia?.tier === tier);
const clanAccountInfo = await getClanAccountInfo(server, id, ['clan']); const clanAccountInfo = await getClanAccountInfo(server, id, ['clan']);
const groupedTanks: Record<string, TankopediaEntry[]> = {}; const groupedTanks: Record<string, BlitzkriegTankopediaEntry[]> = {};
const nations: string[] = []; const nations: string[] = [];
filteredTanks.forEach((tank) => { filteredTanks.forEach((tank) => {
@@ -94,11 +95,11 @@ export const ownedTanksCommand: CommandRegistry = {
{await Promise.all( {await Promise.all(
leftColumn.map(async (tank) => ( leftColumn.map(async (tank) => (
<Tanks.Item <Tanks.Item
key={tank.tank_id} key={tank.id}
name={await resolveTankName(tank.tank_id)} name={await resolveTankName(tank.id)}
tankType={tank.type} tankType={tank.type}
image={tank.images?.normal} image={tankIcon(tank.id)}
treeType={await getTreeType(tank.tank_id)} treeType={await getTreeType(tank.id)}
/> />
)), )),
)} )}
@@ -107,11 +108,11 @@ export const ownedTanksCommand: CommandRegistry = {
{await Promise.all( {await Promise.all(
rightColumn.map(async (tank) => ( rightColumn.map(async (tank) => (
<Tanks.Item <Tanks.Item
key={tank.tank_id} key={tank.id}
name={await resolveTankName(tank.tank_id)} name={await resolveTankName(tank.id)}
tankType={tank.type} tankType={tank.type}
image={tank.images?.normal} image={tankIcon(tank.id)}
treeType={await getTreeType(tank.tank_id)} treeType={await getTreeType(tank.id)}
/> />
)), )),
)} )}
+1 -1
View File
@@ -1,7 +1,7 @@
import { SlashCommandBuilder } from 'discord.js'; import { SlashCommandBuilder } from 'discord.js';
import { go } from 'fuzzysort'; import { go } from 'fuzzysort';
import markdownEscape from 'markdown-escape'; import markdownEscape from 'markdown-escape';
import { TANK_NAMES_DIACRITICS } from '../core/blitzstars/tankopedia'; import { TANK_NAMES_DIACRITICS } from '../core/blitzkrieg/tankopedia';
import addTankChoices from '../core/discord/addTankChoices'; import addTankChoices from '../core/discord/addTankChoices';
import embedInfo from '../core/discord/embedInfo'; import embedInfo from '../core/discord/embedInfo';
import { CommandRegistry } from '../events/interactionCreate'; import { CommandRegistry } from '../events/interactionCreate';
+1 -1
View File
@@ -2,7 +2,7 @@ import {
TANK_ICONS, TANK_ICONS,
TANK_ICONS_COLLECTOR, TANK_ICONS_COLLECTOR,
TANK_ICONS_PREMIUM, TANK_ICONS_PREMIUM,
} from '../../../core/blitzstars/tankopedia'; } from '../../../core/blitzkrieg/tankopedia';
import { theme } from '../../../stitches.config'; import { theme } from '../../../stitches.config';
export enum TreeTypeEnum { export enum TreeTypeEnum {
+1 -1
View File
@@ -1,4 +1,4 @@
import { Tier } from '../core/blitzstars/tankopedia'; import { Tier } from '../core/blitzkrieg/tankopedia';
import { theme } from '../stitches.config'; import { theme } from '../stitches.config';
export type TierWeightsRecord = Partial<Record<Tier, number>>; export type TierWeightsRecord = Partial<Record<Tier, number>>;
+3 -3
View File
@@ -1,11 +1,11 @@
import { TreeTypeEnum } from '../../components/Tanks'; import { TreeTypeEnum } from '../../components/Tanks';
import { tankopedia } from '../blitzstars/tankopedia'; import { tankopedia } from '../blitzkrieg/tankopedia';
export default async function getTreeType(id: number) { export default async function getTreeType(id: number) {
const entry = (await tankopedia)[id]; const entry = (await tankopedia)[id];
if (entry?.is_collectible) return TreeTypeEnum.Collector; if (entry.tree_type === 'collector') return TreeTypeEnum.Collector;
if (entry?.is_premium) return TreeTypeEnum.Premium; if (entry.tree_type === 'premium') return TreeTypeEnum.Premium;
return TreeTypeEnum.TechTree; return TreeTypeEnum.TechTree;
} }
+2 -2
View File
@@ -1,6 +1,6 @@
import { go } from 'fuzzysort'; import { go } from 'fuzzysort';
import { TANKS, tankopedia } from '../blitzkrieg/tankopedia';
import { UserError } from '../blitzkrieg/userError'; import { UserError } from '../blitzkrieg/userError';
import { TANKS, tankopedia } from '../blitzstars/tankopedia';
export default async function resolveTankId(tank: string | number) { export default async function resolveTankId(tank: string | number) {
const number = typeof tank === 'string' ? parseInt(tank) : tank; 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}".`, cause: `Could not find tank by the name "${tank}".`,
}); });
} else { } else {
return searchResult[0].obj.tank_id; return searchResult[0].obj.id;
} }
} else { } else {
if ((await tankopedia)[number]) { if ((await tankopedia)[number]) {
+1 -1
View File
@@ -1,4 +1,4 @@
import { tankopedia } from '../blitzstars/tankopedia'; import { tankopedia } from '../blitzkrieg/tankopedia';
export default async function resolveTankName(tankId: number) { export default async function resolveTankName(tankId: number) {
const tankopediaName = (await tankopedia)[tankId]?.name; const tankopediaName = (await tankopedia)[tankId]?.name;
+3
View File
@@ -0,0 +1,3 @@
export function asset(path: string) {
return `https://raw.githubusercontent.com/tresabhi/blitzkrieg-assets/main/${path}`;
}
+1 -1
View File
@@ -1,8 +1,8 @@
import { TREE_TYPE_NAMES } from '../../components/Tanks'; import { TREE_TYPE_NAMES } from '../../components/Tanks';
import resolveTankName from '../blitz/resolveTankName'; import resolveTankName from '../blitz/resolveTankName';
import { tankopediaInfo } from '../blitz/tankopediaInfo'; import { tankopediaInfo } from '../blitz/tankopediaInfo';
import { TIER_ROMAN_NUMERALS, Tier } from '../blitzstars/tankopedia';
import { StatFilters } from '../statistics/filterStats'; import { StatFilters } from '../statistics/filterStats';
import { TIER_ROMAN_NUMERALS, Tier } from './tankopedia';
export async function filtersToDescription({ export async function filtersToDescription({
nation, nation,
+5
View File
@@ -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 { deburr } from 'lodash';
import { context } from '../blitzkrieg/context'; import { TreeTypeString } from '../../components/Tanks';
import { asset } from './asset';
export interface TankopediaEntry { export interface TankopediaEntry {
name: string; name: string;
@@ -17,30 +18,36 @@ export interface Tankopedia {
[id: number]: TankopediaEntry | undefined; [id: number]: TankopediaEntry | undefined;
} }
export const tankopedia = fetch( export interface BlitzkriegTankopediaEntry {
context === 'website' id: number;
? '/api/tankopedia' nation: string;
: 'https://www.blitzstars.com/bs-tankopedia.json', name: string;
) name_short?: string;
.then(async (response) => response.json()) tree_type: TreeTypeString;
.then((wrapperTankopedia) => tier: Tier;
context === 'server' type: string;
? (wrapperTankopedia as { data: Tankopedia }).data }
: (wrapperTankopedia as Tankopedia),
); export type BlitzkriegTankopedia = Record<number, BlitzkriegTankopediaEntry>;
const entries = new Promise<TankopediaEntry[]>(async (resolve) => {
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)); resolve(Object.entries(await tankopedia).map(([, entry]) => entry));
}); });
export const TANKS = new Promise<TankopediaEntry[]>(async (resolve) => { export const TANKS = new Promise<BlitzkriegTankopediaEntry[]>(
resolve((await entries).map((entry) => entry)); async (resolve) => {
}); resolve((await entries).map((entry) => entry));
},
);
export const TANK_NAMES = new Promise<string[]>(async (resolve) => { export const TANK_NAMES = new Promise<string[]>(async (resolve) => {
resolve((await entries).map(({ name }) => name)); resolve((await entries).map(({ name }) => name));
}); });
export const TANK_NAMES_DIACRITICS = TANK_NAMES.then((tankNames) => export const TANK_NAMES_DIACRITICS = TANK_NAMES.then((tankNames) =>
Promise.all( Promise.all(
tankNames.map(async (tankName, index) => { tankNames.map(async (tankName, index) => {
const id = (await TANKS)[index].tank_id; const { id } = (await TANKS)[index];
const name = tankName ?? `Unknown Tank ${id}`; const name = tankName ?? `Unknown Tank ${id}`;
const diacriticless = deburr(name); const diacriticless = deburr(name);
+1 -1
View File
@@ -1,6 +1,6 @@
import { AllStats } from '../blitz/getAccountInfo'; import { AllStats } from '../blitz/getAccountInfo';
import { context } from '../blitzkrieg/context'; import { context } from '../blitzkrieg/context';
import { tankopedia } from './tankopedia'; import { tankopedia } from '../blitzkrieg/tankopedia';
export interface SpecialStats { export interface SpecialStats {
winrate: number; winrate: number;
+1 -1
View File
@@ -4,7 +4,7 @@ import {
CacheType, CacheType,
} from 'discord.js'; } from 'discord.js';
import { go } from 'fuzzysort'; import { go } from 'fuzzysort';
import { TANK_NAMES_DIACRITICS } from '../blitzstars/tankopedia'; import { TANK_NAMES_DIACRITICS } from '../blitzkrieg/tankopedia';
import { import {
DISCORD_CHOICES_MAX_NAME_SIZE, DISCORD_CHOICES_MAX_NAME_SIZE,
OVERFLOW_SUFFIX, OVERFLOW_SUFFIX,
+5 -8
View File
@@ -1,7 +1,7 @@
import { TreeTypeString } from '../../components/Tanks'; import { TreeTypeString } from '../../components/Tanks';
import { tankopedia } from '../blitzkrieg/tankopedia';
import { DiffedTankStats } from '../blitzstars/getStatsInPeriod'; import { DiffedTankStats } from '../blitzstars/getStatsInPeriod';
import { tankAverages } from '../blitzstars/tankAverages'; import { tankAverages } from '../blitzstars/tankAverages';
import { tankopedia } from '../blitzstars/tankopedia';
import calculateWN8 from './calculateWN8'; import calculateWN8 from './calculateWN8';
import sumStats from './sumStats'; import sumStats from './sumStats';
@@ -31,14 +31,11 @@ export async function filterStats(
(filters.tier === undefined || entry.tier === filters.tier) && (filters.tier === undefined || entry.tier === filters.tier) &&
(filters.tankType === undefined || entry.type === filters.tankType) && (filters.tankType === undefined || entry.type === filters.tankType) &&
(filters.treeType === undefined || (filters.treeType === undefined ||
(filters.treeType === 'collector' && entry.is_collectible) || (filters.treeType === 'collector' && entry.tree_type === 'collector') ||
(filters.treeType === 'premium' && (filters.treeType === 'premium' && entry.tree_type === 'premium') ||
entry.is_premium &&
!entry.is_collectible) ||
(filters.treeType === 'tech-tree' && (filters.treeType === 'tech-tree' &&
!entry.is_collectible && entry.tree_type === 'tech-tree')) &&
!entry.is_premium)) && (filters.tank === undefined || entry.id === filters.tank)
(filters.tank === undefined || entry.tank_id === filters.tank)
); );
}); });
const stats = sumStats(filteredOrder.map((id) => diff[id])); const stats = sumStats(filteredOrder.map((id) => diff[id]));
+2 -2
View File
@@ -1,6 +1,6 @@
import { TierWeightsRecord } from '../../components/TierWeights'; import { TierWeightsRecord } from '../../components/TierWeights';
import { AllStats } from '../blitz/getAccountInfo'; import { AllStats } from '../blitz/getAccountInfo';
import { tankopedia } from '../blitzstars/tankopedia'; import { tankopedia } from '../blitzkrieg/tankopedia';
export async function getTierWeights( export async function getTierWeights(
stats: Record<number, AllStats>, stats: Record<number, AllStats>,
@@ -9,7 +9,7 @@ export async function getTierWeights(
const awaitedTankopedia = await tankopedia; const awaitedTankopedia = await tankopedia;
const tierWeights: TierWeightsRecord = {}; const tierWeights: TierWeightsRecord = {};
order.map((id) => { order.forEach((id) => {
const entry = awaitedTankopedia[id]; const entry = awaitedTankopedia[id];
if (!entry) return; if (!entry) return;