Files
blitzkit/packages/website/src/components/TanksEmbed.tsx
T

149 lines
4.5 KiB
TypeScript
Raw Normal View History

2024-09-07 21:45:00 -05:00
import {
2024-11-08 10:32:44 -06:00
formatCompositeStat,
2024-10-05 20:55:44 -05:00
TankClass,
2024-09-07 21:45:00 -05:00
TankDefinition,
2024-10-05 20:55:44 -05:00
TankType,
2024-11-08 10:32:44 -06:00
type CompositeStats,
2024-10-05 20:55:44 -05:00
type CompositeStatsKey,
2024-09-07 21:45:00 -05:00
} from '@blitzkit/core';
2025-01-14 19:22:41 -06:00
import strings from '@blitzkit/i18n/strings/en.json';
2024-08-08 14:22:04 -05:00
import { amberDark, blueDark } from '@radix-ui/colors';
2024-11-04 10:36:43 -06:00
import { Flex, Text, type FlexProps } from '@radix-ui/themes';
2024-09-14 19:43:14 -05:00
import { times } from 'lodash-es';
2024-10-05 20:55:44 -05:00
import type { ReactNode } from 'react';
2024-09-08 21:52:12 -05:00
import { breakdownConfig } from '../constants/embeds';
2024-10-05 20:55:44 -05:00
import { toRadiusVar } from '../core/radix/utils';
2025-01-14 19:22:41 -06:00
import { useLocale } from '../hooks/useLocale';
2024-10-05 20:55:44 -05:00
import { useEmbedStateCurry } from '../stores/embedState/utilities';
2024-09-07 21:45:00 -05:00
import { ClassHeavy } from './ClassIcon/components/ClassHeavy';
import { ClassLight } from './ClassIcon/components/ClassLight';
import { ClassMedium } from './ClassIcon/components/ClassMedium';
import { ClassTankDestroyer } from './ClassIcon/components/ClassTankDestroyer';
2024-08-05 12:52:40 -05:00
2024-11-04 10:36:43 -06:00
type BreakdownEmbedWrapperProps = FlexProps & {
2024-08-05 12:52:40 -05:00
children: ReactNode;
2024-11-04 10:36:43 -06:00
};
2024-08-05 12:52:40 -05:00
2024-08-07 12:03:45 -05:00
export function BreakdownEmbedWrapper({
children,
2024-11-04 10:36:43 -06:00
...props
2024-08-07 12:03:45 -05:00
}: BreakdownEmbedWrapperProps) {
2024-10-28 10:30:53 -05:00
const { useEmbedState } = useEmbedStateCurry<typeof breakdownConfig>();
2024-08-08 14:18:22 -05:00
2024-08-05 12:52:40 -05:00
return (
2024-11-04 10:36:43 -06:00
<Flex
direction="column"
gap={useEmbedState('listGap')}
height="100%"
{...props}
>
2024-08-05 12:52:40 -05:00
{children}
</Flex>
);
}
2024-08-07 12:03:45 -05:00
interface BreakdownEmbedCardProps {
2024-11-04 10:38:48 -06:00
tank: TankDefinition | null | undefined;
2024-11-08 10:32:44 -06:00
composite: CompositeStats;
2024-08-05 12:52:40 -05:00
}
2024-11-08 10:32:44 -06:00
export function BreakdownEmbedCard({
tank,
composite,
}: BreakdownEmbedCardProps) {
2024-10-28 10:30:53 -05:00
const { useEmbedState, useRichText } =
2024-08-08 14:18:22 -05:00
useEmbedStateCurry<typeof breakdownConfig>();
2025-01-14 19:22:41 -06:00
const { unwrap } = useLocale();
2024-08-08 14:18:22 -05:00
2024-08-05 12:52:40 -05:00
return (
<Flex
2024-08-11 13:05:11 -05:00
flexShrink="0"
2024-08-05 12:52:40 -05:00
direction="column"
style={{
2024-10-28 10:30:53 -05:00
borderRadius: toRadiusVar(useEmbedState('cardRadius')),
2024-08-05 12:52:40 -05:00
overflow: 'hidden',
2024-10-28 10:30:53 -05:00
backgroundColor: useEmbedState('cardBodyBackgroundColor'),
2024-08-05 12:52:40 -05:00
}}
>
<Flex
justify="center"
style={{
2024-10-28 10:30:53 -05:00
backgroundColor: useEmbedState('cardHeaderBackgroundColor'),
2024-08-05 12:52:40 -05:00
}}
2024-10-28 10:30:53 -05:00
p={useEmbedState('cardHeaderPadding')}
2024-08-05 12:52:40 -05:00
>
2024-08-06 13:33:39 -05:00
<Text
2024-08-08 14:22:04 -05:00
{...{
...useRichText('cardTitle'),
style:
tank === null
? undefined
2024-11-04 10:38:48 -06:00
: tank === undefined ||
tank.type === TankType.RESEARCHABLE ||
2024-10-28 10:30:53 -05:00
!useEmbedState('cardTitleTypeColor')
2024-09-08 21:52:12 -05:00
? undefined
: {
color:
2024-10-05 20:55:44 -05:00
tank.type === TankType.PREMIUM
2024-09-08 21:52:12 -05:00
? amberDark.amber11
: blueDark.blue11,
},
2024-08-08 14:18:22 -05:00
}}
2024-08-06 13:33:39 -05:00
>
<Flex align="center" gap="1">
2024-11-04 10:38:48 -06:00
{useEmbedState('cardTitleClassIcon') &&
tank !== null &&
tank !== undefined && (
<>
{tank.class === TankClass.LIGHT && (
<ClassLight width="1em" height="1em" />
)}
{tank.class === TankClass.MEDIUM && (
<ClassMedium width="1em" height="1em" />
)}
{tank.class === TankClass.HEAVY && (
<ClassHeavy width="1em" height="1em" />
)}
{tank.class === TankClass.TANK_DESTROYER && (
<ClassTankDestroyer width="1em" height="1em" />
)}
</>
)}{' '}
{tank === null
? 'Total'
: tank === undefined
? `Unknown tank`
2025-01-14 19:22:41 -06:00
: unwrap(tank.name)}
2024-08-06 13:33:39 -05:00
</Flex>
</Text>
2024-08-05 12:52:40 -05:00
</Flex>
2024-08-05 14:25:12 -05:00
2024-10-28 10:30:53 -05:00
<Flex p={useEmbedState('cardBodyPadding')}>
2024-08-05 14:25:12 -05:00
{times(4, (index) => {
const column = (index + 1) as 1 | 2 | 3 | 4;
2024-11-08 10:32:44 -06:00
const statKey = useEmbedState(`column${column}`) as CompositeStatsKey;
2024-10-28 10:30:53 -05:00
const customLabel = useEmbedState(`column${column}CustomLabel`);
2024-08-05 14:25:12 -05:00
return (
<Flex
2024-10-26 14:34:56 -05:00
key={column}
2024-08-05 14:25:12 -05:00
direction="column"
align="center"
2024-10-28 10:30:53 -05:00
gap={useEmbedState('columnGap')}
2024-08-05 14:25:12 -05:00
flexGrow="1"
>
2024-08-08 14:18:22 -05:00
<Text {...useRichText('columnValue')}>
2024-11-08 10:32:44 -06:00
{formatCompositeStat(composite[statKey], statKey, composite)}
2024-08-05 14:25:12 -05:00
</Text>
2024-08-08 14:18:22 -05:00
<Text {...useRichText('columnLabel')}>
2024-08-10 13:29:10 -05:00
{customLabel.length === 0
2024-11-08 10:32:44 -06:00
? strings.common.composite_stats[statKey]
2024-08-10 13:29:10 -05:00
: customLabel}
2024-08-05 14:25:12 -05:00
</Text>
</Flex>
);
})}
</Flex>
2024-08-05 12:52:40 -05:00
</Flex>
);
}