Files
blitzkit/packages/bot/src/components/AllStatsOverview/index.tsx
T

130 lines
3.4 KiB
TypeScript
Raw Normal View History

2024-09-08 10:17:40 -05:00
import {
getWN8Percentile,
Percentile,
2025-10-13 23:15:32 -05:00
type SupplementaryStats,
2024-09-08 10:17:40 -05:00
} from '@blitzkit/core';
2024-03-08 20:29:35 -06:00
import { Locale } from 'discord.js';
2024-09-08 10:11:24 -05:00
import { translator } from '../../core/localization/translator';
2024-04-16 19:03:37 -05:00
import { PERCENTILE_COLORS } from '../PercentileIndicator/constants';
2024-03-20 20:40:01 -05:00
import { HeroStat } from './components/HeroStat';
2023-06-28 17:58:36 +00:00
import {
WN8SurroundingStat,
WN8SurroundingStatAlign,
2023-07-11 19:54:57 +00:00
} from './components/WN8SurroundingStat';
2023-06-28 17:58:36 +00:00
export interface AllStatsOverviewProps {
2024-03-20 18:03:00 -05:00
stats: {
battles: number;
wins: number;
damage_dealt: number;
damage_received: number;
survived_battles: number;
hits: number;
shots: number;
frags: number;
};
2023-06-28 17:58:36 +00:00
supplementaryStats: SupplementaryStats;
2024-03-08 20:29:35 -06:00
locale: Locale;
2023-06-28 17:58:36 +00:00
}
2024-09-08 10:11:24 -05:00
export function AllStatsOverview({
2023-06-28 17:58:36 +00:00
stats,
2024-03-08 20:29:35 -06:00
locale,
2023-06-28 17:58:36 +00:00
supplementaryStats,
}: AllStatsOverviewProps) {
2025-01-16 13:48:13 -06:00
const { strings } = translator(locale);
2024-04-16 19:03:37 -05:00
const percentile =
2024-06-06 19:41:53 -05:00
typeof supplementaryStats.WN8 === 'number'
? getWN8Percentile(supplementaryStats.WN8)
: Percentile.VeryBad;
2024-04-16 19:03:37 -05:00
const color = PERCENTILE_COLORS[percentile];
2024-06-06 19:41:53 -05:00
2024-04-16 19:03:37 -05:00
const heroStat =
2024-06-06 19:41:53 -05:00
typeof supplementaryStats.WN8 === 'number'
? supplementaryStats.WN8.toFixed(0)
: '--';
2024-03-08 20:29:35 -06:00
2023-06-28 17:58:36 +00:00
return (
<div
style={{
display: 'flex',
2024-03-21 22:32:01 -05:00
alignItems: 'center',
2023-06-28 17:58:36 +00:00
gap: -64,
width: '100%',
2023-06-28 17:58:36 +00:00
}}
>
<div
style={{
display: 'flex',
flexDirection: 'column',
gap: 8,
alignItems: 'flex-end',
flex: 1,
}}
>
<WN8SurroundingStat
2025-01-16 13:48:13 -06:00
label={strings.bot.common.hero_stats.battles}
2023-06-28 17:58:36 +00:00
value={stats.battles.toLocaleString()}
align={WN8SurroundingStatAlign.Right}
/>
<WN8SurroundingStat
2025-01-16 13:48:13 -06:00
label={strings.bot.common.hero_stats.winrate}
2023-06-28 17:58:36 +00:00
value={`${(100 * (stats.wins / stats.battles)).toFixed(2)}%`}
align={WN8SurroundingStatAlign.Right}
padded
/>
<WN8SurroundingStat
2025-01-16 13:48:13 -06:00
label={strings.bot.common.hero_stats.damage}
2023-06-28 17:58:36 +00:00
value={Math.round(
stats.damage_dealt / stats.battles,
).toLocaleString()}
align={WN8SurroundingStatAlign.Right}
padded
/>
<WN8SurroundingStat
2025-01-16 13:48:13 -06:00
label={strings.bot.common.hero_stats.damage_ratio}
2023-06-28 17:58:36 +00:00
value={(stats.damage_dealt / stats.damage_received).toFixed(2)}
align={WN8SurroundingStatAlign.Right}
/>
</div>
2024-04-16 19:03:37 -05:00
<HeroStat
value={heroStat}
2025-01-16 13:48:13 -06:00
subtitle={strings.common.wn8_percentile[percentile]}
2024-04-16 19:03:37 -05:00
color={color}
/>
2023-06-28 17:58:36 +00:00
<div
style={{
display: 'flex',
flexDirection: 'column',
gap: 8,
flex: 1,
}}
>
2024-03-24 22:06:48 -05:00
<WN8SurroundingStat
2025-01-16 13:48:13 -06:00
label={strings.bot.common.hero_stats.tier}
2024-03-24 22:06:48 -05:00
value={
supplementaryStats.tier ? supplementaryStats.tier.toFixed(2) : '--'
}
/>
2023-06-28 17:58:36 +00:00
<WN8SurroundingStat
2025-01-16 13:48:13 -06:00
label={strings.bot.common.hero_stats.survival}
2023-06-28 17:58:36 +00:00
value={`${(100 * (stats.survived_battles / stats.battles)).toFixed(
2,
)}%`}
padded
/>
<WN8SurroundingStat
2025-01-16 13:48:13 -06:00
label={strings.bot.common.hero_stats.accuracy}
2023-06-28 17:58:36 +00:00
value={`${(100 * (stats.hits / stats.shots)).toFixed(2)}%`}
padded
/>
<WN8SurroundingStat
2025-01-16 13:48:13 -06:00
label={strings.bot.common.hero_stats.kills}
2024-03-20 20:40:01 -05:00
value={(stats.frags / stats.battles).toFixed(2)}
2023-06-28 17:58:36 +00:00
/>
</div>
</div>
);
}