mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-11-18 11:25:25 +01:00
performance table rewrite and shared sort direction
This commit is contained in:
38 files changed
+965
-874
No files matched your search
@@ -51,6 +51,16 @@
|
|||||||
"open": "Open in Tankopedia"
|
"open": "Open in Tankopedia"
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"performance": {
|
||||||
|
"player_count": "Player count",
|
||||||
|
"tank": "Tank",
|
||||||
|
"total": "Total",
|
||||||
|
"no_tanks": {
|
||||||
|
"title": "No tanks found",
|
||||||
|
"body": "No tanks with statistics match these filters"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
"units": {
|
"units": {
|
||||||
"m": "{value}m",
|
"m": "{value}m",
|
||||||
"mm": "{value}mm",
|
"mm": "{value}mm",
|
||||||
@@ -500,6 +510,22 @@
|
|||||||
"d_1": "Yesterday"
|
"d_1": "Yesterday"
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"stats": {
|
||||||
|
"winrate": "Winrate",
|
||||||
|
"players": "Players",
|
||||||
|
"damage": "Damage",
|
||||||
|
"survival": "Survival",
|
||||||
|
"xp": "XP",
|
||||||
|
"kills": "Kills",
|
||||||
|
"spots": "Spots",
|
||||||
|
"accuracy": "Accuracy",
|
||||||
|
"shots": "Shots",
|
||||||
|
"hits": "Hits",
|
||||||
|
"damage_ratio": "Dmg. ratio",
|
||||||
|
"damage_taken": "Dmg. taken",
|
||||||
|
"capture_points": "Cap points"
|
||||||
|
},
|
||||||
|
|
||||||
"branches": {
|
"branches": {
|
||||||
"beta": "Beta",
|
"beta": "Beta",
|
||||||
"development": "Post Malone Edition",
|
"development": "Post Malone Edition",
|
||||||
|
|||||||
@@ -1,41 +0,0 @@
|
|||||||
import { Table } from "@radix-ui/themes";
|
|
||||||
import type { CellProps } from "@radix-ui/themes/components/table";
|
|
||||||
|
|
||||||
export enum CompareCellDirection {
|
|
||||||
HIGHER_IS_BETTER,
|
|
||||||
LOWER_IS_BETTER,
|
|
||||||
}
|
|
||||||
|
|
||||||
interface CompareCellProps extends CellProps {
|
|
||||||
value: number;
|
|
||||||
truth: number;
|
|
||||||
direction?: CompareCellDirection;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function CompareCell({
|
|
||||||
value,
|
|
||||||
truth,
|
|
||||||
style,
|
|
||||||
direction = CompareCellDirection.HIGHER_IS_BETTER,
|
|
||||||
...props
|
|
||||||
}: CompareCellProps) {
|
|
||||||
const percentage = value / truth - 1;
|
|
||||||
const shiftedPercentage = Math.round(
|
|
||||||
Math.min(100, Math.abs(percentage) * 2 * 100 + 25)
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Table.Cell
|
|
||||||
style={{
|
|
||||||
backgroundColor:
|
|
||||||
value === truth
|
|
||||||
? undefined
|
|
||||||
: (direction === CompareCellDirection.HIGHER_IS_BETTER) ===
|
|
||||||
value > truth
|
|
||||||
? `color-mix(in srgb, var(--green-7) ${shiftedPercentage}%, var(--green-3))`
|
|
||||||
: `color-mix(in srgb, var(--red-7) ${shiftedPercentage}%, var(--red-3))`,
|
|
||||||
}}
|
|
||||||
{...props}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,8 +1,3 @@
|
|||||||
.logo {
|
|
||||||
margin: auto;
|
|
||||||
color: var(--gray-a5);
|
|
||||||
}
|
|
||||||
|
|
||||||
.label {
|
.label {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
|||||||
@@ -10,18 +10,16 @@ import { characteristicsGroups } from "../../config/characteristicsGroups";
|
|||||||
import { computeCharacteristics } from "../../hooks/useCharacteristics";
|
import { computeCharacteristics } from "../../hooks/useCharacteristics";
|
||||||
import { useStrings } from "../../hooks/useStrings";
|
import { useStrings } from "../../hooks/useStrings";
|
||||||
import { useUnwrapper } from "../../hooks/useUnwrapper";
|
import { useUnwrapper } from "../../hooks/useUnwrapper";
|
||||||
import { Logo } from "../../icons/Logo";
|
|
||||||
import {
|
import {
|
||||||
CompareEphemeral,
|
CompareEphemeral,
|
||||||
syncShellSlot,
|
syncShellSlot,
|
||||||
type CompareMember,
|
type CompareMember,
|
||||||
} from "../../stores/compareEphemeral";
|
} from "../../stores/compareEphemeral";
|
||||||
import { ComparePersistent } from "../../stores/comparePersistent";
|
import { ComparePersistent } from "../../stores/comparePersistent";
|
||||||
import { TankopediaSortDirection } from "../../stores/tankopediaPersistent";
|
import { SortDirection } from "../../stores/tankopediaPersistent";
|
||||||
import { rankingValue } from "../../tankopedia/calculateRankings";
|
import { rankingValue } from "../../tankopedia/calculateRankings";
|
||||||
import { resolveTankModules } from "../../tankopedia/resolveTankModules";
|
import { resolveTankModules } from "../../tankopedia/resolveTankModules";
|
||||||
import {
|
import {
|
||||||
CharacteristicRanking,
|
|
||||||
type CharacteristicName,
|
type CharacteristicName,
|
||||||
type CharacteristicRenderConfig,
|
type CharacteristicRenderConfig,
|
||||||
type ComputedCharacteristics,
|
type ComputedCharacteristics,
|
||||||
@@ -79,10 +77,9 @@ export function CompareTable() {
|
|||||||
<Table.Root scrollable>
|
<Table.Root scrollable>
|
||||||
<Table.Head>
|
<Table.Head>
|
||||||
<Table.Row>
|
<Table.Row>
|
||||||
<Table.Corner>
|
<Table.IconCorner>
|
||||||
<Logo className={styles.logo} width={64} height={64} />
|
|
||||||
<CompareInsertionMarker index={0} />
|
<CompareInsertionMarker index={0} />
|
||||||
</Table.Corner>
|
</Table.IconCorner>
|
||||||
|
|
||||||
{members.map(({ key, state }, index) => (
|
{members.map(({ key, state }, index) => (
|
||||||
<CompareTankCard
|
<CompareTankCard
|
||||||
@@ -255,14 +252,12 @@ function Row({ config, characteristics }: RowProps) {
|
|||||||
onClick={() => sort(config.name, values, members)}
|
onClick={() => sort(config.name, values, members)}
|
||||||
>
|
>
|
||||||
{!isSorted && <CaretSortIcon className={styles.sort} />}
|
{!isSorted && <CaretSortIcon className={styles.sort} />}
|
||||||
{isSorted &&
|
{isSorted && sorting.direction === SortDirection.Ascending && (
|
||||||
sorting.direction === TankopediaSortDirection.Ascending && (
|
<CaretRightIcon />
|
||||||
<CaretRightIcon />
|
)}
|
||||||
)}
|
{isSorted && sorting.direction === SortDirection.Descending && (
|
||||||
{isSorted &&
|
<CaretLeftIcon />
|
||||||
sorting.direction === TankopediaSortDirection.Descending && (
|
)}
|
||||||
<CaretLeftIcon />
|
|
||||||
)}
|
|
||||||
</IconButton>
|
</IconButton>
|
||||||
|
|
||||||
<Text>{label}</Text>
|
<Text>{label}</Text>
|
||||||
@@ -282,10 +277,12 @@ function Row({ config, characteristics }: RowProps) {
|
|||||||
value !== undefined && truth !== undefined ? value - truth : 0;
|
value !== undefined && truth !== undefined ? value - truth : 0;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Table.Cell
|
<Table.CellRanked
|
||||||
key={members[index].key}
|
key={members[index].key}
|
||||||
align="end"
|
align="end"
|
||||||
style={{ backgroundColor: cellColor(config, value, truth) }}
|
ranking={config.ranking}
|
||||||
|
value={value}
|
||||||
|
truth={truth}
|
||||||
>
|
>
|
||||||
<div className={styles.value}>
|
<div className={styles.value}>
|
||||||
{output && (
|
{output && (
|
||||||
@@ -314,7 +311,7 @@ function Row({ config, characteristics }: RowProps) {
|
|||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</Table.Cell>
|
</Table.CellRanked>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
</Table.Row>
|
</Table.Row>
|
||||||
@@ -331,7 +328,7 @@ function sort(
|
|||||||
CompareEphemeral.mutate((draft) => {
|
CompareEphemeral.mutate((draft) => {
|
||||||
const ascending =
|
const ascending =
|
||||||
draft.sorting?.by === name &&
|
draft.sorting?.by === name &&
|
||||||
draft.sorting.direction === TankopediaSortDirection.Descending;
|
draft.sorting.direction === SortDirection.Descending;
|
||||||
|
|
||||||
// Missing values always sink to the end
|
// Missing values always sink to the end
|
||||||
draft.members.sort((a, b) => {
|
draft.members.sort((a, b) => {
|
||||||
@@ -347,34 +344,7 @@ function sort(
|
|||||||
|
|
||||||
draft.sorting = {
|
draft.sorting = {
|
||||||
by: name,
|
by: name,
|
||||||
direction: ascending
|
direction: ascending ? SortDirection.Ascending : SortDirection.Descending,
|
||||||
? TankopediaSortDirection.Ascending
|
|
||||||
: TankopediaSortDirection.Descending,
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function cellColor(
|
|
||||||
config: CharacteristicRenderConfig,
|
|
||||||
value: number | undefined,
|
|
||||||
truth: number | undefined,
|
|
||||||
) {
|
|
||||||
if (
|
|
||||||
config.ranking === CharacteristicRanking.None ||
|
|
||||||
value === undefined ||
|
|
||||||
truth === undefined ||
|
|
||||||
value === truth ||
|
|
||||||
!Number.isFinite(value) ||
|
|
||||||
!Number.isFinite(truth)
|
|
||||||
) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
const higherIsBetter = config.ranking !== CharacteristicRanking.LowerIsBetter;
|
|
||||||
const better = higherIsBetter === value > truth;
|
|
||||||
const change = truth === 0 ? 1 : Math.abs(value / truth - 1);
|
|
||||||
const intensity = Math.round(Math.min(100, change * 2 * 100 + 25));
|
|
||||||
const color = better ? "jade" : "red";
|
|
||||||
|
|
||||||
return `color-mix(in srgb, var(--${color}-7) ${intensity}%, var(--${color}-3))`;
|
|
||||||
}
|
|
||||||
@@ -1,12 +1,11 @@
|
|||||||
import { times } from "lodash-es";
|
import { times } from "lodash-es";
|
||||||
import { useEffect, useRef, useState, type ReactNode } from "react";
|
import { useCallback, useEffect, useState, type ReactNode } from "react";
|
||||||
import type { MaybeSkeletonComponentProps } from "../types/maybeSkeletonComponentProps";
|
import type { MaybeSkeletonComponentProps } from "../types/maybeSkeletonComponentProps";
|
||||||
|
|
||||||
export interface IncrementalLoaderProps<Props extends { key: string }> {
|
export interface IncrementalLoaderProps<Props extends { key: string }> {
|
||||||
initial: number;
|
initial: number;
|
||||||
intermediate: number;
|
intermediate: number;
|
||||||
rate?: number;
|
rate?: number;
|
||||||
|
|
||||||
skeleton?: boolean;
|
skeleton?: boolean;
|
||||||
data: Props[];
|
data: Props[];
|
||||||
Component: (
|
Component: (
|
||||||
@@ -25,6 +24,9 @@ export function IncrementalLoader<Props extends { key: string }>({
|
|||||||
const [count, setCount] = useState(initial);
|
const [count, setCount] = useState(initial);
|
||||||
const sliced = data.slice(0, count);
|
const sliced = data.slice(0, count);
|
||||||
|
|
||||||
|
// Stable so memoized skeletons skip re-rendering whenever more load in
|
||||||
|
const loadMore = useCallback(() => setCount((state) => state + rate), [rate]);
|
||||||
|
|
||||||
useEffect(() => setCount(initial), [data, initial]);
|
useEffect(() => setCount(initial), [data, initial]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -37,48 +39,9 @@ export function IncrementalLoader<Props extends { key: string }>({
|
|||||||
? initial + intermediate
|
? initial + intermediate
|
||||||
: Math.min(intermediate, data.length - count),
|
: Math.min(intermediate, data.length - count),
|
||||||
(index) => (
|
(index) => (
|
||||||
<Item key={index} rate={rate} setCount={setCount}>
|
<Component key={index} skeleton onIntersection={loadMore} />
|
||||||
<Component skeleton />
|
|
||||||
</Item>
|
|
||||||
),
|
),
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ItemProps {
|
|
||||||
children: ReactNode;
|
|
||||||
rate: number;
|
|
||||||
setCount: (setter: (state: number) => number) => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
function Item({ setCount, rate, children }: ItemProps) {
|
|
||||||
const wrapper = useRef<HTMLDivElement>(null);
|
|
||||||
const observer = useRef<IntersectionObserver | null>(null);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
function dispose() {
|
|
||||||
observer.current?.disconnect();
|
|
||||||
observer.current = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!wrapper.current) return;
|
|
||||||
|
|
||||||
if (observer.current === null) {
|
|
||||||
observer.current = new IntersectionObserver(([entry]) => {
|
|
||||||
if (!entry.isIntersecting) return;
|
|
||||||
setCount((state) => state + rate);
|
|
||||||
});
|
|
||||||
|
|
||||||
observer.current.observe(wrapper.current);
|
|
||||||
}
|
|
||||||
|
|
||||||
return dispose;
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div ref={wrapper} className="incremental-loader">
|
|
||||||
{children}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,68 +0,0 @@
|
|||||||
import {
|
|
||||||
CaretDownIcon,
|
|
||||||
CaretSortIcon,
|
|
||||||
CaretUpIcon,
|
|
||||||
} from "@radix-ui/react-icons";
|
|
||||||
import { Button, Flex, Table } from "@radix-ui/themes";
|
|
||||||
import { useLocale } from "../../hooks/useLocale";
|
|
||||||
import { TankPerformanceSort } from "../../stores/tankPerformanceSort";
|
|
||||||
import { TankPerformanceSortTypeNamesArray } from "../../stores/tankPerformanceSort/constants";
|
|
||||||
import { StickyColumnHeaderCell } from "../StickyColumnHeaderCell";
|
|
||||||
|
|
||||||
export function Header() {
|
|
||||||
const sort = TankPerformanceSort.use();
|
|
||||||
const { strings } = useLocale();
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Table.Header>
|
|
||||||
<Table.Row align="center">
|
|
||||||
<StickyColumnHeaderCell>
|
|
||||||
{strings.website.tools.performance.table.tanks.header}
|
|
||||||
</StickyColumnHeaderCell>
|
|
||||||
|
|
||||||
{TankPerformanceSortTypeNamesArray.map((type) => {
|
|
||||||
const isSelected = sort.type === type;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<StickyColumnHeaderCell
|
|
||||||
px="2"
|
|
||||||
key={type}
|
|
||||||
width="0"
|
|
||||||
justify="center"
|
|
||||||
>
|
|
||||||
<Flex align="center" gap="1">
|
|
||||||
<Button
|
|
||||||
variant="ghost"
|
|
||||||
color={isSelected ? undefined : "gray"}
|
|
||||||
highContrast={!isSelected}
|
|
||||||
onClick={() => {
|
|
||||||
if (isSelected) {
|
|
||||||
TankPerformanceSort.mutate((draft) => {
|
|
||||||
draft.direction *= -1;
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
TankPerformanceSort.mutate((draft) => {
|
|
||||||
draft.type = type;
|
|
||||||
draft.direction = -1;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{strings.website.tools.performance.table.stats[type]}
|
|
||||||
|
|
||||||
{!isSelected && <CaretSortIcon />}
|
|
||||||
{isSelected && (
|
|
||||||
<>
|
|
||||||
{sort.direction === 1 && <CaretUpIcon />}
|
|
||||||
{sort.direction === -1 && <CaretDownIcon />}
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</Button>
|
|
||||||
</Flex>
|
|
||||||
</StickyColumnHeaderCell>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</Table.Row>
|
|
||||||
</Table.Header>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
import { formatCompact } from "@blitzkit/core";
|
|
||||||
import { literals } from "@blitzkit/i18n/src/literals";
|
|
||||||
import { InfoCircledIcon } from "@radix-ui/react-icons";
|
|
||||||
import { Callout, Flex } from "@radix-ui/themes";
|
|
||||||
import { awaitableAverageDefinitions } from "../../core/awaitables/averageDefinitions";
|
|
||||||
import { awaitableDiscoveredIdsDefinitions } from "../../core/awaitables/discoveredIdsDefinitions";
|
|
||||||
import { useLocale } from "../../hooks/useLocale";
|
|
||||||
import type { MaybeSkeletonComponentProps } from "../../types/maybeSkeletonComponentProps";
|
|
||||||
import { InlineSkeleton } from "../InlineSkeleton";
|
|
||||||
|
|
||||||
const [discoveredIdsDefinitions, averageDefinitions] = await Promise.all([
|
|
||||||
awaitableDiscoveredIdsDefinitions,
|
|
||||||
awaitableAverageDefinitions,
|
|
||||||
]);
|
|
||||||
|
|
||||||
export function PerformanceInfo({ skeleton }: MaybeSkeletonComponentProps) {
|
|
||||||
const { strings, locale } = useLocale();
|
|
||||||
const samples = formatCompact(
|
|
||||||
locale,
|
|
||||||
Math.round(discoveredIdsDefinitions.count)
|
|
||||||
);
|
|
||||||
const minutesAgo = Math.floor(
|
|
||||||
(Date.now() - averageDefinitions.time) / (1000 * 60)
|
|
||||||
);
|
|
||||||
const hoursAgo = Math.floor(minutesAgo / 60);
|
|
||||||
const timeAgo = literals(
|
|
||||||
strings.website.tools.performance.estimation[
|
|
||||||
hoursAgo === 0 ? "minutes" : "hours"
|
|
||||||
],
|
|
||||||
{ count: hoursAgo === 0 ? minutesAgo : hoursAgo }
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Flex justify="center">
|
|
||||||
<Callout.Root style={{ width: "fit-content" }}>
|
|
||||||
<Callout.Icon>
|
|
||||||
<InfoCircledIcon />
|
|
||||||
</Callout.Icon>
|
|
||||||
<Callout.Text>
|
|
||||||
{skeleton && <InlineSkeleton width="9rem" />}
|
|
||||||
|
|
||||||
{!skeleton &&
|
|
||||||
literals(strings.website.tools.performance.estimation.body, {
|
|
||||||
count: samples,
|
|
||||||
age: timeAgo,
|
|
||||||
})}
|
|
||||||
</Callout.Text>
|
|
||||||
</Callout.Root>
|
|
||||||
</Flex>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
import { Flex, Select, Text } from '@radix-ui/themes';
|
|
||||||
import { useLocale } from '../../hooks/useLocale';
|
|
||||||
import { Performance, type PlayerCountPeriod } from '../../stores/performance';
|
|
||||||
|
|
||||||
export function PlayerCountControl() {
|
|
||||||
const playerCountPeriod = Performance.use((state) => state.playerCountPeriod);
|
|
||||||
const { strings } = useLocale();
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Flex justify="center" align="center" gap="2">
|
|
||||||
<Text>{strings.website.tools.performance.player_count.label}</Text>
|
|
||||||
<Select.Root
|
|
||||||
value={playerCountPeriod}
|
|
||||||
onValueChange={(period) => {
|
|
||||||
Performance.mutate((draft) => {
|
|
||||||
draft.playerCountPeriod = period as PlayerCountPeriod;
|
|
||||||
});
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Select.Trigger variant="classic" />
|
|
||||||
<Select.Content>
|
|
||||||
<Select.Item value="total">
|
|
||||||
{strings.common.player_count_period.total}
|
|
||||||
</Select.Item>
|
|
||||||
<Select.Item value="d_120">
|
|
||||||
{strings.common.player_count_period.d_120}
|
|
||||||
</Select.Item>
|
|
||||||
<Select.Item value="d_90">
|
|
||||||
{strings.common.player_count_period.d_90}
|
|
||||||
</Select.Item>
|
|
||||||
<Select.Item value="d_60">
|
|
||||||
{strings.common.player_count_period.d_60}
|
|
||||||
</Select.Item>
|
|
||||||
<Select.Item value="d_30">
|
|
||||||
{strings.common.player_count_period.d_30}
|
|
||||||
</Select.Item>
|
|
||||||
<Select.Item value="d_7">
|
|
||||||
{strings.common.player_count_period.d_7}
|
|
||||||
</Select.Item>
|
|
||||||
<Select.Item value="d_1">
|
|
||||||
{strings.common.player_count_period.d_1}
|
|
||||||
</Select.Item>
|
|
||||||
</Select.Content>
|
|
||||||
</Select.Root>
|
|
||||||
</Flex>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
import { Skeleton, Table } from "@radix-ui/themes";
|
|
||||||
import { times } from "lodash-es";
|
|
||||||
import { memo, useRef } from "react";
|
|
||||||
import { useIntersection } from "../../hooks/useIntersection";
|
|
||||||
import { TankPerformanceSortTypeNamesArray } from "../../stores/tankPerformanceSort/constants";
|
|
||||||
|
|
||||||
interface RowLoaderProps {
|
|
||||||
onIntersection?: () => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const RowLoader = memo<RowLoaderProps>(({ onIntersection }) => {
|
|
||||||
const row = useRef<HTMLTableRowElement>(null!);
|
|
||||||
|
|
||||||
useIntersection(() => onIntersection?.(), row, {
|
|
||||||
disabled: onIntersection === undefined,
|
|
||||||
});
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Table.Row ref={row}>
|
|
||||||
<Table.RowHeaderCell align="center">
|
|
||||||
<Skeleton height="100%" width="128px" />
|
|
||||||
</Table.RowHeaderCell>
|
|
||||||
|
|
||||||
{times(TankPerformanceSortTypeNamesArray.length, (index) => (
|
|
||||||
<Table.Cell key={index} align="center">
|
|
||||||
<Skeleton height="1em" width="32px" />
|
|
||||||
</Table.Cell>
|
|
||||||
))}
|
|
||||||
</Table.Row>
|
|
||||||
);
|
|
||||||
});
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
import { Flex } from "@radix-ui/themes";
|
|
||||||
import type { MaybeSkeletonComponentProps } from "../../types/maybeSkeletonComponentProps";
|
|
||||||
import { StickyTableRoot } from "../StickyTableRoot";
|
|
||||||
import { Header } from "./Header";
|
|
||||||
import { Tanks } from "./Tanks";
|
|
||||||
|
|
||||||
export function TankTable({ skeleton }: MaybeSkeletonComponentProps) {
|
|
||||||
return (
|
|
||||||
<Flex justify="center" maxWidth="100%" flexGrow="1" position="relative">
|
|
||||||
<StickyTableRoot
|
|
||||||
size={{ initial: "1", sm: "2" }}
|
|
||||||
variant="surface"
|
|
||||||
style={{
|
|
||||||
position: "absolute",
|
|
||||||
maxWidth: "100%",
|
|
||||||
maxHeight: "100%",
|
|
||||||
height: "100%",
|
|
||||||
borderBottomRightRadius: 0,
|
|
||||||
borderBottomLeftRadius: 0,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Header />
|
|
||||||
<Tanks skeleton={skeleton} />
|
|
||||||
</StickyTableRoot>
|
|
||||||
</Flex>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,138 +0,0 @@
|
|||||||
import { formatCompact } from "@blitzkit/core";
|
|
||||||
import { TankDefinition } from "@blitzkit/protos";
|
|
||||||
import { Table } from "@radix-ui/themes";
|
|
||||||
import { memo } from "react";
|
|
||||||
import { awaitableAverageDefinitions } from "../../core/awaitables/averageDefinitions";
|
|
||||||
import { useAveragesExclusionRatio } from "../../hooks/useAveragesExclusionRatio";
|
|
||||||
import { useLocale } from "../../hooks/useLocale";
|
|
||||||
import { Performance } from "../../stores/performance";
|
|
||||||
import { CompareCell, CompareCellDirection } from "../CompareCell";
|
|
||||||
import { TankRowHeaderCell } from "../TankRowHeaderCell";
|
|
||||||
|
|
||||||
interface TankRowProps {
|
|
||||||
tank: TankDefinition;
|
|
||||||
average: Record<string, number>;
|
|
||||||
}
|
|
||||||
|
|
||||||
const averageDefinitions = await awaitableAverageDefinitions;
|
|
||||||
|
|
||||||
export const TankRow = memo<TankRowProps>(
|
|
||||||
({ tank, average }) => {
|
|
||||||
const averages = averageDefinitions.averages[tank.id];
|
|
||||||
const ratio = useAveragesExclusionRatio();
|
|
||||||
const playerCountPeriod = Performance.use(
|
|
||||||
(state) => state.playerCountPeriod,
|
|
||||||
);
|
|
||||||
const { locale } = useLocale();
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Table.Row>
|
|
||||||
<TankRowHeaderCell tank={tank} />
|
|
||||||
|
|
||||||
<CompareCell
|
|
||||||
value={averages.mu!.wins / averages.mu!.battles}
|
|
||||||
truth={average.winrate}
|
|
||||||
align="center"
|
|
||||||
>
|
|
||||||
{((averages.mu!.wins / averages.mu!.battles) * 100).toFixed(1)}%
|
|
||||||
</CompareCell>
|
|
||||||
<Table.Cell align="center">
|
|
||||||
{formatCompact(
|
|
||||||
locale,
|
|
||||||
Math.round(ratio * averages.samples![playerCountPeriod]),
|
|
||||||
)}
|
|
||||||
</Table.Cell>
|
|
||||||
<CompareCell
|
|
||||||
value={averages.mu!.damage_dealt / averages.mu!.battles}
|
|
||||||
truth={average.damage}
|
|
||||||
align="center"
|
|
||||||
>
|
|
||||||
{Math.round(
|
|
||||||
averages.mu!.damage_dealt / averages.mu!.battles,
|
|
||||||
).toLocaleString(locale)}
|
|
||||||
</CompareCell>
|
|
||||||
<CompareCell
|
|
||||||
value={averages.mu!.survived_battles / averages.mu!.battles}
|
|
||||||
truth={average.survival}
|
|
||||||
align="center"
|
|
||||||
>
|
|
||||||
{Math.round(
|
|
||||||
(averages.mu!.survived_battles / averages.mu!.battles) * 100,
|
|
||||||
)}
|
|
||||||
%
|
|
||||||
</CompareCell>
|
|
||||||
<CompareCell
|
|
||||||
value={averages.mu!.xp / averages.mu!.battles}
|
|
||||||
truth={average.xp}
|
|
||||||
align="center"
|
|
||||||
>
|
|
||||||
{Math.round(averages.mu!.xp / averages.mu!.battles).toLocaleString(
|
|
||||||
locale,
|
|
||||||
)}
|
|
||||||
</CompareCell>
|
|
||||||
<CompareCell
|
|
||||||
value={averages.mu!.frags / averages.mu!.battles}
|
|
||||||
truth={average.kills}
|
|
||||||
align="center"
|
|
||||||
>
|
|
||||||
{(averages.mu!.frags / averages.mu!.battles).toFixed(2)}
|
|
||||||
</CompareCell>
|
|
||||||
<CompareCell
|
|
||||||
value={averages.mu!.spotted / averages.mu!.battles}
|
|
||||||
truth={average.spots}
|
|
||||||
align="center"
|
|
||||||
>
|
|
||||||
{(averages.mu!.spotted / averages.mu!.battles).toFixed(2)}
|
|
||||||
</CompareCell>
|
|
||||||
<CompareCell
|
|
||||||
value={averages.mu!.hits / averages.mu!.shots}
|
|
||||||
truth={average.accuracy}
|
|
||||||
align="center"
|
|
||||||
>
|
|
||||||
{Math.round((averages.mu!.hits / averages.mu!.shots) * 100)}%
|
|
||||||
</CompareCell>
|
|
||||||
<CompareCell
|
|
||||||
value={averages.mu!.shots / averages.mu!.battles}
|
|
||||||
truth={average.shots}
|
|
||||||
align="center"
|
|
||||||
>
|
|
||||||
{(averages.mu!.shots / averages.mu!.battles).toFixed(1)}
|
|
||||||
</CompareCell>
|
|
||||||
<CompareCell
|
|
||||||
value={averages.mu!.hits / averages.mu!.battles}
|
|
||||||
truth={average.hits}
|
|
||||||
align="center"
|
|
||||||
>
|
|
||||||
{(averages.mu!.hits / averages.mu!.battles).toFixed(1)}
|
|
||||||
</CompareCell>
|
|
||||||
<CompareCell
|
|
||||||
value={averages.mu!.damage_dealt / averages.mu!.damage_received}
|
|
||||||
truth={average.damageRatio}
|
|
||||||
align="center"
|
|
||||||
>
|
|
||||||
{(averages.mu!.damage_dealt / averages.mu!.damage_received).toFixed(
|
|
||||||
2,
|
|
||||||
)}
|
|
||||||
</CompareCell>
|
|
||||||
<CompareCell
|
|
||||||
value={averages.mu!.damage_received / averages.mu!.battles}
|
|
||||||
truth={average.damageReceived}
|
|
||||||
direction={CompareCellDirection.LOWER_IS_BETTER}
|
|
||||||
align="center"
|
|
||||||
>
|
|
||||||
{Math.round(
|
|
||||||
averages.mu!.damage_received / averages.mu!.battles,
|
|
||||||
).toLocaleString(locale)}
|
|
||||||
</CompareCell>
|
|
||||||
<CompareCell
|
|
||||||
value={averages.mu!.capture_points / averages.mu!.battles}
|
|
||||||
truth={average.capturePoints}
|
|
||||||
align="center"
|
|
||||||
>
|
|
||||||
{(averages.mu!.capture_points / averages.mu!.battles).toFixed(2)}
|
|
||||||
</CompareCell>
|
|
||||||
</Table.Row>
|
|
||||||
);
|
|
||||||
},
|
|
||||||
(prev, next) => prev.tank.id === next.tank.id,
|
|
||||||
);
|
|
||||||
@@ -1,269 +0,0 @@
|
|||||||
import { formatCompact, type BlitzkitStats } from "@blitzkit/core";
|
|
||||||
import { Table } from "@radix-ui/themes";
|
|
||||||
import { times } from "lodash-es";
|
|
||||||
import {
|
|
||||||
Fragment,
|
|
||||||
Suspense,
|
|
||||||
useCallback,
|
|
||||||
useEffect,
|
|
||||||
useMemo,
|
|
||||||
useState,
|
|
||||||
} from "react";
|
|
||||||
import usePromise from "react-promise-suspense";
|
|
||||||
import { api } from "../../api/dynamic";
|
|
||||||
import { awaitableAverageDefinitions } from "../../core/awaitables/averageDefinitions";
|
|
||||||
import { filterTanks } from "../../core/blitzkit/filterTanks";
|
|
||||||
import { useAveragesExclusionRatio } from "../../hooks/useAveragesExclusionRatio";
|
|
||||||
import { useLocale } from "../../hooks/useLocale";
|
|
||||||
import { Performance } from "../../stores/performance";
|
|
||||||
import { TankFilters } from "../../stores/tankFilters";
|
|
||||||
import { TankPerformanceSort } from "../../stores/tankPerformanceSort";
|
|
||||||
import type { MaybeSkeletonComponentProps } from "../../types/maybeSkeletonComponentProps";
|
|
||||||
import { StickyRowHeaderCell } from "../StickyRowHeaderCell";
|
|
||||||
import { RowLoader } from "./RowLoader";
|
|
||||||
import { TankRow } from "./TankRow";
|
|
||||||
|
|
||||||
const PREVIEW_COUNT = 10;
|
|
||||||
const DEFAULT_LOADED_ROWS = 25;
|
|
||||||
|
|
||||||
const [tankDefinitions, averageDefinitions] = await Promise.all([
|
|
||||||
api.tanks(),
|
|
||||||
awaitableAverageDefinitions,
|
|
||||||
]);
|
|
||||||
|
|
||||||
const tankList = Object.values(tankDefinitions.tanks);
|
|
||||||
|
|
||||||
export function Tanks({ skeleton }: MaybeSkeletonComponentProps) {
|
|
||||||
if (skeleton) {
|
|
||||||
return (
|
|
||||||
<Table.Body>
|
|
||||||
{times(16, (index) => (
|
|
||||||
<RowLoader key={index} />
|
|
||||||
))}
|
|
||||||
</Table.Body>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const sort = TankPerformanceSort.use();
|
|
||||||
const filters = TankFilters.use();
|
|
||||||
const filteredTanks = usePromise(
|
|
||||||
() =>
|
|
||||||
filterTanks(filters, tankList).then((tanks) =>
|
|
||||||
tanks.filter(({ id }) => id in averageDefinitions.averages),
|
|
||||||
),
|
|
||||||
// react-promise-suspense has awful type annotations
|
|
||||||
[filters] as any,
|
|
||||||
);
|
|
||||||
const tanksMapped = useMemo(
|
|
||||||
() =>
|
|
||||||
filteredTanks.map(({ id }) => ({
|
|
||||||
id,
|
|
||||||
...averageDefinitions.averages[id],
|
|
||||||
})),
|
|
||||||
[filters],
|
|
||||||
);
|
|
||||||
const tanksSorted = useMemo(() => {
|
|
||||||
const { playerCountPeriod } = Performance.state;
|
|
||||||
|
|
||||||
switch (sort.type) {
|
|
||||||
case "accuracy":
|
|
||||||
return tanksMapped.sort(
|
|
||||||
(a, b) =>
|
|
||||||
sort.direction *
|
|
||||||
(a.mu!.hits / a.mu!.shots - b.mu!.hits / b.mu!.shots),
|
|
||||||
);
|
|
||||||
case "capture_points":
|
|
||||||
return tanksMapped.sort(
|
|
||||||
(a, b) =>
|
|
||||||
sort.direction *
|
|
||||||
(a.mu!.capture_points / a.mu!.battles -
|
|
||||||
b.mu!.capture_points / b.mu!.battles),
|
|
||||||
);
|
|
||||||
case "damage":
|
|
||||||
return tanksMapped.sort(
|
|
||||||
(a, b) =>
|
|
||||||
sort.direction *
|
|
||||||
(a.mu!.damage_dealt / a.mu!.battles -
|
|
||||||
b.mu!.damage_dealt / b.mu!.battles),
|
|
||||||
);
|
|
||||||
case "damage_ratio":
|
|
||||||
return tanksMapped.sort(
|
|
||||||
(a, b) =>
|
|
||||||
sort.direction *
|
|
||||||
(a.mu!.damage_dealt / a.mu!.damage_received -
|
|
||||||
b.mu!.damage_dealt / b.mu!.damage_received),
|
|
||||||
);
|
|
||||||
case "damage_taken":
|
|
||||||
return tanksMapped.sort(
|
|
||||||
(a, b) =>
|
|
||||||
sort.direction *
|
|
||||||
(a.mu!.damage_received / a.mu!.battles -
|
|
||||||
b.mu!.damage_received / b.mu!.battles),
|
|
||||||
);
|
|
||||||
case "hits":
|
|
||||||
return tanksMapped.sort(
|
|
||||||
(a, b) =>
|
|
||||||
sort.direction *
|
|
||||||
(a.mu!.hits / a.mu!.battles - b.mu!.hits / b.mu!.battles),
|
|
||||||
);
|
|
||||||
case "kills":
|
|
||||||
return tanksMapped.sort(
|
|
||||||
(a, b) =>
|
|
||||||
sort.direction *
|
|
||||||
(a.mu!.frags / a.mu!.battles - b.mu!.frags / b.mu!.battles),
|
|
||||||
);
|
|
||||||
case "shots":
|
|
||||||
return tanksMapped.sort(
|
|
||||||
(a, b) =>
|
|
||||||
sort.direction *
|
|
||||||
(a.mu!.shots / a.mu!.battles - b.mu!.shots / b.mu!.battles),
|
|
||||||
);
|
|
||||||
case "players":
|
|
||||||
return tanksMapped.sort(
|
|
||||||
(a, b) =>
|
|
||||||
sort.direction *
|
|
||||||
(a.samples![playerCountPeriod] - b.samples![playerCountPeriod]),
|
|
||||||
);
|
|
||||||
case "spots":
|
|
||||||
return tanksMapped.sort(
|
|
||||||
(a, b) =>
|
|
||||||
sort.direction *
|
|
||||||
(a.mu!.spotted / a.mu!.battles - b.mu!.spotted / b.mu!.battles),
|
|
||||||
);
|
|
||||||
case "survival":
|
|
||||||
return tanksMapped.sort(
|
|
||||||
(a, b) =>
|
|
||||||
sort.direction *
|
|
||||||
(a.mu!.survived_battles / a.mu!.battles -
|
|
||||||
b.mu!.survived_battles / b.mu!.battles),
|
|
||||||
);
|
|
||||||
case "winrate":
|
|
||||||
return tanksMapped.sort(
|
|
||||||
(a, b) =>
|
|
||||||
sort.direction *
|
|
||||||
(a.mu!.wins / a.mu!.battles - b.mu!.wins / b.mu!.battles),
|
|
||||||
);
|
|
||||||
case "xp":
|
|
||||||
return tanksMapped.sort(
|
|
||||||
(a, b) =>
|
|
||||||
sort.direction *
|
|
||||||
(a.mu!.xp / a.mu!.battles - b.mu!.xp / b.mu!.battles),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}, [filters, sort]);
|
|
||||||
const [loadedRows, setLoadedRows] = useState(DEFAULT_LOADED_ROWS);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
setLoadedRows(DEFAULT_LOADED_ROWS);
|
|
||||||
}, [filters, sort]);
|
|
||||||
|
|
||||||
const playerCountPeriod = Performance.use((state) => state.playerCountPeriod);
|
|
||||||
const { strings, locale } = useLocale();
|
|
||||||
const ratio = useAveragesExclusionRatio();
|
|
||||||
const sum = useCallback(
|
|
||||||
(slice: (tank: BlitzkitStats) => number) => {
|
|
||||||
return tanksSorted.reduce(
|
|
||||||
(acc, tank) => acc + tank.samples![playerCountPeriod] * slice(tank.mu!),
|
|
||||||
0,
|
|
||||||
);
|
|
||||||
},
|
|
||||||
[tanksSorted],
|
|
||||||
);
|
|
||||||
|
|
||||||
const battles = sum(({ battles }) => battles);
|
|
||||||
const winrate = sum(({ wins }) => wins) / battles;
|
|
||||||
const damage = sum(({ damage_dealt }) => damage_dealt) / battles;
|
|
||||||
const survival = sum(({ survived_battles }) => survived_battles) / battles;
|
|
||||||
const xp = sum(({ xp }) => xp) / battles;
|
|
||||||
const kills = sum(({ frags }) => frags) / battles;
|
|
||||||
const spots = sum(({ spotted }) => spotted) / battles;
|
|
||||||
const hits = sum(({ hits }) => hits) / battles;
|
|
||||||
const shots = sum(({ shots }) => shots) / battles;
|
|
||||||
const accuracy = hits / shots;
|
|
||||||
const damageReceived =
|
|
||||||
sum(({ damage_received }) => damage_received) / battles;
|
|
||||||
const damageRatio = damage / damageReceived;
|
|
||||||
const capturePoints = sum(({ capture_points }) => capture_points) / battles;
|
|
||||||
|
|
||||||
const average = {
|
|
||||||
battles,
|
|
||||||
winrate,
|
|
||||||
damage,
|
|
||||||
survival,
|
|
||||||
xp,
|
|
||||||
kills,
|
|
||||||
spots,
|
|
||||||
hits,
|
|
||||||
shots,
|
|
||||||
accuracy,
|
|
||||||
damageReceived,
|
|
||||||
damageRatio,
|
|
||||||
capturePoints,
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Table.Body>
|
|
||||||
<Table.Row>
|
|
||||||
<StickyRowHeaderCell style={{ overflow: "hidden", display: "flex" }}>
|
|
||||||
{strings.website.tools.performance.table.tanks.total}
|
|
||||||
</StickyRowHeaderCell>
|
|
||||||
<Table.Cell align="center">{(winrate * 100).toFixed(1)}%</Table.Cell>
|
|
||||||
<Table.Cell align="center">
|
|
||||||
{formatCompact(
|
|
||||||
locale,
|
|
||||||
ratio * averageDefinitions.samples![playerCountPeriod],
|
|
||||||
)}
|
|
||||||
</Table.Cell>
|
|
||||||
<Table.Cell align="center">
|
|
||||||
{Math.round(damage).toLocaleString(locale)}
|
|
||||||
</Table.Cell>
|
|
||||||
<Table.Cell align="center">
|
|
||||||
{Math.round(survival * 100).toFixed(1)}%
|
|
||||||
</Table.Cell>
|
|
||||||
<Table.Cell align="center">
|
|
||||||
{Math.round(xp).toLocaleString(locale)}
|
|
||||||
</Table.Cell>
|
|
||||||
<Table.Cell align="center">{kills.toFixed(2)}</Table.Cell>
|
|
||||||
<Table.Cell align="center">{spots.toFixed(2)}</Table.Cell>
|
|
||||||
<Table.Cell align="center">{(accuracy * 100).toFixed(0)}%</Table.Cell>
|
|
||||||
<Table.Cell align="center">{shots.toFixed(1)}</Table.Cell>
|
|
||||||
<Table.Cell align="center">{hits.toFixed(1)}</Table.Cell>
|
|
||||||
<Table.Cell align="center">{damageRatio.toFixed(2)}</Table.Cell>
|
|
||||||
<Table.Cell align="center">
|
|
||||||
{Math.round(damageReceived).toLocaleString(locale)}
|
|
||||||
</Table.Cell>
|
|
||||||
<Table.Cell align="center">{capturePoints.toFixed(2)}</Table.Cell>
|
|
||||||
</Table.Row>
|
|
||||||
|
|
||||||
{tanksSorted.slice(0, loadedRows).map((averages) => {
|
|
||||||
const tank = tankDefinitions.tanks[averages.id];
|
|
||||||
|
|
||||||
if (tank === undefined) return null;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Fragment key={tank.id}>
|
|
||||||
<Suspense fallback={<RowLoader />}>
|
|
||||||
<TankRow average={average} tank={tank} />
|
|
||||||
</Suspense>
|
|
||||||
</Fragment>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
|
|
||||||
{times(
|
|
||||||
Math.min(PREVIEW_COUNT, tanksSorted.length - loadedRows),
|
|
||||||
(index) => {
|
|
||||||
return (
|
|
||||||
<RowLoader
|
|
||||||
key={index}
|
|
||||||
onIntersection={() => {
|
|
||||||
setLoadedRows((state) =>
|
|
||||||
Math.min(state + 2, tanksSorted.length),
|
|
||||||
);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
},
|
|
||||||
)}
|
|
||||||
</Table.Body>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
.controls {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
gap: var(--space-4);
|
||||||
|
|
||||||
|
.period {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: var(--space-3);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
import { CaretDownIcon, DotFilledIcon } from "@radix-ui/react-icons";
|
||||||
|
import { useStrings } from "../../hooks/useStrings";
|
||||||
|
import { Performance, type PlayerCountPeriod } from "../../stores/performance";
|
||||||
|
import { Select } from "../Select";
|
||||||
|
import { TankSearchFilters } from "../TankSearchFilters";
|
||||||
|
import { Text } from "../Text";
|
||||||
|
import styles from "./index.module.css";
|
||||||
|
|
||||||
|
const periods: PlayerCountPeriod[] = [
|
||||||
|
"total",
|
||||||
|
"d_120",
|
||||||
|
"d_90",
|
||||||
|
"d_60",
|
||||||
|
"d_30",
|
||||||
|
"d_7",
|
||||||
|
"d_1",
|
||||||
|
];
|
||||||
|
|
||||||
|
export function PerformanceControls() {
|
||||||
|
const strings = useStrings();
|
||||||
|
const playerCountPeriod = Performance.use(
|
||||||
|
(state) => state.player_count_period,
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={styles.controls}>
|
||||||
|
<TankSearchFilters />
|
||||||
|
|
||||||
|
<div className={styles.period}>
|
||||||
|
<Text>{strings.performance.player_count}</Text>
|
||||||
|
|
||||||
|
<Select.Root
|
||||||
|
value={playerCountPeriod}
|
||||||
|
onValueChange={(value) => {
|
||||||
|
Performance.mutate((draft) => {
|
||||||
|
draft.player_count_period = value as PlayerCountPeriod;
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Select.Trigger>
|
||||||
|
<Select.Value />
|
||||||
|
|
||||||
|
<Select.Icon>
|
||||||
|
<CaretDownIcon />
|
||||||
|
</Select.Icon>
|
||||||
|
</Select.Trigger>
|
||||||
|
|
||||||
|
<Select.Portal>
|
||||||
|
<Select.Content>
|
||||||
|
<Select.Viewport>
|
||||||
|
{periods.map((period) => (
|
||||||
|
<Select.Item key={period} value={period}>
|
||||||
|
<Select.ItemIndicator>
|
||||||
|
<DotFilledIcon />
|
||||||
|
</Select.ItemIndicator>
|
||||||
|
|
||||||
|
<Select.ItemText>
|
||||||
|
{strings.common.player_count_period[period]}
|
||||||
|
</Select.ItemText>
|
||||||
|
</Select.Item>
|
||||||
|
))}
|
||||||
|
</Select.Viewport>
|
||||||
|
</Select.Content>
|
||||||
|
</Select.Portal>
|
||||||
|
</Select.Root>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
/* Spans the page even when the columns would fit in less */
|
||||||
|
.root {
|
||||||
|
--tank-width: 15rem;
|
||||||
|
|
||||||
|
width: 100%;
|
||||||
|
|
||||||
|
/* Fixed layout keeps stat columns equal. Fixed tables ignore cell minimums, so the table holds 8rem per stat column and scrolls past that */
|
||||||
|
table {
|
||||||
|
table-layout: fixed;
|
||||||
|
width: 100%;
|
||||||
|
min-width: calc(var(--tank-width) + var(--columns) * 8rem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.corner {
|
||||||
|
box-sizing: border-box;
|
||||||
|
width: var(--tank-width);
|
||||||
|
}
|
||||||
|
|
||||||
|
.value {
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.value-skeleton {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Table cells ignore max-width, so the link inside caps the column instead */
|
||||||
|
.tank {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: var(--space-2);
|
||||||
|
|
||||||
|
white-space: nowrap;
|
||||||
|
|
||||||
|
.icon {
|
||||||
|
flex-shrink: 0;
|
||||||
|
/* Bleeds into the cell's padding so rows stay as tall as their text */
|
||||||
|
height: calc(1em + 2 * var(--space-3));
|
||||||
|
margin: calc(-1 * var(--space-3)) 0;
|
||||||
|
aspect-ratio: 4 / 3;
|
||||||
|
object-fit: cover;
|
||||||
|
}
|
||||||
|
|
||||||
|
.glyph {
|
||||||
|
flex-shrink: 0;
|
||||||
|
width: 1em;
|
||||||
|
height: 1em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.name {
|
||||||
|
min-width: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.tank-skeleton {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
@@ -0,0 +1,391 @@
|
|||||||
|
import { tankIcon } from "@blitzkit/core";
|
||||||
|
import {
|
||||||
|
TankType,
|
||||||
|
type AverageDefinitionsAllStats,
|
||||||
|
type TankDefinition,
|
||||||
|
} from "@blitzkit/protos";
|
||||||
|
import {
|
||||||
|
memo,
|
||||||
|
useEffect,
|
||||||
|
useMemo,
|
||||||
|
useRef,
|
||||||
|
useState,
|
||||||
|
type CSSProperties,
|
||||||
|
} from "react";
|
||||||
|
import { api } from "../../api/dynamic";
|
||||||
|
import {
|
||||||
|
performanceStatNames,
|
||||||
|
performanceStats,
|
||||||
|
type PerformanceEntry,
|
||||||
|
type PerformanceStatName,
|
||||||
|
} from "../../config/performanceStats";
|
||||||
|
import { awaitableAverageDefinitions } from "../../core/awaitables/averageDefinitions";
|
||||||
|
import { awaitableDiscoveredIdsDefinitions } from "../../core/awaitables/discoveredIdsDefinitions";
|
||||||
|
import { filterTanks } from "../../core/blitzkit/filterTanks";
|
||||||
|
import { useLocale } from "../../hooks/useLocale";
|
||||||
|
import { useStrings } from "../../hooks/useStrings";
|
||||||
|
import { useUnwrapper } from "../../hooks/useUnwrapper";
|
||||||
|
import { App } from "../../stores/app";
|
||||||
|
import { Performance } from "../../stores/performance";
|
||||||
|
import { TankFilters } from "../../stores/tankFilters";
|
||||||
|
import { SortDirection } from "../../stores/tankopediaPersistent";
|
||||||
|
import type { MaybeSkeletonComponentProps } from "../../types/maybeSkeletonComponentProps";
|
||||||
|
import { ClassIcon } from "../ClassIcon";
|
||||||
|
import { EmptyState } from "../EmptyState";
|
||||||
|
import { ExperimentIcon } from "../ExperimentIcon";
|
||||||
|
import { IncrementalLoader } from "../IncrementalLoader";
|
||||||
|
import { InlineSkeleton } from "../InlineSkeleton";
|
||||||
|
import { LinkI18n } from "../LinkI18n";
|
||||||
|
import { Skeleton } from "../Skeleton";
|
||||||
|
import { Table } from "../Table";
|
||||||
|
import { Text } from "../Text";
|
||||||
|
import styles from "./index.module.css";
|
||||||
|
|
||||||
|
const [tankDefinitions, averageDefinitions, discoveredIdsDefinitions] =
|
||||||
|
await Promise.all([
|
||||||
|
api.tanks(),
|
||||||
|
awaitableAverageDefinitions,
|
||||||
|
awaitableDiscoveredIdsDefinitions,
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Only tanks with statistics can be listed
|
||||||
|
const tanksWithAverages = Object.values(tankDefinitions.tanks).filter(
|
||||||
|
({ id }) => id in averageDefinitions.averages,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Samples only cover part of the discovered players, so player counts are scaled up to all of them
|
||||||
|
const exclusionRatio =
|
||||||
|
discoveredIdsDefinitions.count / averageDefinitions.samples!.total;
|
||||||
|
|
||||||
|
interface PerformanceRow {
|
||||||
|
tank: TankDefinition;
|
||||||
|
entry: PerformanceEntry;
|
||||||
|
values: Record<PerformanceStatName, number>;
|
||||||
|
}
|
||||||
|
|
||||||
|
function computeValues(entry: PerformanceEntry) {
|
||||||
|
const values = {} as Record<PerformanceStatName, number>;
|
||||||
|
|
||||||
|
for (const name of performanceStatNames) {
|
||||||
|
values[name] = performanceStats[name].value(entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
return values;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function PerformanceTable() {
|
||||||
|
const strings = useStrings();
|
||||||
|
const filters = TankFilters.use();
|
||||||
|
const wargaming = App.use((state) => state.logins.wargaming);
|
||||||
|
const [filtered, setFiltered] = useState<TankDefinition[] | null>(null);
|
||||||
|
|
||||||
|
// Filtering can wait on the player's garage, so the last results stay up until it settles
|
||||||
|
useEffect(() => {
|
||||||
|
let cancelled = false;
|
||||||
|
|
||||||
|
filterTanks(filters, tanksWithAverages, wargaming?.id).then((tanks) => {
|
||||||
|
if (!cancelled) setFiltered(tanks);
|
||||||
|
});
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
cancelled = true;
|
||||||
|
};
|
||||||
|
}, [filters, wargaming?.id]);
|
||||||
|
|
||||||
|
if (filtered !== null && filtered.length === 0) {
|
||||||
|
return (
|
||||||
|
<EmptyState
|
||||||
|
title={strings.performance.no_tanks.title}
|
||||||
|
body={strings.performance.no_tanks.body}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Table.Root
|
||||||
|
scrollable
|
||||||
|
className={styles.root}
|
||||||
|
style={{ "--columns": performanceStatNames.length } as CSSProperties}
|
||||||
|
>
|
||||||
|
<Head />
|
||||||
|
<Body filtered={filtered} />
|
||||||
|
</Table.Root>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function Head() {
|
||||||
|
return (
|
||||||
|
<Table.Head>
|
||||||
|
<Table.Row>
|
||||||
|
<Table.IconCorner className={styles.corner} />
|
||||||
|
|
||||||
|
{performanceStatNames.map((name) => (
|
||||||
|
<ColumnHeader key={name} name={name} />
|
||||||
|
))}
|
||||||
|
</Table.Row>
|
||||||
|
</Table.Head>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
interface BodyProps {
|
||||||
|
filtered: TankDefinition[] | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Owns sorting and period, so changing them never re-renders the head
|
||||||
|
function Body({ filtered }: BodyProps) {
|
||||||
|
const sorting = Performance.use((state) => state.sorting);
|
||||||
|
const period = Performance.use((state) => state.player_count_period);
|
||||||
|
|
||||||
|
const rows = useMemo(() => {
|
||||||
|
if (filtered === null) return null;
|
||||||
|
|
||||||
|
return filtered.map((tank) => {
|
||||||
|
const average = averageDefinitions.averages[tank.id];
|
||||||
|
const entry = {
|
||||||
|
stats: average.mu!,
|
||||||
|
players: exclusionRatio * average.samples![period],
|
||||||
|
} satisfies PerformanceEntry;
|
||||||
|
|
||||||
|
return {
|
||||||
|
tank,
|
||||||
|
entry,
|
||||||
|
values: computeValues(entry),
|
||||||
|
} satisfies PerformanceRow;
|
||||||
|
});
|
||||||
|
}, [filtered, period]);
|
||||||
|
|
||||||
|
// Every tank's stats weighted by how many players it had in the period
|
||||||
|
const total = useMemo(() => {
|
||||||
|
if (rows === null) return null;
|
||||||
|
|
||||||
|
const stats = {} as AverageDefinitionsAllStats;
|
||||||
|
let samples = 0;
|
||||||
|
|
||||||
|
for (const { tank } of rows) {
|
||||||
|
const average = averageDefinitions.averages[tank.id];
|
||||||
|
const weight = average.samples![period];
|
||||||
|
|
||||||
|
samples += weight;
|
||||||
|
|
||||||
|
for (const key in average.mu!) {
|
||||||
|
const stat = key as keyof AverageDefinitionsAllStats;
|
||||||
|
|
||||||
|
stats[stat] = (stats[stat] ?? 0) + weight * average.mu![stat];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return computeValues({ stats, players: exclusionRatio * samples });
|
||||||
|
}, [rows, period]);
|
||||||
|
|
||||||
|
const sorted = useMemo(() => {
|
||||||
|
if (rows === null) return null;
|
||||||
|
|
||||||
|
const direction = sorting.direction === SortDirection.Ascending ? 1 : -1;
|
||||||
|
|
||||||
|
return [...rows].sort(
|
||||||
|
(a, b) => direction * (a.values[sorting.by] - b.values[sorting.by]),
|
||||||
|
);
|
||||||
|
}, [rows, sorting]);
|
||||||
|
|
||||||
|
const data = useMemo(
|
||||||
|
() =>
|
||||||
|
(sorted ?? []).map((row) => ({
|
||||||
|
key: `${row.tank.id}`,
|
||||||
|
row,
|
||||||
|
total: total!,
|
||||||
|
})),
|
||||||
|
[sorted, total],
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Table.Body>
|
||||||
|
<TotalRow total={total} />
|
||||||
|
|
||||||
|
<IncrementalLoader
|
||||||
|
skeleton={sorted === null}
|
||||||
|
initial={32}
|
||||||
|
intermediate={8}
|
||||||
|
data={data}
|
||||||
|
Component={Row}
|
||||||
|
/>
|
||||||
|
</Table.Body>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
interface TotalRowProps {
|
||||||
|
total: Record<PerformanceStatName, number> | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function TotalRow({ total }: TotalRowProps) {
|
||||||
|
const strings = useStrings();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Table.Row>
|
||||||
|
<Table.RowHeader>{strings.performance.total}</Table.RowHeader>
|
||||||
|
|
||||||
|
{performanceStatNames.map((name) => (
|
||||||
|
<Table.Cell key={name}>
|
||||||
|
{total === null ? (
|
||||||
|
<Skeleton className={styles["value-skeleton"]} />
|
||||||
|
) : (
|
||||||
|
<Value name={name} value={total[name]} />
|
||||||
|
)}
|
||||||
|
</Table.Cell>
|
||||||
|
))}
|
||||||
|
</Table.Row>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ColumnHeaderProps {
|
||||||
|
name: PerformanceStatName;
|
||||||
|
}
|
||||||
|
|
||||||
|
function ColumnHeader({ name }: ColumnHeaderProps) {
|
||||||
|
const strings = useStrings();
|
||||||
|
const sorting = Performance.use((state) => state.sorting);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Table.ColumnHeaderSortable
|
||||||
|
direction={sorting.by === name ? sorting.direction : undefined}
|
||||||
|
onSort={() => {
|
||||||
|
Performance.mutate((draft) => {
|
||||||
|
const ascending =
|
||||||
|
draft.sorting.by === name &&
|
||||||
|
draft.sorting.direction === SortDirection.Descending;
|
||||||
|
|
||||||
|
draft.sorting = {
|
||||||
|
by: name,
|
||||||
|
direction: ascending
|
||||||
|
? SortDirection.Ascending
|
||||||
|
: SortDirection.Descending,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{strings.common.stats[name]}
|
||||||
|
</Table.ColumnHeaderSortable>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ValueProps {
|
||||||
|
name: PerformanceStatName;
|
||||||
|
value: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
function Value({ name, value }: ValueProps) {
|
||||||
|
const locale = useLocale();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Text className={styles.value}>
|
||||||
|
{Number.isFinite(value)
|
||||||
|
? performanceStats[name].format(value, locale)
|
||||||
|
: "-"}
|
||||||
|
</Text>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
interface RowProps {
|
||||||
|
row: PerformanceRow;
|
||||||
|
total: Record<PerformanceStatName, number>;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Memoized so loading more rows leaves the loaded ones be
|
||||||
|
const Row = memo((props: MaybeSkeletonComponentProps<RowProps>) => {
|
||||||
|
if (props.skeleton) {
|
||||||
|
return <SkeletonRow onIntersection={props.onIntersection} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { row, total } = props;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Table.Row>
|
||||||
|
<Table.RowHeader>
|
||||||
|
<TankLink tank={row.tank} />
|
||||||
|
</Table.RowHeader>
|
||||||
|
|
||||||
|
{performanceStatNames.map((name) => (
|
||||||
|
<Table.CellRanked
|
||||||
|
key={name}
|
||||||
|
ranking={performanceStats[name].ranking}
|
||||||
|
value={row.values[name]}
|
||||||
|
truth={total[name]}
|
||||||
|
>
|
||||||
|
<Value name={name} value={row.values[name]} />
|
||||||
|
</Table.CellRanked>
|
||||||
|
))}
|
||||||
|
</Table.Row>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
interface TankLinkProps {
|
||||||
|
tank: TankDefinition;
|
||||||
|
}
|
||||||
|
|
||||||
|
function TankLink({ tank }: TankLinkProps) {
|
||||||
|
const locale = useLocale();
|
||||||
|
const unwrap = useUnwrapper();
|
||||||
|
const name = unwrap(tank.name!);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<LinkI18n
|
||||||
|
locale={locale}
|
||||||
|
href={`/tanks/${tank.slug}`}
|
||||||
|
underline="hover"
|
||||||
|
className={styles.tank}
|
||||||
|
color={
|
||||||
|
tank.type === TankType.TANK_TYPE_COLLECTOR
|
||||||
|
? "blue"
|
||||||
|
: tank.type === TankType.TANK_TYPE_PREMIUM
|
||||||
|
? "amber"
|
||||||
|
: "gray"
|
||||||
|
}
|
||||||
|
highContrast={tank.type === TankType.TANK_TYPE_RESEARCHABLE}
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
alt={name}
|
||||||
|
src={tankIcon(tank.id)}
|
||||||
|
draggable={false}
|
||||||
|
className={styles.icon}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<ClassIcon class={tank.class} className={styles.glyph} />
|
||||||
|
{tank.testing && <ExperimentIcon className={styles.glyph} />}
|
||||||
|
|
||||||
|
<span className={styles.name}>{name}</span>
|
||||||
|
</LinkI18n>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
interface SkeletonRowProps {
|
||||||
|
onIntersection?: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
function SkeletonRow({ onIntersection }: SkeletonRowProps) {
|
||||||
|
const row = useRef<HTMLTableRowElement>(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!onIntersection) return;
|
||||||
|
|
||||||
|
const observer = new IntersectionObserver(([entry]) => {
|
||||||
|
if (entry.isIntersecting) onIntersection();
|
||||||
|
});
|
||||||
|
|
||||||
|
observer.observe(row.current!);
|
||||||
|
|
||||||
|
return () => observer.disconnect();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Table.Row ref={row}>
|
||||||
|
<Table.RowHeader>
|
||||||
|
<InlineSkeleton className={styles["tank-skeleton"]} />
|
||||||
|
</Table.RowHeader>
|
||||||
|
|
||||||
|
{performanceStatNames.map((name) => (
|
||||||
|
<Table.Cell key={name}>
|
||||||
|
<InlineSkeleton className={styles["value-skeleton"]} />
|
||||||
|
</Table.Cell>
|
||||||
|
))}
|
||||||
|
</Table.Row>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
/* Row dividers sit inside the cells, so they take no space. Borders on a row itself don't paint with separate borders, so rows apply them to their cells here */
|
/* Row dividers sit inside the cells, so they take no space. Borders on a row itself don't paint with separate borders, so rows apply them to their cells here */
|
||||||
tbody tr > * {
|
tbody tr > * {
|
||||||
box-shadow: inset 0 var(--space-0) var(--gray-a4);
|
box-shadow: inset 0 var(--space-0) var(--gray-5);
|
||||||
}
|
}
|
||||||
|
|
||||||
.column-header {
|
.column-header {
|
||||||
@@ -32,11 +32,43 @@
|
|||||||
padding-bottom: var(--space-4);
|
padding-bottom: var(--space-4);
|
||||||
|
|
||||||
background-color: var(--gray-3);
|
background-color: var(--gray-3);
|
||||||
|
|
||||||
|
&[data-sortable] {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
&[data-sorted="true"] {
|
||||||
|
color: var(--accent-11);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Inline so the cell's alignment still centers it */
|
||||||
|
.sortable {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: var(--space-2);
|
||||||
}
|
}
|
||||||
|
|
||||||
.corner {
|
.corner {
|
||||||
left: 0;
|
left: 0;
|
||||||
z-index: 2;
|
z-index: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Fills the cell inside its padding, so the row's other headers decide the size */
|
||||||
|
.logo {
|
||||||
|
--padding: var(--space-3);
|
||||||
|
--max-height: 4rem;
|
||||||
|
|
||||||
|
position: absolute;
|
||||||
|
|
||||||
|
top: 50%;
|
||||||
|
left: var(--padding);
|
||||||
|
transform: translateY(-50%);
|
||||||
|
|
||||||
|
width: calc(100% - var(--padding) * 2);
|
||||||
|
height: min(var(--max-height), calc(100% - var(--padding) * 2));
|
||||||
|
|
||||||
|
color: var(--gray-6);
|
||||||
}
|
}
|
||||||
|
|
||||||
.row-header {
|
.row-header {
|
||||||
@@ -81,5 +113,21 @@
|
|||||||
&[data-align="end"] {
|
&[data-align="end"] {
|
||||||
text-align: right;
|
text-align: right;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&[data-delta="better"] {
|
||||||
|
background-color: color-mix(
|
||||||
|
in srgb,
|
||||||
|
var(--jade-5) var(--intensity),
|
||||||
|
var(--jade-1)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
&[data-delta="worse"] {
|
||||||
|
background-color: color-mix(
|
||||||
|
in srgb,
|
||||||
|
var(--red-5) var(--intensity),
|
||||||
|
var(--red-1)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,17 @@
|
|||||||
import { useEffect, useRef, type ComponentProps } from "react";
|
import {
|
||||||
|
CaretDownIcon,
|
||||||
|
CaretSortIcon,
|
||||||
|
CaretUpIcon,
|
||||||
|
} from "@radix-ui/react-icons";
|
||||||
|
import {
|
||||||
|
useEffect,
|
||||||
|
useRef,
|
||||||
|
type ComponentProps,
|
||||||
|
type CSSProperties,
|
||||||
|
} from "react";
|
||||||
|
import { Logo } from "../../icons/Logo";
|
||||||
|
import { SortDirection } from "../../stores/tankopediaPersistent";
|
||||||
|
import { CharacteristicRanking } from "../../types/characteristics";
|
||||||
import { classNames } from "../../ui/classNames";
|
import { classNames } from "../../ui/classNames";
|
||||||
import { Scroller, ScrollerOrientation } from "../Scroller";
|
import { Scroller, ScrollerOrientation } from "../Scroller";
|
||||||
import styles from "./index.module.css";
|
import styles from "./index.module.css";
|
||||||
@@ -21,7 +34,7 @@ function Root({ children, className, scrollable, ...props }: RootProps) {
|
|||||||
const observer = new ResizeObserver(() => {
|
const observer = new ResizeObserver(() => {
|
||||||
table.current!.style.setProperty(
|
table.current!.style.setProperty(
|
||||||
"--head-height",
|
"--head-height",
|
||||||
`${head.offsetHeight}px`
|
`${head.offsetHeight}px`,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -78,12 +91,62 @@ function Corner({ className, ...props }: ComponentProps<"th">) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function IconCorner({ children, ...props }: ComponentProps<"th">) {
|
||||||
|
return (
|
||||||
|
<Corner {...props}>
|
||||||
|
<Logo className={styles.logo} />
|
||||||
|
{children}
|
||||||
|
</Corner>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function ColumnHeader({ className, ...props }: ComponentProps<"th">) {
|
function ColumnHeader({ className, ...props }: ComponentProps<"th">) {
|
||||||
return (
|
return (
|
||||||
<th className={classNames(styles["column-header"], className)} {...props} />
|
<th className={classNames(styles["column-header"], className)} {...props} />
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface ColumnHeaderSortableProps extends ComponentProps<"th"> {
|
||||||
|
// Unsorted when undefined
|
||||||
|
direction: SortDirection | undefined;
|
||||||
|
onSort: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The whole header toggles sorting, inheriting the header's font rather than a button's
|
||||||
|
function ColumnHeaderSortable({
|
||||||
|
className,
|
||||||
|
children,
|
||||||
|
direction,
|
||||||
|
onSort,
|
||||||
|
...props
|
||||||
|
}: ColumnHeaderSortableProps) {
|
||||||
|
return (
|
||||||
|
<th
|
||||||
|
className={classNames(styles["column-header"], className)}
|
||||||
|
onClick={onSort}
|
||||||
|
data-sortable
|
||||||
|
data-sorted={direction !== undefined}
|
||||||
|
aria-sort={
|
||||||
|
direction === undefined
|
||||||
|
? undefined
|
||||||
|
: direction === SortDirection.Ascending
|
||||||
|
? "ascending"
|
||||||
|
: "descending"
|
||||||
|
}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
{/* The cell stays a table cell, so its content lays out in here instead */}
|
||||||
|
<span className={styles.sortable}>
|
||||||
|
{children}
|
||||||
|
|
||||||
|
{direction === undefined && <CaretSortIcon />}
|
||||||
|
{direction === SortDirection.Ascending && <CaretUpIcon />}
|
||||||
|
{direction === SortDirection.Descending && <CaretDownIcon />}
|
||||||
|
</span>
|
||||||
|
</th>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function RowHeader({ className, ...props }: ComponentProps<"th">) {
|
function RowHeader({ className, ...props }: ComponentProps<"th">) {
|
||||||
return (
|
return (
|
||||||
<th className={classNames(styles["row-header"], className)} {...props} />
|
<th className={classNames(styles["row-header"], className)} {...props} />
|
||||||
@@ -124,15 +187,56 @@ function Cell({ className, align, ...props }: CellProps) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface CellRankedProps extends CellProps {
|
||||||
|
ranking: CharacteristicRanking | undefined;
|
||||||
|
value: number | undefined;
|
||||||
|
truth: number | undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tints by how far the value strays from the truth, jade when better and red when worse
|
||||||
|
function CellRanked({
|
||||||
|
ranking,
|
||||||
|
value,
|
||||||
|
truth,
|
||||||
|
style,
|
||||||
|
...props
|
||||||
|
}: CellRankedProps) {
|
||||||
|
const isRanked =
|
||||||
|
ranking !== CharacteristicRanking.None &&
|
||||||
|
value !== undefined &&
|
||||||
|
truth !== undefined &&
|
||||||
|
value !== truth &&
|
||||||
|
Number.isFinite(value) &&
|
||||||
|
Number.isFinite(truth);
|
||||||
|
|
||||||
|
if (!isRanked) return <Cell style={style} {...props} />;
|
||||||
|
|
||||||
|
const higherIsBetter = ranking !== CharacteristicRanking.LowerIsBetter;
|
||||||
|
const better = higherIsBetter === value > truth;
|
||||||
|
const change = truth === 0 ? 1 : Math.abs(value / truth - 1);
|
||||||
|
const intensity = Math.round(Math.min(100, change * 2 * 100 + 25));
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Cell
|
||||||
|
data-delta={better ? "better" : "worse"}
|
||||||
|
style={{ "--intensity": `${intensity}%`, ...style } as CSSProperties}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export const Table = {
|
export const Table = {
|
||||||
Root,
|
Root,
|
||||||
Head,
|
Head,
|
||||||
Body,
|
Body,
|
||||||
Row,
|
Row,
|
||||||
Corner,
|
Corner,
|
||||||
|
IconCorner,
|
||||||
ColumnHeader,
|
ColumnHeader,
|
||||||
|
ColumnHeaderSortable,
|
||||||
RowHeader,
|
RowHeader,
|
||||||
GroupTitle,
|
GroupTitle,
|
||||||
GroupCell,
|
GroupCell,
|
||||||
Cell,
|
Cell,
|
||||||
|
CellRanked,
|
||||||
};
|
};
|
||||||
@@ -26,7 +26,7 @@ const tankDefinitions = await api.tanks();
|
|||||||
|
|
||||||
export const TankCard = (props: MaybeSkeletonComponentProps<TankCardProps>) => {
|
export const TankCard = (props: MaybeSkeletonComponentProps<TankCardProps>) => {
|
||||||
if (props.skeleton) {
|
if (props.skeleton) {
|
||||||
return <TankCardSkeleton />;
|
return <TankCardSkeleton onIntersection={props.onIntersection} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
const unwrap = useUnwrapper();
|
const unwrap = useUnwrapper();
|
||||||
|
|||||||
@@ -1,14 +1,31 @@
|
|||||||
|
import { useEffect, useRef } from "react";
|
||||||
import { InlineSkeleton } from "../InlineSkeleton";
|
import { InlineSkeleton } from "../InlineSkeleton";
|
||||||
import { Skeleton } from "../Skeleton";
|
import { Skeleton } from "../Skeleton";
|
||||||
import styles from "./index.module.css";
|
import styles from "./index.module.css";
|
||||||
|
|
||||||
type TankCardProps = {
|
type TankCardProps = {
|
||||||
compact?: boolean;
|
compact?: boolean;
|
||||||
|
onIntersection?: () => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const TankCardSkeleton = ({ compact }: TankCardProps) => {
|
export const TankCardSkeleton = ({ compact, onIntersection }: TankCardProps) => {
|
||||||
|
const wrapper = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!onIntersection) return;
|
||||||
|
|
||||||
|
const observer = new IntersectionObserver(([entry]) => {
|
||||||
|
if (entry.isIntersecting) onIntersection();
|
||||||
|
});
|
||||||
|
|
||||||
|
observer.observe(wrapper.current!);
|
||||||
|
|
||||||
|
return () => observer.disconnect();
|
||||||
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
|
ref={wrapper}
|
||||||
className={styles.wrapper}
|
className={styles.wrapper}
|
||||||
data-compact={compact}
|
data-compact={compact}
|
||||||
style={{
|
style={{
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import type { Vector2Tuple } from "three";
|
|
||||||
import { metaSortTank, SEARCH_KEYS } from "@blitzkit/core";
|
import { metaSortTank, SEARCH_KEYS } from "@blitzkit/core";
|
||||||
import { literals } from "@blitzkit/i18n/src/literals";
|
import { literals } from "@blitzkit/i18n/src/literals";
|
||||||
import type { TankDefinition } from "@blitzkit/protos";
|
import type { TankDefinition } from "@blitzkit/protos";
|
||||||
@@ -6,6 +5,7 @@ import fuzzysort from "fuzzysort";
|
|||||||
import { uniq } from "lodash-es";
|
import { uniq } from "lodash-es";
|
||||||
import { memo, useMemo } from "react";
|
import { memo, useMemo } from "react";
|
||||||
import usePromise from "react-promise-suspense";
|
import usePromise from "react-promise-suspense";
|
||||||
|
import type { Vector2Tuple } from "three";
|
||||||
import { api } from "../../api/dynamic";
|
import { api } from "../../api/dynamic";
|
||||||
import { characteristics } from "../../config/characteristics";
|
import { characteristics } from "../../config/characteristics";
|
||||||
import { characteristicRenderConfigs } from "../../config/characteristicsGroups";
|
import { characteristicRenderConfigs } from "../../config/characteristicsGroups";
|
||||||
@@ -18,8 +18,8 @@ import { useStrings } from "../../hooks/useStrings";
|
|||||||
import { App } from "../../stores/app";
|
import { App } from "../../stores/app";
|
||||||
import { TankFilters } from "../../stores/tankFilters";
|
import { TankFilters } from "../../stores/tankFilters";
|
||||||
import {
|
import {
|
||||||
|
SortDirection,
|
||||||
TankopediaPersistent,
|
TankopediaPersistent,
|
||||||
TankopediaSortDirection,
|
|
||||||
} from "../../stores/tankopediaPersistent";
|
} from "../../stores/tankopediaPersistent";
|
||||||
import { TankSort } from "../../stores/tankopediaSort";
|
import { TankSort } from "../../stores/tankopediaSort";
|
||||||
import { sortableCharacteristics } from "../../tankopedia/sortableCharacteristics";
|
import { sortableCharacteristics } from "../../tankopedia/sortableCharacteristics";
|
||||||
@@ -108,7 +108,7 @@ export const TankSearch = memo<TankSearchProps>(
|
|||||||
) {
|
) {
|
||||||
const byMeta = metaSortTank([...filtered], gameDefinitions);
|
const byMeta = metaSortTank([...filtered], gameDefinitions);
|
||||||
|
|
||||||
return tankopediaSort.direction === TankopediaSortDirection.Ascending
|
return tankopediaSort.direction === SortDirection.Ascending
|
||||||
? byMeta
|
? byMeta
|
||||||
: byMeta.reverse();
|
: byMeta.reverse();
|
||||||
}
|
}
|
||||||
@@ -171,7 +171,7 @@ export const TankSearch = memo<TankSearchProps>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const direction =
|
const direction =
|
||||||
tankopediaSort.direction === TankopediaSortDirection.Ascending ? 1 : -1;
|
tankopediaSort.direction === SortDirection.Ascending ? 1 : -1;
|
||||||
|
|
||||||
return [...filtered].sort((a, b) => {
|
return [...filtered].sort((a, b) => {
|
||||||
const aValue = values.get(a.id);
|
const aValue = values.get(a.id);
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import {
|
|||||||
} from "@radix-ui/react-icons";
|
} from "@radix-ui/react-icons";
|
||||||
import { characteristicsGroups } from "../config/characteristicsGroups";
|
import { characteristicsGroups } from "../config/characteristicsGroups";
|
||||||
import { useStrings } from "../hooks/useStrings";
|
import { useStrings } from "../hooks/useStrings";
|
||||||
import { TankopediaSortDirection } from "../stores/tankopediaPersistent";
|
import { SortDirection } from "../stores/tankopediaPersistent";
|
||||||
import { TankSort } from "../stores/tankopediaSort";
|
import { TankSort } from "../stores/tankopediaSort";
|
||||||
import { sortableCharacteristics } from "../tankopedia/sortableCharacteristics";
|
import { sortableCharacteristics } from "../tankopedia/sortableCharacteristics";
|
||||||
import type { RenderedCharacteristicName } from "../types/characteristics";
|
import type { RenderedCharacteristicName } from "../types/characteristics";
|
||||||
@@ -112,8 +112,8 @@ export function TankSearchSort() {
|
|||||||
value={direction}
|
value={direction}
|
||||||
onValueChange={(value) => {
|
onValueChange={(value) => {
|
||||||
if (
|
if (
|
||||||
value !== TankopediaSortDirection.Ascending &&
|
value !== SortDirection.Ascending &&
|
||||||
value !== TankopediaSortDirection.Descending
|
value !== SortDirection.Descending
|
||||||
) {
|
) {
|
||||||
throw new Error(`Unknown tankopedia sort direction: ${value}`);
|
throw new Error(`Unknown tankopedia sort direction: ${value}`);
|
||||||
}
|
}
|
||||||
@@ -123,14 +123,14 @@ export function TankSearchSort() {
|
|||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<DropdownMenu.RadioItem value={TankopediaSortDirection.Ascending}>
|
<DropdownMenu.RadioItem value={SortDirection.Ascending}>
|
||||||
<DropdownMenu.ItemIndicator>
|
<DropdownMenu.ItemIndicator>
|
||||||
<DotFilledIcon />
|
<DotFilledIcon />
|
||||||
</DropdownMenu.ItemIndicator>
|
</DropdownMenu.ItemIndicator>
|
||||||
|
|
||||||
{strings.website.common.tank_search.sort.direction.ascending}
|
{strings.website.common.tank_search.sort.direction.ascending}
|
||||||
</DropdownMenu.RadioItem>
|
</DropdownMenu.RadioItem>
|
||||||
<DropdownMenu.RadioItem value={TankopediaSortDirection.Descending}>
|
<DropdownMenu.RadioItem value={SortDirection.Descending}>
|
||||||
<DropdownMenu.ItemIndicator>
|
<DropdownMenu.ItemIndicator>
|
||||||
<DotFilledIcon />
|
<DotFilledIcon />
|
||||||
</DropdownMenu.ItemIndicator>
|
</DropdownMenu.ItemIndicator>
|
||||||
|
|||||||
@@ -0,0 +1,105 @@
|
|||||||
|
import { formatCompact } from "@blitzkit/core";
|
||||||
|
import type { AverageDefinitionsAllStats } from "@blitzkit/protos";
|
||||||
|
import { CharacteristicRanking } from "../types/characteristics";
|
||||||
|
|
||||||
|
export interface PerformanceEntry {
|
||||||
|
stats: AverageDefinitionsAllStats;
|
||||||
|
players: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface PerformanceStat {
|
||||||
|
value: (entry: PerformanceEntry) => number;
|
||||||
|
format: (value: number, locale: string) => string;
|
||||||
|
ranking: CharacteristicRanking;
|
||||||
|
}
|
||||||
|
|
||||||
|
function perBattle(key: keyof AverageDefinitionsAllStats) {
|
||||||
|
return ({ stats }: PerformanceEntry) => stats[key] / stats.battles;
|
||||||
|
}
|
||||||
|
|
||||||
|
function percentage(decimals: number) {
|
||||||
|
return (value: number) => `${(value * 100).toFixed(decimals)}%`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function fixed(decimals: number) {
|
||||||
|
return (value: number) => value.toFixed(decimals);
|
||||||
|
}
|
||||||
|
|
||||||
|
function integer(value: number, locale: string) {
|
||||||
|
return Math.round(value).toLocaleString(locale);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: formalize this more like characteristics
|
||||||
|
export const performanceStats = {
|
||||||
|
winrate: {
|
||||||
|
value: perBattle("wins"),
|
||||||
|
format: percentage(1),
|
||||||
|
ranking: CharacteristicRanking.HigherIsBetter,
|
||||||
|
},
|
||||||
|
players: {
|
||||||
|
value: ({ players }) => players,
|
||||||
|
format: (value, locale) => formatCompact(locale, Math.round(value)),
|
||||||
|
ranking: CharacteristicRanking.None,
|
||||||
|
},
|
||||||
|
damage: {
|
||||||
|
value: perBattle("damage_dealt"),
|
||||||
|
format: integer,
|
||||||
|
ranking: CharacteristicRanking.HigherIsBetter,
|
||||||
|
},
|
||||||
|
survival: {
|
||||||
|
value: perBattle("survived_battles"),
|
||||||
|
format: percentage(0),
|
||||||
|
ranking: CharacteristicRanking.HigherIsBetter,
|
||||||
|
},
|
||||||
|
xp: {
|
||||||
|
value: perBattle("xp"),
|
||||||
|
format: integer,
|
||||||
|
ranking: CharacteristicRanking.HigherIsBetter,
|
||||||
|
},
|
||||||
|
kills: {
|
||||||
|
value: perBattle("frags"),
|
||||||
|
format: fixed(2),
|
||||||
|
ranking: CharacteristicRanking.HigherIsBetter,
|
||||||
|
},
|
||||||
|
spots: {
|
||||||
|
value: perBattle("spotted"),
|
||||||
|
format: fixed(2),
|
||||||
|
ranking: CharacteristicRanking.HigherIsBetter,
|
||||||
|
},
|
||||||
|
accuracy: {
|
||||||
|
value: ({ stats }) => stats.hits / stats.shots,
|
||||||
|
format: percentage(0),
|
||||||
|
ranking: CharacteristicRanking.HigherIsBetter,
|
||||||
|
},
|
||||||
|
shots: {
|
||||||
|
value: perBattle("shots"),
|
||||||
|
format: fixed(1),
|
||||||
|
ranking: CharacteristicRanking.HigherIsBetter,
|
||||||
|
},
|
||||||
|
hits: {
|
||||||
|
value: perBattle("hits"),
|
||||||
|
format: fixed(1),
|
||||||
|
ranking: CharacteristicRanking.HigherIsBetter,
|
||||||
|
},
|
||||||
|
damage_ratio: {
|
||||||
|
value: ({ stats }) => stats.damage_dealt / stats.damage_received,
|
||||||
|
format: fixed(2),
|
||||||
|
ranking: CharacteristicRanking.HigherIsBetter,
|
||||||
|
},
|
||||||
|
damage_taken: {
|
||||||
|
value: perBattle("damage_received"),
|
||||||
|
format: integer,
|
||||||
|
ranking: CharacteristicRanking.LowerIsBetter,
|
||||||
|
},
|
||||||
|
capture_points: {
|
||||||
|
value: perBattle("capture_points"),
|
||||||
|
format: fixed(2),
|
||||||
|
ranking: CharacteristicRanking.HigherIsBetter,
|
||||||
|
},
|
||||||
|
} satisfies Record<string, PerformanceStat>;
|
||||||
|
|
||||||
|
export type PerformanceStatName = keyof typeof performanceStats;
|
||||||
|
|
||||||
|
export const performanceStatNames = Object.keys(
|
||||||
|
performanceStats,
|
||||||
|
) as PerformanceStatName[];
|
||||||
@@ -24,7 +24,6 @@ export const tools: Record<string, Tool> = {
|
|||||||
banner_background_position: "bottom",
|
banner_background_position: "bottom",
|
||||||
},
|
},
|
||||||
performance: {
|
performance: {
|
||||||
disabled: true,
|
|
||||||
id: "performance",
|
id: "performance",
|
||||||
banner_background_position: "bottom",
|
banner_background_position: "bottom",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1 +1,7 @@
|
|||||||
export const awaitableAverageDefinitions = fetchAverage();
|
import { fetchPB, staticAsset } from "@blitzkit/core";
|
||||||
|
import { AverageDefinitions } from "@blitzkit/protos";
|
||||||
|
|
||||||
|
export const awaitableAverageDefinitions = fetchPB(
|
||||||
|
staticAsset("averages.pb"),
|
||||||
|
AverageDefinitions,
|
||||||
|
);
|
||||||
@@ -1 +1,3 @@
|
|||||||
|
import { fetchDiscoveredIds } from "@blitzkit/core";
|
||||||
|
|
||||||
export const awaitableDiscoveredIdsDefinitions = fetchDiscoveredIds();
|
export const awaitableDiscoveredIdsDefinitions = fetchDiscoveredIds();
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
import { awaitableAverageDefinitions } from "../core/awaitables/averageDefinitions";
|
|
||||||
import { awaitableDiscoveredIdsDefinitions } from "../core/awaitables/discoveredIdsDefinitions";
|
|
||||||
|
|
||||||
const [discoveredIdsDefinitions, averageDefinitions] = await Promise.all([
|
|
||||||
awaitableDiscoveredIdsDefinitions,
|
|
||||||
awaitableAverageDefinitions,
|
|
||||||
]);
|
|
||||||
|
|
||||||
export function useAveragesExclusionRatio() {
|
|
||||||
return discoveredIdsDefinitions.count / averageDefinitions.samples!.total;
|
|
||||||
}
|
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
import type { APIContext, GetStaticPathsItem } from "astro";
|
import type { APIContext, GetStaticPathsItem } from "astro";
|
||||||
import sharp from "sharp";
|
import sharp from "sharp";
|
||||||
|
import { mixStaticPaths } from "../../../../astro/mixStaticPaths";
|
||||||
import {
|
import {
|
||||||
docImageId,
|
docImageId,
|
||||||
externalDocImages,
|
externalDocImages,
|
||||||
} from "../../../../core/blitzkit/docImages";
|
} from "../../../../core/blitzkit/docImages";
|
||||||
import { mixStaticPaths } from "../../../../core/blitzkit/mixStaticPaths";
|
|
||||||
import { getStaticPaths as _getStaticPaths } from "../../_index";
|
import { getStaticPaths as _getStaticPaths } from "../../_index";
|
||||||
|
|
||||||
export const getStaticPaths = mixStaticPaths(_getStaticPaths, async () => {
|
export const getStaticPaths = mixStaticPaths(_getStaticPaths, async () => {
|
||||||
@@ -20,7 +20,7 @@ export const getStaticPaths = mixStaticPaths(_getStaticPaths, async () => {
|
|||||||
({
|
({
|
||||||
params: { id: docImageId(url) },
|
params: { id: docImageId(url) },
|
||||||
props: { url },
|
props: { url },
|
||||||
}) satisfies GetStaticPathsItem,
|
} satisfies GetStaticPathsItem),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,19 +0,0 @@
|
|||||||
---
|
|
||||||
import ToolOpenGraph from "../../../../components/ToolOpenGraph.astro";
|
|
||||||
import { tools } from "../../../../constants/tools";
|
|
||||||
import BaseLayout from "../../../../layouts/BaseLayout.astro";
|
|
||||||
import type { getStaticPaths } from "../index.astro";
|
|
||||||
import { Page } from "./_index";
|
|
||||||
|
|
||||||
export { getStaticPaths } from "../index.astro";
|
|
||||||
|
|
||||||
const { locale } = Astro.props;
|
|
||||||
---
|
|
||||||
|
|
||||||
<ToolOpenGraph {locale} tool={tools.performance} />
|
|
||||||
|
|
||||||
<BaseLayout {locale} noFooter>
|
|
||||||
<Page client:only="react" {locale}>
|
|
||||||
<Page skeleton slot="fallback" {locale} />
|
|
||||||
</Page>
|
|
||||||
</BaseLayout>
|
|
||||||
+28
@@ -0,0 +1,28 @@
|
|||||||
|
.page {
|
||||||
|
/* Fixed to the viewport so the table scrolls, not the page */
|
||||||
|
height: 100dvh;
|
||||||
|
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
box-sizing: border-box;
|
||||||
|
|
||||||
|
.top {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
gap: var(--space-4);
|
||||||
|
|
||||||
|
padding: var(--space-4);
|
||||||
|
}
|
||||||
|
|
||||||
|
.table {
|
||||||
|
flex: 1;
|
||||||
|
min-height: 0;
|
||||||
|
align-self: stretch;
|
||||||
|
overflow: hidden;
|
||||||
|
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,30 +1,19 @@
|
|||||||
import { PageWrapper } from "../../../../components/PageWrapper";
|
import { PerformanceControls } from "../../../../components/PerformanceControls";
|
||||||
import { PlayerCountControl } from "../../../../components/Performance/PlayerCountControl";
|
import { PerformanceTable } from "../../../../components/PerformanceTable";
|
||||||
import { TankTable } from "../../../../components/Performance/Table";
|
import { withErrorWrapper } from "../../../../hocs/withErrorWrapper";
|
||||||
import { TankSearchFilters } from "../../../../components/TankSearchFilters";
|
import { withLocale } from "../../../../hocs/withLocale";
|
||||||
import {
|
import styles from "./_index.module.css";
|
||||||
LocaleProvider,
|
|
||||||
type LocaleAcceptorProps,
|
|
||||||
} from "../../../../hooks/useLocale";
|
|
||||||
import type { MaybeSkeletonComponentProps } from "../../../../types/maybeSkeletonComponentProps";
|
|
||||||
|
|
||||||
type PageProps = MaybeSkeletonComponentProps & LocaleAcceptorProps;
|
export const Page = withLocale(
|
||||||
|
withErrorWrapper(() => (
|
||||||
|
<div className={styles.page}>
|
||||||
|
<div className={styles.top}>
|
||||||
|
<PerformanceControls />
|
||||||
|
</div>
|
||||||
|
|
||||||
export function Page({ skeleton, locale }: PageProps) {
|
<div className={styles.table}>
|
||||||
return (
|
<PerformanceTable />
|
||||||
<LocaleProvider locale={locale}>
|
</div>
|
||||||
<Content skeleton={skeleton} />
|
</div>
|
||||||
</LocaleProvider>
|
)),
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
function Content({ skeleton }: MaybeSkeletonComponentProps) {
|
|
||||||
return (
|
|
||||||
<PageWrapper pb="0" px="0" color="jade" maxWidth="100%">
|
|
||||||
<TankSearchFilters />
|
|
||||||
<PlayerCountControl />
|
|
||||||
|
|
||||||
<TankTable skeleton={skeleton} />
|
|
||||||
</PageWrapper>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
---
|
||||||
|
import ColorScale from "../../../../components/ColorScale.astro";
|
||||||
|
import BaseLayout from "../../../../layouts/BaseLayout.astro";
|
||||||
|
import { Page } from "./_index";
|
||||||
|
|
||||||
|
export { getStaticPaths } from "../index.astro";
|
||||||
|
|
||||||
|
const { locale } = Astro.props;
|
||||||
|
---
|
||||||
|
|
||||||
|
<BaseLayout accent="jade" {locale}>
|
||||||
|
<ColorScale color="red" />
|
||||||
|
<ColorScale color="jade" />
|
||||||
|
<ColorScale color="amber" />
|
||||||
|
<ColorScale color="blue" />
|
||||||
|
|
||||||
|
<Page {locale} client:load />
|
||||||
|
</BaseLayout>
|
||||||
@@ -2,7 +2,7 @@ import type { TankEnvironment } from "@blitzkit/core";
|
|||||||
import { Soapstone } from "soapstone";
|
import { Soapstone } from "soapstone";
|
||||||
import { resolveTankModules } from "../tankopedia/resolveTankModules";
|
import { resolveTankModules } from "../tankopedia/resolveTankModules";
|
||||||
import type { TankState } from "../tankopedia/tankState";
|
import type { TankState } from "../tankopedia/tankState";
|
||||||
import { TankopediaSortDirection } from "./tankopediaPersistent";
|
import { SortDirection } from "./tankopediaPersistent";
|
||||||
import type { TankSort } from "./tankopediaSort";
|
import type { TankSort } from "./tankopediaSort";
|
||||||
|
|
||||||
export interface CompareMember {
|
export interface CompareMember {
|
||||||
@@ -24,7 +24,7 @@ export const CompareEphemeral = new Soapstone<
|
|||||||
environment,
|
environment,
|
||||||
syncShells: false,
|
syncShells: false,
|
||||||
members: [],
|
members: [],
|
||||||
sorting: { by: null, direction: TankopediaSortDirection.Descending },
|
sorting: { by: null, direction: SortDirection.Descending },
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// Picks the shell at the same slot on every member, where one exists
|
// Picks the shell at the same slot on every member, where one exists
|
||||||
|
|||||||
@@ -1,12 +1,24 @@
|
|||||||
import type { Samples } from "@blitzkit/protos";
|
import type { Samples } from "@blitzkit/protos";
|
||||||
import { Soapstone } from "soapstone";
|
import { Soapstone } from "soapstone";
|
||||||
|
import type { PerformanceStatName } from "../config/performanceStats";
|
||||||
export interface Performance {
|
import { SortDirection } from "./tankopediaPersistent";
|
||||||
playerCountPeriod: PlayerCountPeriod;
|
|
||||||
}
|
|
||||||
|
|
||||||
export type PlayerCountPeriod = keyof Samples;
|
export type PlayerCountPeriod = keyof Samples;
|
||||||
|
|
||||||
|
export interface PerformanceSort {
|
||||||
|
by: PerformanceStatName;
|
||||||
|
direction: SortDirection;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Performance {
|
||||||
|
player_count_period: PlayerCountPeriod;
|
||||||
|
sorting: PerformanceSort;
|
||||||
|
}
|
||||||
|
|
||||||
export const Performance = new Soapstone<Performance>({
|
export const Performance = new Soapstone<Performance>({
|
||||||
playerCountPeriod: "total",
|
player_count_period: "total",
|
||||||
|
sorting: {
|
||||||
|
by: "winrate",
|
||||||
|
direction: SortDirection.Descending,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
import en from '@blitzkit/i18n/strings/en.json';
|
|
||||||
import type { TankPerformanceSortType } from '.';
|
|
||||||
|
|
||||||
export const TankPerformanceSortTypeNamesArray = Object.keys(
|
|
||||||
en.website.tools.performance.table.stats,
|
|
||||||
) as TankPerformanceSortType[];
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
import type en from "@blitzkit/i18n/strings/en.json";
|
|
||||||
import { Soapstone } from "soapstone";
|
|
||||||
|
|
||||||
export type TankPerformanceSortType =
|
|
||||||
keyof typeof en.website.tools.performance.table.stats;
|
|
||||||
|
|
||||||
export interface TankPerformanceSort {
|
|
||||||
type: TankPerformanceSortType;
|
|
||||||
direction: -1 | 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const TankPerformanceSort = new Soapstone<TankPerformanceSort>({
|
|
||||||
type: "winrate",
|
|
||||||
direction: -1,
|
|
||||||
});
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Soapstone } from "soapstone";
|
import { Soapstone } from "soapstone";
|
||||||
|
|
||||||
export enum TankopediaSortDirection {
|
export enum SortDirection {
|
||||||
Ascending = "ascending",
|
Ascending = "ascending",
|
||||||
Descending = "descending",
|
Descending = "descending",
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
import { Soapstone } from "soapstone";
|
import { Soapstone } from "soapstone";
|
||||||
import type { RenderedCharacteristicName } from "../types/characteristics";
|
import type { RenderedCharacteristicName } from "../types/characteristics";
|
||||||
import { TankopediaSortDirection } from "./tankopediaPersistent";
|
import { SortDirection } from "./tankopediaPersistent";
|
||||||
|
|
||||||
export interface TankSort {
|
export interface TankSort {
|
||||||
by: RenderedCharacteristicName | null;
|
by: RenderedCharacteristicName | null;
|
||||||
direction: TankopediaSortDirection;
|
direction: SortDirection;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const TankSort = new Soapstone<TankSort>({
|
export const TankSort = new Soapstone<TankSort>({
|
||||||
by: null,
|
by: null,
|
||||||
direction: TankopediaSortDirection.Descending,
|
direction: SortDirection.Descending,
|
||||||
});
|
});
|
||||||
Reference in new issue
Block a user