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 { ElementCompact, xml2js } from 'xml-js';
import { parse } from 'yaml';
import { TreeTypeString } from '../src/components/Tanks';
import { NATION_IDS } from '../src/constants/nations';
import { BlitzkriegTankopedia, Tier } from '../src/core/blitzkrieg/tankopedia';
import commitMultipleFiles, { FileChange } from './commitMultipleFiles';
const LANGUAGE = 'en';
@@ -45,21 +45,11 @@ if (!noRewrite) {
console.log('Creating new tankopedia folder');
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(
`${TEMP}/${directoriesOfInterest.strings}/${LANGUAGE}.yaml`,
'utf-8',
).then((data) => load(data) as Record<string, string>);
const tankopedia: Record<number, BlitzkriegTankopedia> = {};
const tankopedia: BlitzkriegTankopedia = {};
const tankIds: number[] = [];
const images: Record<number, { big: string; small: string }> = {};
const nations = await readdir(
@@ -89,7 +79,7 @@ Promise.all(
const isCollector = vehicleData.sellPrice
? 'gold' in vehicleData.sellPrice
: false;
const tier = parseInt(vehicleData.level._text);
const tier = parseInt(vehicleData.level._text) as Tier;
const tags = vehicleData.tags._text.split(' ');
const type = tags[0];
@@ -174,7 +164,7 @@ Promise.all(
'blitzkrieg-assets',
'main',
new Date().toString(),
iconsChange,
[tankopediaChange, ...iconsChange],
true,
);
} else {
+1 -1
View File
@@ -1,5 +1,5 @@
import { NextResponse } from 'next/server';
import { tankopedia } from '../../../core/blitzstars/tankopedia';
import { tankopedia } from '../../../core/blitzkrieg/tankopedia';
export async function GET() {
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 { WARGAMING_APPLICATION_ID } from '../../../constants/wargamingApplicationID';
import fetchBlitz from '../../../core/blitz/fetchBlitz';
import { tankAverages } from '../../../core/blitzstars/tankAverages';
import {
TankopediaEntry,
BlitzkriegTankopediaEntry,
tankopedia,
} from '../../../core/blitzstars/tankopedia';
} from '../../../core/blitzkrieg/tankopedia';
import { tankAverages } from '../../../core/blitzstars/tankAverages';
import calculateWN8 from '../../../core/statistics/calculateWN8';
import { deltaTankStats } from '../../../core/statistics/deltaTankStats';
import getWN8Percentile from '../../../core/statistics/getWN8Percentile';
@@ -30,7 +30,7 @@ export default function SessionPage() {
list: {
stats: IndividualTankStats;
tankopedia?: TankopediaEntry;
tankopedia?: BlitzkriegTankopediaEntry;
career: IndividualTankStats;
currentWN8?: number;
careerWN8?: number;
@@ -299,9 +299,10 @@ export default function SessionPage() {
type="tank"
tankType={tankopedia?.type}
treeType={(() => {
if (tankopedia?.is_collectible)
if (tankopedia?.tree_type === 'collector')
return TreeTypeEnum.Collector;
if (tankopedia?.is_premium) return TreeTypeEnum.Premium;
if (tankopedia?.tree_type === 'premium')
return TreeTypeEnum.Premium;
})()}
stats={session.customColumns.map((customColumn) => {
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 resolveTankName from '../core/blitz/resolveTankName';
import { filtersToDescription } from '../core/blitzkrieg/filtersToDescription';
import { tankopedia } from '../core/blitzkrieg/tankopedia';
import { getBlitzStarsLinkButton } from '../core/blitzstars/getBlitzStarsLinkButton';
import getStatsInPeriod from '../core/blitzstars/getStatsInPeriod';
import { tankAverages } from '../core/blitzstars/tankAverages';
import { tankopedia } from '../core/blitzstars/tankopedia';
import addFilterOptions from '../core/discord/addFilterOptions';
import addUsernameChoices from '../core/discord/addUsernameChoices';
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 getPeriodNow from '../core/blitzkrieg/getPeriodNow';
import getTimeDaysAgo from '../core/blitzkrieg/getTimeDaysAgo';
import { tankopedia } from '../core/blitzkrieg/tankopedia';
import getStatsInPeriod from '../core/blitzstars/getStatsInPeriod';
import { tankAverages } from '../core/blitzstars/tankAverages';
import { tankopedia } from '../core/blitzstars/tankopedia';
import addUsernameChoices from '../core/discord/addUsernameChoices';
import embedNegative from '../core/discord/embedNegative';
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 { tankopediaInfo } from '../core/blitz/tankopediaInfo';
import { emblemIdToURL } from '../core/blitzkrieg/emblemIdToURL';
import { tankIcon } from '../core/blitzkrieg/tankIcon';
import {
BlitzkriegTankopediaEntry,
TIER_ROMAN_NUMERALS,
TankopediaEntry,
Tier,
tankopedia,
} from '../core/blitzstars/tankopedia';
} from '../core/blitzkrieg/tankopedia';
import addTierChoices from '../core/discord/addTierChoices';
import addUsernameChoices from '../core/discord/addUsernameChoices';
import autocompleteUsername from '../core/discord/autocompleteUsername';
@@ -42,12 +43,12 @@ export const ownedTanksCommand: CommandRegistry = {
await Promise.all(
tankStats.map(async (tankData) => ({
tankopedia: (await tankopedia)[tankData.tank_id]!,
tank_id: tankData.tank_id,
id: tankData.tank_id,
})),
)
).filter((tank) => tank.tankopedia?.tier === tier);
const clanAccountInfo = await getClanAccountInfo(server, id, ['clan']);
const groupedTanks: Record<string, TankopediaEntry[]> = {};
const groupedTanks: Record<string, BlitzkriegTankopediaEntry[]> = {};
const nations: string[] = [];
filteredTanks.forEach((tank) => {
@@ -94,11 +95,11 @@ export const ownedTanksCommand: CommandRegistry = {
{await Promise.all(
leftColumn.map(async (tank) => (
<Tanks.Item
key={tank.tank_id}
name={await resolveTankName(tank.tank_id)}
key={tank.id}
name={await resolveTankName(tank.id)}
tankType={tank.type}
image={tank.images?.normal}
treeType={await getTreeType(tank.tank_id)}
image={tankIcon(tank.id)}
treeType={await getTreeType(tank.id)}
/>
)),
)}
@@ -107,11 +108,11 @@ export const ownedTanksCommand: CommandRegistry = {
{await Promise.all(
rightColumn.map(async (tank) => (
<Tanks.Item
key={tank.tank_id}
name={await resolveTankName(tank.tank_id)}
key={tank.id}
name={await resolveTankName(tank.id)}
tankType={tank.type}
image={tank.images?.normal}
treeType={await getTreeType(tank.tank_id)}
image={tankIcon(tank.id)}
treeType={await getTreeType(tank.id)}
/>
)),
)}
+1 -1
View File
@@ -1,7 +1,7 @@
import { SlashCommandBuilder } from 'discord.js';
import { go } from 'fuzzysort';
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 embedInfo from '../core/discord/embedInfo';
import { CommandRegistry } from '../events/interactionCreate';
+1 -1
View File
@@ -2,7 +2,7 @@ import {
TANK_ICONS,
TANK_ICONS_COLLECTOR,
TANK_ICONS_PREMIUM,
} from '../../../core/blitzstars/tankopedia';
} from '../../../core/blitzkrieg/tankopedia';
import { theme } from '../../../stitches.config';
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';
export type TierWeightsRecord = Partial<Record<Tier, number>>;
+3 -3
View File
@@ -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;
}
+2 -2
View File
@@ -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 -1
View File
@@ -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;
+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 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,
+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 { 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 -1
View File
@@ -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;
+1 -1
View File
@@ -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,
+5 -8
View File
@@ -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]));
+2 -2
View File
@@ -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;