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

+94 -92
View File
@@ -7,9 +7,9 @@ import { TreeTypeEnum } from '../../../components/Tanks';
import { WARGAMING_APPLICATION_ID } from '../../../constants/wargamingApplicationID';
import fetchBlitz from '../../../core/blitz/fetchBlitz';
import {
BlitzkriegTankopediaEntry,
tankopedia,
} from '../../../core/blitzkrieg/tankopedia';
TankDefinition,
tankDefinitions,
} from '../../../core/blitzkrieg/definitions/tanks';
import { tankAverages } from '../../../core/blitzstars/tankAverages';
import calculateWN8 from '../../../core/statistics/calculateWN8';
import { deltaTankStats } from '../../../core/statistics/deltaTankStats';
@@ -30,7 +30,7 @@ export default function SessionPage() {
list: {
stats: IndividualTankStats;
tankopedia?: BlitzkriegTankopediaEntry;
tankDefinitions?: TankDefinition;
career: IndividualTankStats;
currentWN8?: number;
careerWN8?: number;
@@ -88,7 +88,7 @@ export default function SessionPage() {
}),
{},
);
const awaitedTankopedia = await tankopedia;
const awaitedTankDefinitions = await tankDefinitions;
const awaitedTankAverages = await tankAverages;
const careerWN8 =
careerRaw[id].reduce(
@@ -119,7 +119,7 @@ export default function SessionPage() {
).map((stats) => {
return {
stats,
tankopedia: awaitedTankopedia[stats.tank_id],
tankDefinitions: awaitedTankDefinitions[stats.tank_id],
career: career[stats.tank_id],
currentWN8: awaitedTankAverages[stats.tank_id]
? calculateWN8(
@@ -238,95 +238,97 @@ export default function SessionPage() {
.sort(
(a, b) => b.stats.last_battle_time - a.stats.last_battle_time,
)
.map(({ stats, tankopedia, career, careerWN8, currentWN8 }) => {
const rowStats: Record<
CustomColumnDisplay,
Breakdown.RowStatItem | undefined
> = {
battles: {
title: 'Battles',
current: stats.all.battles.toLocaleString(),
career: career.all.battles.toLocaleString(),
},
winrate: {
title: 'Winrate',
current: `${(
100 *
(stats.all.wins / stats.all.battles)
).toFixed(2)}%`,
career: `${(
100 *
(career.all.wins / career.all.battles)
).toFixed(2)}%`,
delta:
stats.all.wins / stats.all.battles -
career.all.wins / career.all.battles,
},
wn8: {
title: 'WN8',
current:
currentWN8 === undefined
? undefined
: Math.round(currentWN8).toLocaleString(),
career:
careerWN8 === undefined
? undefined
: Math.round(careerWN8).toLocaleString(),
percentile:
currentWN8 === undefined
? undefined
: getWN8Percentile(currentWN8),
},
damage: {
title: 'Damage',
current: Math.round(
stats.all.damage_dealt / stats.all.battles,
).toLocaleString(),
career: Math.round(
career.all.damage_dealt / career.all.battles,
).toLocaleString(),
delta:
stats.all.damage_dealt / stats.all.battles -
career.all.damage_dealt / career.all.battles,
},
none: undefined,
};
.map(
({ stats, tankDefinitions, career, careerWN8, currentWN8 }) => {
const rowStats: Record<
CustomColumnDisplay,
Breakdown.RowStatItem | undefined
> = {
battles: {
title: 'Battles',
current: stats.all.battles.toLocaleString(),
career: career.all.battles.toLocaleString(),
},
winrate: {
title: 'Winrate',
current: `${(
100 *
(stats.all.wins / stats.all.battles)
).toFixed(2)}%`,
career: `${(
100 *
(career.all.wins / career.all.battles)
).toFixed(2)}%`,
delta:
stats.all.wins / stats.all.battles -
career.all.wins / career.all.battles,
},
wn8: {
title: 'WN8',
current:
currentWN8 === undefined
? undefined
: Math.round(currentWN8).toLocaleString(),
career:
careerWN8 === undefined
? undefined
: Math.round(careerWN8).toLocaleString(),
percentile:
currentWN8 === undefined
? undefined
: getWN8Percentile(currentWN8),
},
damage: {
title: 'Damage',
current: Math.round(
stats.all.damage_dealt / stats.all.battles,
).toLocaleString(),
career: Math.round(
career.all.damage_dealt / career.all.battles,
).toLocaleString(),
delta:
stats.all.damage_dealt / stats.all.battles -
career.all.damage_dealt / career.all.battles,
},
none: undefined,
};
return (
<Breakdown.Row
color={session.color}
key={stats.tank_id}
minimized={!session.showCareer}
title={
tankopedia?.name_short ??
tankopedia?.name ??
`Unknown tank ${stats.tank_id}`
}
type="tank"
tankType={tankopedia?.type}
treeType={(() => {
if (tankopedia?.tree_type === 'collector')
return TreeTypeEnum.Collector;
if (tankopedia?.tree_type === 'premium')
return TreeTypeEnum.Premium;
})()}
stats={session.customColumns.map((customColumn) => {
const rowStat = rowStats[customColumn.display];
return (
<Breakdown.Row
color={session.color}
key={stats.tank_id}
minimized={!session.showCareer}
title={
tankDefinitions?.name_short ??
tankDefinitions?.name ??
`Unknown tank ${stats.tank_id}`
}
type="tank"
tankType={tankDefinitions?.type}
treeType={(() => {
if (tankDefinitions?.tree_type === 'collector')
return TreeTypeEnum.Collector;
if (tankDefinitions?.tree_type === 'premium')
return TreeTypeEnum.Premium;
})()}
stats={session.customColumns.map((customColumn) => {
const rowStat = rowStats[customColumn.display];
if (!rowStat) return undefined;
if (!rowStat) return undefined;
return {
...rowStat,
delta:
customColumn.showDelta &&
rowStat.percentile === undefined
? rowStat.delta
: undefined,
};
})}
/>
);
})}
return {
...rowStat,
delta:
customColumn.showDelta &&
rowStat.percentile === undefined
? rowStat.delta
: undefined,
};
})}
/>
);
},
)}
</Breakdown.Root>
</div>
</ContextMenu.Trigger>
@@ -15,7 +15,7 @@ import {
NATIONS,
TIERS,
TIER_ROMAN_NUMERALS,
} from '../../../../core/blitzkrieg/tankopedia';
} from '../../../../core/blitzkrieg/definitions/tanks';
import mutateTankopedia, {
TankopediaSortBy,
TankopediaSortDirection,
@@ -1,12 +1,12 @@
import { CaretLeftIcon, CaretRightIcon } from '@radix-ui/react-icons';
import { Button, Flex, TextField } from '@radix-ui/themes';
import { useEffect, useRef } from 'react';
import { BlitzkriegTankopediaEntry } from '../../../../core/blitzkrieg/tankopedia';
import { TankDefinition } from '../../../../core/blitzkrieg/definitions/tanks';
interface PageTurnerProps {
page: number;
setPage: (page: number) => void;
searchedList: BlitzkriegTankopediaEntry[];
searchedList: TankDefinition[];
tanksPerPage: number;
}
+6 -6
View File
@@ -7,15 +7,15 @@ import { go } from 'fuzzysort';
import { Suspense, use, useEffect, useMemo, useRef, useState } from 'react';
import PageWrapper from '../../../components/PageWrapper';
import { asset } from '../../../core/blitzkrieg/asset';
import { tankIcon } from '../../../core/blitzkrieg/tankIcon';
import {
BlitzkriegTankopediaEntry,
TANK_ICONS,
TANK_ICONS_COLLECTOR,
TANK_ICONS_PREMIUM,
TIER_ROMAN_NUMERALS,
tanks,
} from '../../../core/blitzkrieg/tankopedia';
TankDefinition,
tanksDefinitionsArray,
} from '../../../core/blitzkrieg/definitions/tanks';
import { tankIcon } from '../../../core/blitzkrieg/tankIcon';
import { theme } from '../../../stitches.config';
import { useTankopedia } from '../../../stores/tankopedia';
import { Options } from './components/Options';
@@ -26,7 +26,7 @@ const TANKS_PER_PAGE = 3 * 2 ** 4;
export default function Page() {
const tankopediaState = useTankopedia();
const awaitedTanks = use(tanks);
const awaitedTanks = use(tanksDefinitionsArray);
const input = useRef<HTMLInputElement>(null);
const searchableTanks = useMemo(
() =>
@@ -102,7 +102,7 @@ export default function Page() {
'name',
'name_short',
'id',
] satisfies (keyof BlitzkriegTankopediaEntry)[],
] satisfies (keyof TankDefinition)[],
}).map(({ obj }) => obj),
);
}