feat: module arrows

This commit is contained in:
TrèsAbhi committed 2024-05-04 13:16:33 -05:00
1 parent d0743b54e0
commit 42076c1317
2 files changed
+117 -124

No files matched your search

@@ -1,4 +1,10 @@
import { Flex, Heading, IconButton, Text } from '@radix-ui/themes'; import {
ChevronDownIcon,
Flex,
Heading,
IconButton,
Text,
} from '@radix-ui/themes';
import Link from 'next/link'; import Link from 'next/link';
import { use } from 'react'; import { use } from 'react';
import PageWrapper from '../../../../../../components/PageWrapper'; import PageWrapper from '../../../../../../components/PageWrapper';
@@ -14,7 +20,6 @@ import {
import { TIER_ROMAN_NUMERALS } from '../../../../../../core/blitzkit/tankDefinitions/constants'; import { TIER_ROMAN_NUMERALS } from '../../../../../../core/blitzkit/tankDefinitions/constants';
import { tankIcon } from '../../../../../../core/blitzkit/tankIcon'; import { tankIcon } from '../../../../../../core/blitzkit/tankIcon';
import { mutateDuel, useDuel } from '../../../../../../stores/duel'; import { mutateDuel, useDuel } from '../../../../../../stores/duel';
import { TreeArrow } from './TechTreeSection';
function ModuleButton({ function ModuleButton({
tier, tier,
@@ -162,12 +167,11 @@ export function ModulesSection() {
function tree(type: ModuleType, unlocks: Unlock[]) { function tree(type: ModuleType, unlocks: Unlock[]) {
return ( return (
<Flex direction="column" gap="2"> <Flex gap="2">
{unlocks.map((unlock) => { {unlocks.map((unlock, index) => {
const direction = index < Math.floor(unlocks.length / 2) ? -1 : 1;
let module: ModuleDefinition | TankDefinition | undefined = undefined; let module: ModuleDefinition | TankDefinition | undefined = undefined;
console.log(unlock.type);
if (unlock.type === 'chassis') { if (unlock.type === 'chassis') {
module = tank.tracks.find((track) => track.id === unlock.id)!; module = tank.tracks.find((track) => track.id === unlock.id)!;
} else if (unlock.type === 'engine') { } else if (unlock.type === 'engine') {
@@ -187,7 +191,53 @@ export function ModulesSection() {
if (module === undefined) return null; if (module === undefined) return null;
return ( return (
<Flex align="center" gap="2"> <Flex
align="center"
direction="column"
gap="2"
style={{
position: 'relative',
}}
>
{unlock.cost.value > 0 && (
<>
{unlocks.length > 1 && (
<div
style={{
backgroundColor: 'currentcolor',
width: 'calc(50% + 4px)',
height: 1,
position: 'absolute',
right: direction < 0 ? 0 : undefined,
left: direction > 0 ? 0 : undefined,
transform: `translateX(${direction * -4}px)`,
}}
/>
)}
<Flex
direction="column"
align="center"
style={{
marginBottom: -7,
}}
>
<div
style={{
backgroundColor: 'currentcolor',
width: 1,
height: 8,
}}
/>
<ChevronDownIcon
style={{
transform: 'translateY(-7px)',
}}
/>
</Flex>
</>
)}
<ModuleButton <ModuleButton
unlock={unlock} unlock={unlock}
tier={module.tier} tier={module.tier}
@@ -205,12 +255,20 @@ export function ModulesSection() {
onClick={() => setByUnlock(unlock)} onClick={() => setByUnlock(unlock)}
/> />
{(module as ModuleDefinition).unlocks && ( {(module as ModuleDefinition).unlocks &&
<> (module as ModuleDefinition).unlocks!.length > 1 && (
<TreeArrow style={{ width: 32 }} /> <div
{tree(type, (module as ModuleDefinition).unlocks!)} style={{
</> backgroundColor: 'currentcolor',
)} width: 1,
height: 8,
marginBottom: -8,
}}
/>
)}
{(module as ModuleDefinition).unlocks &&
tree(type, (module as ModuleDefinition).unlocks!)}
</Flex> </Flex>
); );
})} })}
@@ -222,110 +280,35 @@ export function ModulesSection() {
<PageWrapper> <PageWrapper>
<Heading>Modules</Heading> <Heading>Modules</Heading>
<Flex direction="column" gap="2"> <Flex gap="2">
<Flex align="center" gap="2"> {tree('turret', [
<ModuleButton {
unlock={{ cost: { type: 'xp', value: 0 },
type: 'turret', id: turret0.id,
id: turret0.id, type: 'turret',
cost: { type: 'xp', value: 0 }, },
}} ])}
tier={turret0.tier} {tree('gun', [
selected={turret0.id === turret.id} {
onClick={() => cost: { type: 'xp', value: 0 },
setByUnlock({ id: gun0.id,
id: turret0.id, type: 'gun',
type: 'turret', },
cost: { type: 'xp', value: 0 }, ])}
}) {tree('engine', [
} {
/> cost: { type: 'xp', value: 0 },
id: engine0.id,
{turret0.unlocks && ( type: 'engine',
<> },
<TreeArrow style={{ width: 32, flex: undefined }} /> ])}
{tree('turret', turret0.unlocks)} {tree('chassis', [
</> {
)} cost: { type: 'xp', value: 0 },
</Flex> id: track0.id,
type: 'chassis',
<Flex align="center" gap="2"> },
<ModuleButton ])}
unlock={{
type: 'gun',
id: gun0.id,
cost: { type: 'xp', value: 0 },
}}
tier={gun0.tier}
selected={gun0.id === gun.id}
onClick={() =>
setByUnlock({
id: gun0.id,
type: 'gun',
cost: { type: 'xp', value: 0 },
})
}
/>
{gun0.unlocks && (
<>
<TreeArrow style={{ width: 32, flex: undefined }} />
{tree('gun', gun0.unlocks)}
</>
)}
</Flex>
<Flex align="center" gap="2">
<ModuleButton
unlock={{
type: 'engine',
id: engine0.id,
cost: { type: 'xp', value: 0 },
}}
tier={engine0.tier}
selected={engine0.id === engine.id}
onClick={() =>
setByUnlock({
id: engine0.id,
type: 'engine',
cost: { type: 'xp', value: 0 },
})
}
/>
{engine0.unlocks && (
<>
<TreeArrow style={{ width: 32, flex: undefined }} />
{tree('engine', engine0.unlocks)}
</>
)}
</Flex>
<Flex align="center" gap="2">
<ModuleButton
unlock={{
type: 'chassis',
id: track0.id,
cost: { type: 'xp', value: 0 },
}}
tier={track0.tier}
selected={track0.id === track.id}
onClick={() =>
setByUnlock({
id: track0.id,
type: 'chassis',
cost: { type: 'xp', value: 0 },
})
}
/>
{track0.unlocks && (
<>
<TreeArrow style={{ width: 32, flex: undefined }} />
{tree('chassis', track0.unlocks)}
</>
)}
</Flex>
</Flex> </Flex>
</PageWrapper> </PageWrapper>
); );
@@ -1,5 +1,5 @@
import { ChevronRightIcon } from '@radix-ui/react-icons'; import { ChevronRightIcon } from '@radix-ui/react-icons';
import { Flex, Heading, Text } from '@radix-ui/themes'; import { ChevronDownIcon, Flex, Heading, Text } from '@radix-ui/themes';
import Link from 'next/link'; import Link from 'next/link';
import { ComponentProps, use } from 'react'; import { ComponentProps, use } from 'react';
import PageWrapper from '../../../../../../components/PageWrapper'; import PageWrapper from '../../../../../../components/PageWrapper';
@@ -8,7 +8,13 @@ import { tankDefinitions } from '../../../../../../core/blitzkit/tankDefinitions
import { TIER_ROMAN_NUMERALS } from '../../../../../../core/blitzkit/tankDefinitions/constants'; import { TIER_ROMAN_NUMERALS } from '../../../../../../core/blitzkit/tankDefinitions/constants';
import { useDuel } from '../../../../../../stores/duel'; import { useDuel } from '../../../../../../stores/duel';
export function TreeArrow({ style, ...props }: ComponentProps<typeof Text>) { export function TreeArrow({
style,
down = false,
...props
}: ComponentProps<typeof Text> & { down?: boolean }) {
const Icon = down ? ChevronDownIcon : ChevronRightIcon;
return ( return (
<Text <Text
color="gray" color="gray"
@@ -21,17 +27,21 @@ export function TreeArrow({ style, ...props }: ComponentProps<typeof Text>) {
<Flex <Flex
style={{ style={{
backgroundColor: 'currentcolor', backgroundColor: 'currentcolor',
height: 1, height: down ? '100%' : 1,
width: down ? 1 : '100%',
position: 'relative', position: 'relative',
}} }}
direction={down ? 'column' : 'row'}
justify="end" justify="end"
> >
<ChevronRightIcon <Icon
style={{ style={{
position: 'absolute', position: 'absolute',
right: 0, right: down ? undefined : 0,
top: '50%', top: down ? undefined : '50%',
transform: 'translate(5px, -50%)', bottom: down ? 0 : undefined,
left: down ? '50%' : undefined,
transform: down ? 'translate(-50%, 2px)' : 'translate(5px, -50%)',
}} }}
/> />
</Flex> </Flex>