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

214 lines
5.4 KiB
TypeScript
Raw Normal View History

2024-05-03 22:16:32 -05:00
import { ChevronRightIcon } from '@radix-ui/react-icons';
2024-05-04 13:46:57 -05:00
import { ChevronDownIcon, Flex, Text } from '@radix-ui/themes';
2024-05-03 22:16:32 -05:00
import Link from 'next/link';
2024-05-04 11:00:54 -05:00
import { ComponentProps, use } from 'react';
2024-05-03 22:16:32 -05:00
import PageWrapper from '../../../../../../components/PageWrapper';
import { asset } from '../../../../../../core/blitzkit/asset';
import { tankDefinitions } from '../../../../../../core/blitzkit/tankDefinitions';
import { TIER_ROMAN_NUMERALS } from '../../../../../../core/blitzkit/tankDefinitions/constants';
import { useDuel } from '../../../../../../stores/duel';
2024-05-04 13:16:33 -05:00
export function TreeArrow({
style,
down = false,
...props
}: ComponentProps<typeof Text> & { down?: boolean }) {
const Icon = down ? ChevronDownIcon : ChevronRightIcon;
2024-05-03 22:16:32 -05:00
return (
<Text
color="gray"
style={{
flex: 1,
2024-05-04 11:00:54 -05:00
...style,
2024-05-03 22:16:32 -05:00
}}
2024-05-04 11:00:54 -05:00
{...props}
2024-05-03 22:16:32 -05:00
>
<Flex
style={{
backgroundColor: 'currentcolor',
2024-05-04 13:16:33 -05:00
height: down ? '100%' : 1,
width: down ? 1 : '100%',
2024-05-03 22:16:32 -05:00
position: 'relative',
}}
2024-05-04 13:16:33 -05:00
direction={down ? 'column' : 'row'}
2024-05-03 22:16:32 -05:00
justify="end"
>
2024-05-04 13:16:33 -05:00
<Icon
2024-05-03 22:16:32 -05:00
style={{
position: 'absolute',
2024-05-04 13:16:33 -05:00
right: down ? undefined : 0,
top: down ? undefined : '50%',
bottom: down ? 0 : undefined,
left: down ? '50%' : undefined,
transform: down ? 'translate(-50%, 2px)' : 'translate(5px, -50%)',
2024-05-03 22:16:32 -05:00
}}
/>
</Flex>
</Text>
);
}
export function TechTreeSection() {
const awaitedTankDefinitions = use(tankDefinitions);
const tank = useDuel((state) => state.protagonist!.tank);
if (tank.treeType !== 'researchable') return null;
function Card({ id }: { id: number }) {
const ancestor = awaitedTankDefinitions[id];
return (
<Link
href={`/tools/tankopedia/${id}`}
key={id}
style={{
textDecoration: 'none',
color: 'inherit',
}}
>
<Flex direction="column" align="center">
<img
2024-05-04 16:28:12 -05:00
alt={ancestor.name}
2024-05-03 22:16:32 -05:00
src={asset(`icons/tanks/big/${id}.webp`)}
width={64}
height={64}
style={{
objectFit: 'contain',
}}
/>
<Flex direction="column" align="center">
<Flex gap="2" align="center">
<Text color="gray" size="1">
{TIER_ROMAN_NUMERALS[ancestor.tier]}
</Text>
<Text>{ancestor.name}</Text>
</Flex>
<Flex gap="2" align="center">
<Flex gap="1" align="center">
<img
2024-05-04 16:28:12 -05:00
alt="XP"
2024-05-03 22:16:32 -05:00
src={asset('icons/currencies/xp.webp')}
width={16}
height={16}
style={{
objectFit: 'contain',
}}
/>
<Text color="gray" size="1">
2024-05-03 23:01:53 -05:00
{ancestor.xp?.toLocaleString()}
2024-05-03 22:16:32 -05:00
</Text>
</Flex>
<Flex gap="1" align="center">
<img
2024-05-04 16:28:12 -05:00
alt="Silver"
2024-05-03 22:16:32 -05:00
src={asset('icons/currencies/silver.webp')}
width={16}
height={16}
style={{
objectFit: 'contain',
}}
/>
<Text color="gray" size="1">
2024-05-03 23:01:53 -05:00
{ancestor.price.value?.toLocaleString()}
2024-05-03 22:16:32 -05:00
</Text>
</Flex>
</Flex>
</Flex>
</Flex>
</Link>
);
}
return (
2024-05-04 13:46:57 -05:00
<PageWrapper
style={{
position: 'relative',
2024-05-04 16:19:27 -05:00
}}
containerProps={{
style: {
overflow: 'hidden',
marginTop: 16,
},
2024-05-04 13:46:57 -05:00
}}
size={tank.ancestors && tank.successors ? 880 : 480}
gap="0"
highlight
>
<img
2024-05-04 16:28:12 -05:00
alt={tank.nation}
2024-05-04 13:46:57 -05:00
src={asset(`flags/scratched/${tank.nation}.webp`)}
style={{
position: 'absolute',
top: '50%',
left: '50%',
height: '200%',
transform: 'translate(-40%, -48%)',
backgroundRepeat: 'no-repeat',
opacity: 1 / 4,
}}
/>
2024-05-03 22:16:32 -05:00
2024-05-04 13:46:57 -05:00
{/* <Flex justify="center">
<Heading>Tech tree</Heading>
</Flex> */}
<Flex
align="center"
gap="6"
style={{
zIndex: 1,
}}
>
2024-05-03 22:16:32 -05:00
{tank.ancestors && (
<>
2024-05-03 22:54:53 -05:00
<Flex
wrap="wrap"
direction="column"
align="center"
justify="center"
style={{
maxHeight: 360,
}}
gap="4"
>
2024-05-03 22:16:32 -05:00
{tank.ancestors.map((id) => (
<Card key={id} id={id} />
))}
</Flex>
2024-05-04 11:00:54 -05:00
<TreeArrow />
2024-05-03 22:16:32 -05:00
</>
)}
2024-05-04 13:46:57 -05:00
<Flex direction="column">
2024-05-03 22:16:32 -05:00
<Card id={tank.id} />
</Flex>
{tank.successors && (
<>
2024-05-04 11:00:54 -05:00
<TreeArrow />
2024-05-03 22:16:32 -05:00
2024-05-03 22:54:53 -05:00
<Flex
wrap="wrap"
direction="column"
align="center"
justify="center"
style={{
maxHeight: 360,
}}
gap="4"
>
2024-05-03 22:16:32 -05:00
{tank.successors.map((id) => (
<Card key={id} id={id} />
))}
</Flex>
</>
)}
</Flex>
</PageWrapper>
);
}