Files
blitzkit/src/app/tools/tankopedia/[id]/components/Model/HeroSection.tsx
T

169 lines
5.7 KiB
TypeScript
Raw Normal View History

2024-05-04 16:53:26 -05:00
import { ChevronLeftIcon, MixIcon } from '@radix-ui/react-icons';
2024-07-09 20:53:00 -05:00
import { Box, Button, Flex, Heading, Text } from '@radix-ui/themes';
2024-05-03 21:17:31 -05:00
import Link from 'next/link';
2024-07-29 14:08:52 -05:00
import { Suspense, use, useEffect, useMemo, useState } from 'react';
2024-06-29 12:12:10 -05:00
import { classIcons } from '../../../../../../components/ClassIcon';
2024-07-31 13:40:50 -05:00
import { ThicknessRange } from '../../../../../../components/StaticArmor';
2024-07-30 13:45:52 -05:00
import { resolveNearPenetration } from '../../../../../../core/blitz/resolveNearPenetration';
2024-07-29 14:08:52 -05:00
import { tankDefinitions } from '../../../../../../core/blitzkit/tankDefinitions';
2024-05-03 12:57:04 -05:00
import { TIER_ROMAN_NUMERALS } from '../../../../../../core/blitzkit/tankDefinitions/constants';
2024-05-04 17:02:03 -05:00
import { useFullScreen } from '../../../../../../hooks/useFullScreen';
2024-05-03 12:57:04 -05:00
import strings from '../../../../../../lang/en-US.json';
2024-07-09 20:35:36 -05:00
import * as Duel from '../../../../../../stores/duel';
2024-05-03 17:07:27 -05:00
import { Options } from './components/Options';
2024-07-10 13:31:21 -05:00
import { TankSandbox } from './TankSandbox';
import { TankSandboxLoader } from './TankSandboxLoader';
2024-05-03 12:57:04 -05:00
2024-07-29 14:08:52 -05:00
interface HeroSectionProps {
id: number;
}
export function HeroSection({ id }: HeroSectionProps) {
2024-07-10 13:11:09 -05:00
const protagonist = Duel.use((state) => state.protagonist.tank);
const antagonist = Duel.use((state) => state.antagonist.tank);
2024-05-03 21:17:31 -05:00
const compareTanks =
2024-06-29 12:12:10 -05:00
protagonist.id === antagonist.id
? [protagonist.id]
: [protagonist.id, antagonist.id];
2024-05-04 17:02:03 -05:00
const isFullScreen = useFullScreen();
2024-06-29 12:12:10 -05:00
const Icon = classIcons[protagonist.class];
2024-07-10 20:47:02 -05:00
const [dummyLoader, setDummyLoader] = useState(true);
2024-07-13 14:25:26 -05:00
const treeColor =
protagonist.treeType === 'collector'
? 'blue'
: protagonist.treeType === 'premium'
? 'amber'
: undefined;
2024-07-29 14:08:52 -05:00
const awaitedTankDefinitions = use(tankDefinitions);
const tank = awaitedTankDefinitions[id];
const thicknessRange = useMemo(() => {
2024-07-30 13:45:52 -05:00
const entries = Object.values(awaitedTankDefinitions);
const filtered = entries.filter((thisTank) => thisTank.tier === tank.tier);
const value =
2024-07-31 13:25:58 -05:00
(filtered.reduce((accumulator, thisTank) => {
2024-07-30 13:45:52 -05:00
return (
accumulator +
resolveNearPenetration(
thisTank.turrets.at(-1)!.guns.at(-1)!.shells[0].penetration,
)
);
}, 0) /
2024-07-31 13:25:58 -05:00
filtered.length) *
(3 / 4);
2024-07-29 14:08:52 -05:00
2024-07-30 13:45:52 -05:00
return { value } satisfies ThicknessRange;
2024-07-29 14:08:52 -05:00
}, [tank.tier]);
2024-07-10 20:47:02 -05:00
useEffect(() => {
setDummyLoader(false);
}, []);
2024-05-03 12:57:04 -05:00
return (
<Flex
justify="center"
2024-07-09 20:53:00 -05:00
pt={{ initial: '6', md: '0' }}
style={{ background: 'var(--color-surface)', position: 'relative' }}
height={{ initial: 'calc(75vh - 64px)', md: undefined }}
2024-05-03 20:49:05 -05:00
gap="4"
2024-05-03 12:57:04 -05:00
>
<Flex
2024-07-09 20:53:00 -05:00
direction={{ initial: 'column', md: 'row' }}
style={{ maxWidth: 1600, flex: 1 }}
2024-05-03 12:57:04 -05:00
>
<Flex
2024-05-03 17:26:14 -05:00
align="center"
2024-05-03 12:57:04 -05:00
justify="center"
2024-07-09 20:53:00 -05:00
flexGrow={{ initial: undefined, md: '1' }}
flexBasis="0"
2024-05-03 12:57:04 -05:00
>
2024-05-03 19:03:25 -05:00
<Flex
2024-07-09 20:53:00 -05:00
gap={{ initial: '2', md: '4' }}
2024-05-03 19:03:25 -05:00
direction="column"
2024-07-09 20:53:00 -05:00
ml={{ initial: '0', md: '8' }}
2024-07-09 21:01:09 -05:00
align={{ initial: 'center', md: 'start' }}
2024-05-04 16:53:26 -05:00
justify="center"
style={{
height: '100%',
2024-07-29 20:18:31 -05:00
userSelect: 'none',
2024-05-04 16:53:26 -05:00
}}
2024-05-03 19:03:25 -05:00
>
2024-07-10 20:47:02 -05:00
<Flex gap="4">
2024-07-13 14:25:26 -05:00
<Heading size={{ initial: '8', md: '9' }} color={treeColor}>
2024-07-10 20:47:02 -05:00
<Icon style={{ width: '0.75em', height: '0.75em' }} />{' '}
</Heading>
<Heading
size={{ initial: '8', md: '9' }}
align={{ initial: 'center', md: 'left' }}
2024-07-13 14:25:26 -05:00
color={treeColor}
2024-07-10 20:47:02 -05:00
>
{protagonist.name}
</Heading>
</Flex>
2024-05-04 16:53:26 -05:00
2024-07-09 21:01:09 -05:00
<Text color="gray" ml={{ initial: '0', md: '9' }}>
2024-06-29 12:12:10 -05:00
Tier {TIER_ROMAN_NUMERALS[protagonist.tier]}{' '}
2024-05-03 17:42:28 -05:00
{
(strings.common.nations_adjectives as Record<string, string>)[
2024-06-29 12:12:10 -05:00
protagonist.nation
2024-05-03 17:42:28 -05:00
]
}{' '}
2024-06-29 12:12:10 -05:00
{strings.common.tank_class_short[protagonist.class]}
2024-05-03 17:26:14 -05:00
</Text>
2024-07-09 21:01:09 -05:00
<Flex gap="4" ml={{ initial: '0', md: '9' }} mt="-1">
2024-05-04 16:53:26 -05:00
<Link href="/tools/tankopedia">
<Button variant="ghost" size="1" ml="-1">
<ChevronLeftIcon />
Back
</Button>
</Link>
<Link href={`/tools/compare?tanks=${compareTanks.join('%2C')}`}>
<Button variant="ghost" size="1">
<MixIcon />
Compare
</Button>
</Link>
</Flex>
2024-05-03 17:26:14 -05:00
</Flex>
2024-05-03 12:57:04 -05:00
</Flex>
2024-07-09 20:53:00 -05:00
<Box
2024-05-04 17:14:08 -05:00
className="tank-sandbox-container"
2024-07-09 20:53:00 -05:00
height={{ initial: undefined, md: '512px' }}
2024-05-03 12:57:04 -05:00
style={{
2024-05-03 20:49:05 -05:00
flex: 2,
2024-05-04 17:02:03 -05:00
position: isFullScreen ? 'fixed' : 'relative',
top: isFullScreen ? 0 : undefined,
left: isFullScreen ? 0 : undefined,
width: isFullScreen ? '100vw' : undefined,
2024-07-09 20:53:00 -05:00
height: isFullScreen ? '100vh' : 'auto',
2024-05-04 17:02:03 -05:00
zIndex: isFullScreen ? 3 : undefined,
2024-07-09 20:53:00 -05:00
background: isFullScreen ? 'var(--color-background)' : undefined,
2024-05-03 12:57:04 -05:00
}}
>
2024-07-10 13:16:04 -05:00
<Box width="100%" height="100%" position="absolute">
<Box width="100%" height="100%">
2024-07-10 20:47:02 -05:00
<TankSandboxLoader
id={id}
display={dummyLoader ? 'flex' : 'none'}
/>
<Suspense
fallback={
<TankSandboxLoader
id={id}
display={dummyLoader ? 'none' : 'flex'}
/>
}
>
2024-07-29 14:08:52 -05:00
<TankSandbox thicknessRange={thicknessRange} />
2024-07-10 13:31:21 -05:00
</Suspense>
2024-07-10 13:16:04 -05:00
</Box>
2024-05-03 17:35:59 -05:00
2024-07-29 14:08:52 -05:00
<Options thicknessRange={thicknessRange} />
2024-07-10 13:16:04 -05:00
</Box>
2024-07-09 20:53:00 -05:00
</Box>
2024-05-03 12:57:04 -05:00
</Flex>
</Flex>
);
}