mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 10:47:04 +02:00
fix: all commands now work with a lack of tankopedia entries
This commit is contained in:
1 parent
f907c79d68
commit
ca208e44a1
12 files changed
+59
-26
No files matched your search
@@ -71,12 +71,27 @@ export const eligibleCommand: CommandRegistry = {
|
||||
(await entries.reduce<PossiblyPromise<number>>(
|
||||
async (accumulator, [tankIdString, stats]) => {
|
||||
const tankId = parseInt(tankIdString);
|
||||
const tankTier = (await tankopedia)[tankId].tier;
|
||||
const tankopediaEntry = (await tankopedia)[tankId];
|
||||
|
||||
if (!tankopediaEntry) return accumulator;
|
||||
|
||||
const tankTier = tankopediaEntry.tier;
|
||||
|
||||
return (await accumulator) + tankTier * stats.battles;
|
||||
},
|
||||
0,
|
||||
)) / stats.battles;
|
||||
)) /
|
||||
(await entries.reduce<PossiblyPromise<number>>(
|
||||
async (accumulator, [tankIdString, stats]) => {
|
||||
const tankId = parseInt(tankIdString);
|
||||
const tankopediaEntry = (await tankopedia)[tankId];
|
||||
|
||||
if (!tankopediaEntry) return accumulator;
|
||||
|
||||
return stats.battles;
|
||||
},
|
||||
0,
|
||||
));
|
||||
const WN8 =
|
||||
(await entries.reduce<PossiblyPromise<number>>(
|
||||
async (accumulator, [tankIdString, stats]) => {
|
||||
|
||||
@@ -7,6 +7,7 @@ import Wrapper from '../components/Wrapper.js';
|
||||
import { BLITZ_SERVERS } from '../constants/servers.js';
|
||||
import getTankStats from '../core/blitz/getTankStats.js';
|
||||
import getWargamingResponse from '../core/blitz/getWargamingResponse.js';
|
||||
import resolveTankName from '../core/blitz/resolveTankName.js';
|
||||
import {
|
||||
TIER_ROMAN_NUMERALS,
|
||||
Tier,
|
||||
@@ -79,7 +80,10 @@ export const ownedTanksCommand: CommandRegistry = {
|
||||
const tankStats = await getTankStats(server, id);
|
||||
const tanks = (
|
||||
await Promise.all(
|
||||
tankStats.map(async (tankData) => (await tankopedia)[tankData.tank_id]),
|
||||
tankStats.map(async (tankData) => ({
|
||||
...(await tankopedia)[tankData.tank_id],
|
||||
tank_id: tankData.tank_id,
|
||||
})),
|
||||
)
|
||||
).filter((tank) => tank?.tier === tier);
|
||||
const clanData = await getWargamingResponse<PlayerClanData>(
|
||||
@@ -106,14 +110,16 @@ export const ownedTanksCommand: CommandRegistry = {
|
||||
|
||||
{tanks.length > 0 && (
|
||||
<Tanks.Root>
|
||||
{tanks.map((tank) => (
|
||||
<Tanks.Item
|
||||
key={tank.tank_id}
|
||||
name={tank.name}
|
||||
type={tank.type}
|
||||
icon={tank.images.normal}
|
||||
/>
|
||||
))}
|
||||
{await Promise.all(
|
||||
tanks.map(async (tank) => (
|
||||
<Tanks.Item
|
||||
key={tank.tank_id}
|
||||
name={await resolveTankName(tank.tank_id)}
|
||||
type={tank.type}
|
||||
icon={tank.images?.normal}
|
||||
/>
|
||||
)),
|
||||
)}
|
||||
</Tanks.Root>
|
||||
)}
|
||||
|
||||
|
||||
@@ -69,7 +69,9 @@ export default function AllStatsOverview({
|
||||
>
|
||||
<WN8SurroundingStat
|
||||
label="Tier"
|
||||
value={supplementaryStats.tier.toFixed(2)}
|
||||
value={
|
||||
supplementaryStats.tier ? supplementaryStats.tier.toFixed(2) : '--'
|
||||
}
|
||||
/>
|
||||
<WN8SurroundingStat
|
||||
label="Survival"
|
||||
|
||||
@@ -40,7 +40,10 @@ export default function GenericAllStats({
|
||||
['Wins', stats.wins],
|
||||
['Losses', stats.losses],
|
||||
['Average damage', (stats.damage_dealt / stats.battles).toFixed(0)],
|
||||
['Average tier', supplementaryStats?.tier.toFixed(2)],
|
||||
[
|
||||
'Average tier',
|
||||
supplementaryStats?.tier ? supplementaryStats?.tier.toFixed(2) : '--',
|
||||
],
|
||||
['Average XP', (stats.xp / stats.battles).toFixed(0)],
|
||||
['Average shots', (stats.shots / stats.battles).toFixed(2)],
|
||||
['Average hits', (stats.hits / stats.battles).toFixed(2)],
|
||||
|
||||
@@ -2,7 +2,7 @@ import { TANK_ICONS, TankType } from '../../../core/blitz/tankopedia.js';
|
||||
|
||||
export interface ItemProps {
|
||||
icon?: string;
|
||||
type: TankType;
|
||||
type?: TankType;
|
||||
name: string;
|
||||
}
|
||||
|
||||
@@ -23,7 +23,10 @@ export function Item({ icon, type, name }: ItemProps) {
|
||||
{icon && <img src={icon} style={{ flex: 1, objectFit: 'contain' }} />}
|
||||
|
||||
<div style={{ display: 'flex', margin: 'auto', gap: 4 }}>
|
||||
<img src={TANK_ICONS[type]} style={{ width: 14, height: 14 }} />
|
||||
{type && (
|
||||
<img src={TANK_ICONS[type]} style={{ width: 14, height: 14 }} />
|
||||
)}
|
||||
|
||||
<span
|
||||
style={{ fontSize: 16, textAlign: 'center', whiteSpace: 'nowrap' }}
|
||||
>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { tankopedia } from './tankopedia.js';
|
||||
|
||||
export default async function resolveTankName(tankId: number) {
|
||||
const tankopediaName = (await tankopedia)[tankId].name;
|
||||
const tankopediaName = (await tankopedia)[tankId]?.name;
|
||||
return tankopediaName ? tankopediaName : `Unknown Tank ${tankId}`;
|
||||
}
|
||||
@@ -13,7 +13,7 @@ export interface TankopediaEntry {
|
||||
}
|
||||
|
||||
export interface Tankopedia {
|
||||
[id: number]: TankopediaEntry;
|
||||
[id: number]: TankopediaEntry | undefined;
|
||||
}
|
||||
|
||||
console.log('Caching tankopedia...');
|
||||
|
||||
@@ -39,7 +39,7 @@ export default async function evolution<Type extends StatType>(
|
||||
: undefined;
|
||||
} else {
|
||||
nameDiscriminator = `(${await resolveTankName(tankId!)})`;
|
||||
image = (await tankopedia)[tankId!].images.normal;
|
||||
image = (await tankopedia)[tankId!]?.images.normal;
|
||||
}
|
||||
|
||||
let histories: Histories;
|
||||
|
||||
@@ -49,7 +49,7 @@ export default async function stats<Type extends StatType>(
|
||||
: undefined;
|
||||
} else if (type === 'tank') {
|
||||
nameDiscriminator = `(${await resolveTankName(tankId!)})`;
|
||||
image = (await tankopedia)[tankId!].images.normal;
|
||||
image = (await tankopedia)[tankId!]?.images.normal;
|
||||
}
|
||||
|
||||
const tankStats = await getTankStatsDiffed(server, id, start, end);
|
||||
@@ -109,7 +109,11 @@ export default async function stats<Type extends StatType>(
|
||||
tierWeights = await entries.reduce<PossiblyPromise<TierWeightsRecord>>(
|
||||
async (accumulator, [tankIdString, stats]) => {
|
||||
const tankId = parseInt(tankIdString);
|
||||
const tier = (await tankopedia)[tankId].tier as Tier;
|
||||
const tankopediaEntry = (await tankopedia)[tankId];
|
||||
|
||||
if (!tankopediaEntry) return accumulator;
|
||||
|
||||
const tier = tankopediaEntry.tier as Tier;
|
||||
|
||||
if ((await accumulator)[tier]) {
|
||||
(await accumulator)[tier]! += stats.battles;
|
||||
@@ -128,7 +132,7 @@ export default async function stats<Type extends StatType>(
|
||||
WN8: stats
|
||||
? calculateWN8((await tankAverages)[tankId!].all, tankStats[tankId!])
|
||||
: undefined,
|
||||
tier: (await tankopedia)[tankId!].tier,
|
||||
tier: (await tankopedia)[tankId!]?.tier,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ export default async function statsfull<Type extends StatType>(
|
||||
: undefined;
|
||||
} else if (type === 'tank') {
|
||||
nameDiscriminator = `(${await resolveTankName(tankId!)})`;
|
||||
image = (await tankopedia)[tankId!].images.normal;
|
||||
image = (await tankopedia)[tankId!]?.images.normal;
|
||||
}
|
||||
|
||||
const tankStats = await getTankStatsDiffed(server, id, start, end);
|
||||
@@ -111,7 +111,7 @@ export default async function statsfull<Type extends StatType>(
|
||||
|
||||
if (!tankopediaEntry) return accumulator;
|
||||
|
||||
const tier = (await tankopedia)[tankId].tier as Tier;
|
||||
const tier = tankopediaEntry.tier as Tier;
|
||||
|
||||
if ((await accumulator)[tier]) {
|
||||
(await accumulator)[tier]! += stats.battles;
|
||||
@@ -128,7 +128,7 @@ export default async function statsfull<Type extends StatType>(
|
||||
|
||||
supplementaryStats = {
|
||||
WN8: calculateWN8((await tankAverages)[tankId!].all, tankStats[tankId!]),
|
||||
tier: (await tankopedia)[tankId!].tier,
|
||||
tier: (await tankopedia)[tankId!]?.tier,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -132,7 +132,7 @@ export default async function today({ server, id }: ResolvedPlayer) {
|
||||
icon={
|
||||
tankId === 0
|
||||
? undefined
|
||||
: (await tankopedia)[tankIdString as unknown as number].images
|
||||
: (await tankopedia)[tankIdString as unknown as number]?.images
|
||||
.normal
|
||||
}
|
||||
/>
|
||||
|
||||
@@ -21,7 +21,7 @@ export interface AllStats {
|
||||
export interface SupplementaryStats {
|
||||
// if undefined, WN8 is not available for tanks without averages
|
||||
WN8?: number;
|
||||
tier: number;
|
||||
tier?: number;
|
||||
}
|
||||
|
||||
export interface ClanStats {
|
||||
|
||||
Reference in new issue
Block a user