import { TankType } from '@blitzkit/core'; import { Box, Flex, Heading, Text } from '@radix-ui/themes'; import { times } from 'lodash-es'; import { Suspense, useEffect, useMemo, useRef } from 'react'; import { NAVBAR_HEIGHT } from '../../../constants/navbar'; import { awaitableTankDefinitions } from '../../../core/awaitables/tankDefinitions'; import { useFullScreen } from '../../../hooks/useFullScreen'; import { useLocale } from '../../../hooks/useLocale'; import { Duel } from '../../../stores/duel'; import { TankopediaEphemeral } from '../../../stores/tankopediaEphemeral'; import type { MaybeSkeletonComponentProps } from '../../../types/maybeSkeletonComponentProps'; import type { ThicknessRange } from '../../Armor/components/StaticArmor'; import { classIcons } from '../../ClassIcon'; import { Options } from './components/Options'; import { TankSandbox } from './components/TankSandbox'; import { TankSandboxLoader } from './components/TankSandboxLoader'; const tankDefinitions = await awaitableTankDefinitions; export function HeroSection({ skeleton }: MaybeSkeletonComponentProps) { const disturbed = TankopediaEphemeral.use((state) => state.disturbed); const { unwrap } = useLocale(); const canvas = useRef(null); const isFullScreen = useFullScreen(); const protagonist = Duel.use((state) => state.protagonist.tank); const Icon = classIcons[protagonist.class]; const treeColor = protagonist.type === TankType.COLLECTOR ? 'blue' : protagonist.type === TankType.PREMIUM ? 'amber' : undefined; const thicknessRange = useMemo(() => { const entries = Object.values(tankDefinitions.tanks); const filtered = entries.filter( (thisTank) => thisTank.tier === protagonist.tier, ); const value = (filtered.reduce((accumulator, thisTank) => { return ( accumulator + thisTank.turrets.at(-1)!.guns.at(-1)!.gun_type!.value.base.shells[0] .penetration.near ); }, 0) / filtered.length) * (3 / 4); return { value } satisfies ThicknessRange; }, [protagonist]); const duelStore = Duel.useStore(); const mutateDuel = Duel.useMutation(); const mutateTankopediaEphemeral = TankopediaEphemeral.useMutation(); useEffect(() => { function handleKeyDown(event: KeyboardEvent) { const { shells } = duelStore.getState().antagonist.gun.gun_type!.value.base; times(3, (index) => { if (event.key === `${index + 1}` && shells.length > index) { mutateDuel((draft) => { draft.antagonist.shell = shells[index]; }); mutateTankopediaEphemeral((draft) => { draft.customShell = undefined; }); } }); } window.addEventListener('keydown', handleKeyDown); return () => window.removeEventListener('keydown', handleKeyDown); }, []); return ( {unwrap(protagonist.name)} BlitzKit Tankopedia {skeleton && } }> ); }