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

127 lines
3.5 KiB
TypeScript
Raw Normal View History

2024-03-08 20:29:35 -06:00
import { Locale } from 'discord.js';
2024-04-16 19:03:37 -05:00
import { Percentile } from '../../constants/percentiles';
2024-03-20 18:03:00 -05:00
import { SupplementaryStats } from '../../core/blitz/getAccountInfo';
2024-03-08 20:29:35 -06:00
import { translator } from '../../core/localization/translator';
2024-04-16 19:03:37 -05:00
import getWN8Percentile from '../../core/statistics/getWN8Percentile';
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
}
export default function AllStatsOverview({
stats,
2024-03-08 20:29:35 -06:00
locale,
2023-06-28 17:58:36 +00:00
supplementaryStats,
}: AllStatsOverviewProps) {
2024-04-16 19:03:37 -05:00
const { t, translate } = translator(locale);
const percentile =
supplementaryStats.WN8 === undefined
? Percentile.VeryBad
: getWN8Percentile(supplementaryStats.WN8);
const color = PERCENTILE_COLORS[percentile];
const heroStat =
supplementaryStats.WN8 === undefined
? '--'
: 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
2024-03-20 20:40:01 -05:00
label={t`bot.common.hero_stats.battles`}
2023-06-28 17:58:36 +00:00
value={stats.battles.toLocaleString()}
align={WN8SurroundingStatAlign.Right}
/>
<WN8SurroundingStat
2024-03-20 20:40:01 -05:00
label={t`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
2024-03-20 20:40:01 -05:00
label={t`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
2024-03-20 20:40:01 -05:00
label={t`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}
subtitle={translate(`common.wn8_percentile.${percentile}`)}
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
label={t`bot.common.hero_stats.tier`}
value={
supplementaryStats.tier ? supplementaryStats.tier.toFixed(2) : '--'
}
/>
2023-06-28 17:58:36 +00:00
<WN8SurroundingStat
2024-03-20 20:40:01 -05:00
label={t`bot.common.hero_stats.survival`}
2023-06-28 17:58:36 +00:00
value={`${(100 * (stats.survived_battles / stats.battles)).toFixed(
2,
)}%`}
padded
/>
<WN8SurroundingStat
2024-03-20 20:40:01 -05:00
label={t`bot.common.hero_stats.accuracy`}
2023-06-28 17:58:36 +00:00
value={`${(100 * (stats.hits / stats.shots)).toFixed(2)}%`}
padded
/>
<WN8SurroundingStat
2024-03-20 20:40:01 -05:00
label={t`bot.common.hero_stats.kills`}
value={(stats.frags / stats.battles).toFixed(2)}
2023-06-28 17:58:36 +00:00
/>
</div>
</div>
);
}