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

139 lines
4.5 KiB
TypeScript
Raw Normal View History

2024-08-28 22:22:53 -05:00
import { Box, Flex, Heading, Text } from '@radix-ui/themes';
2024-08-25 19:11:30 -05:00
import { Suspense, use, useEffect, useMemo, useRef, useState } from 'react';
2024-08-28 21:16:25 -05:00
import { ThicknessRange } from '../../../../../../components/Armor/components/StaticArmor';
2024-06-29 12:12:10 -05:00
import { classIcons } from '../../../../../../components/ClassIcon';
2024-08-28 22:22:53 -05:00
import { NAVBAR_HEIGHT } from '../../../../../../components/Navbar/index.css';
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-08-28 22:22:53 -05:00
import { Var } from '../../../../../../core/blitzkit/var';
2024-05-04 17:02:03 -05:00
import { useFullScreen } from '../../../../../../hooks/useFullScreen';
2024-07-09 20:35:36 -05:00
import * as Duel from '../../../../../../stores/duel';
2024-07-10 13:31:21 -05:00
import { TankSandbox } from './TankSandbox';
import { TankSandboxLoader } from './TankSandboxLoader';
2024-08-28 22:22:53 -05:00
import { Options } from './components/Options';
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-08-25 19:11:30 -05:00
const canvas = useRef<HTMLCanvasElement>(null);
2024-05-04 17:02:03 -05:00
const isFullScreen = useFullScreen();
2024-08-28 22:22:53 -05:00
const protagonist = Duel.use((state) => state.protagonist.tank);
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 (
2024-09-01 17:00:02 -05:00
<Flex justify="center" style={{ backgroundColor: Var('color-surface') }}>
2024-08-28 22:22:53 -05:00
<Box
2024-09-01 17:00:02 -05:00
style={{
backgroundColor: isFullScreen
? Var('color-background')
: Var('color-surface'),
zIndex: isFullScreen ? 2 : undefined,
}}
height={
isFullScreen ? '100vh' : `calc(100vh - ${NAVBAR_HEIGHT}px - 8rem)`
}
maxHeight="40rem"
maxWidth="120rem"
flexGrow="1"
width={isFullScreen ? '100vw' : undefined}
position={isFullScreen ? 'fixed' : 'relative'}
top={isFullScreen ? '0' : undefined}
left={isFullScreen ? '0' : undefined}
2024-08-28 22:22:53 -05:00
>
2024-09-01 17:00:02 -05:00
<Flex
position="absolute"
justify={{ initial: 'center', md: 'start' }}
width="100%"
mt={{ initial: '6', md: '-8' }}
top={{ initial: '0', md: '50%' }}
left={{ initial: '-4', md: '0' }}
pl={{ initial: '0', md: '8' }}
>
<Flex direction="column" align={{ initial: 'center', md: 'start' }}>
<Heading
weight="bold"
size={{ initial: '8', xl: '9' }}
wrap="nowrap"
color={treeColor}
2024-08-28 22:22:53 -05:00
>
2024-09-01 17:00:02 -05:00
<Flex align="center" gap="3">
<Icon width="0.8em" height="0.8em" />
{tank.name}
</Flex>
</Heading>
2024-08-28 22:22:53 -05:00
2024-09-01 17:00:02 -05:00
<Text
color="gray"
size="3"
weight="light"
ml={{ initial: '0', md: '7', xl: '9' }}
>
BlitzKit Tankopedia
</Text>
</Flex>
</Flex>
<Box
position="absolute"
width="100%"
height="100%"
className="tank-sandbox-container"
>
<Box width="100%" height="100%" position="absolute">
<Box width="100%" height="100%">
<TankSandboxLoader
id={id}
display={dummyLoader ? 'flex' : 'none'}
/>
<Suspense
fallback={
<TankSandboxLoader
id={id}
display={dummyLoader ? 'none' : 'flex'}
/>
}
>
<TankSandbox ref={canvas} thicknessRange={thicknessRange} />
</Suspense>
</Box>
<Options canvas={canvas} thicknessRange={thicknessRange} />
</Box>
2024-08-28 22:22:53 -05:00
</Box>
</Box>
2024-09-01 17:00:02 -05:00
</Flex>
2024-05-03 12:57:04 -05:00
);
}