Files
blitzkit/packages/website/src/components/TanksEmbed.tsx
T

149 lines
4.5 KiB
TypeScript
Raw Normal View History

2024-09-07 21:45:00 -05:00
import {
2024-11-08 10:32:44 -06:00
formatCompositeStat,
2024-10-05 20:55:44 -05:00
TankClass,
2024-09-07 21:45:00 -05:00
TankDefinition,
2024-10-05 20:55:44 -05:00
TankType,
2024-11-08 10:32:44 -06:00
type CompositeStats,
2024-10-05 20:55:44 -05:00
type CompositeStatsKey,
2026-03-31 14:11:45 -05:00
} from "@blitzkit/core";
import strings from "@blitzkit/i18n/strings/en.json";
import { amberDark, blueDark } from "@radix-ui/colors";
import { Flex, Text, type FlexProps } from "@radix-ui/themes";
import { times } from "lodash-es";
import type { ReactNode } from "react";
import { breakdownConfig } from "../constants/embeds";
import { toRadiusVar } from "../core/radix/utils";
import { useLocale } from "../hooks/useLocale";
import { useEmbedStateCurry } from "../stores/embedState/utilities";
import { ClassHeavy } from "./ClassIcon/components/ClassHeavy";
import { ClassLight } from "./ClassIcon/components/ClassLight";
import { ClassMedium } from "./ClassIcon/components/ClassMedium";
import { ClassTankDestroyer } from "./ClassIcon/components/ClassTankDestroyer";
2024-08-05 12:52:40 -05:00
2024-11-04 10:36:43 -06:00
type BreakdownEmbedWrapperProps = FlexProps & {
2024-08-05 12:52:40 -05:00
children: ReactNode;
2024-11-04 10:36:43 -06:00
};
2024-08-05 12:52:40 -05:00
2024-08-07 12:03:45 -05:00
export function BreakdownEmbedWrapper({
children,
2024-11-04 10:36:43 -06:00
...props
2024-08-07 12:03:45 -05:00
}: BreakdownEmbedWrapperProps) {
2024-10-28 10:30:53 -05:00
const { useEmbedState } = useEmbedStateCurry<typeof breakdownConfig>();
2024-08-08 14:18:22 -05:00
2024-08-05 12:52:40 -05:00
return (
2024-11-04 10:36:43 -06:00
<Flex
direction="column"
2026-03-31 14:11:45 -05:00
gap={useEmbedState("listGap")}
2024-11-04 10:36:43 -06:00
height="100%"
{...props}
>
2024-08-05 12:52:40 -05:00
{children}
</Flex>
);
}
2024-08-07 12:03:45 -05:00
interface BreakdownEmbedCardProps {
2024-11-04 10:38:48 -06:00
tank: TankDefinition | null | undefined;
2024-11-08 10:32:44 -06:00
composite: CompositeStats;
2024-08-05 12:52:40 -05:00
}
2024-11-08 10:32:44 -06:00
export function BreakdownEmbedCard({
tank,
composite,
}: BreakdownEmbedCardProps) {
2024-10-28 10:30:53 -05:00
const { useEmbedState, useRichText } =
2024-08-08 14:18:22 -05:00
useEmbedStateCurry<typeof breakdownConfig>();
2025-01-14 19:22:41 -06:00
const { unwrap } = useLocale();
2024-08-08 14:18:22 -05:00
2024-08-05 12:52:40 -05:00
return (
<Flex
2024-08-11 13:05:11 -05:00
flexShrink="0"
2024-08-05 12:52:40 -05:00
direction="column"
style={{
2026-03-31 14:11:45 -05:00
borderRadius: toRadiusVar(useEmbedState("cardRadius")),
overflow: "hidden",
backgroundColor: useEmbedState("cardBodyBackgroundColor"),
2024-08-05 12:52:40 -05:00
}}
>
<Flex
justify="center"
style={{
2026-03-31 14:11:45 -05:00
backgroundColor: useEmbedState("cardHeaderBackgroundColor"),
2024-08-05 12:52:40 -05:00
}}
2026-03-31 14:11:45 -05:00
p={useEmbedState("cardHeaderPadding")}
2024-08-05 12:52:40 -05:00
>
2024-08-06 13:33:39 -05:00
<Text
2024-08-08 14:22:04 -05:00
{...{
2026-03-31 14:11:45 -05:00
...useRichText("cardTitle"),
2024-08-08 14:22:04 -05:00
style:
tank === null
? undefined
2024-11-04 10:38:48 -06:00
: tank === undefined ||
2026-03-31 14:11:45 -05:00
tank.type === TankType.TANK_TYPE_RESEARCHABLE ||
!useEmbedState("cardTitleTypeColor")
2024-09-08 21:52:12 -05:00
? undefined
: {
color:
2026-03-31 14:11:45 -05:00
tank.type === TankType.TANK_TYPE_PREMIUM
2024-09-08 21:52:12 -05:00
? amberDark.amber11
: blueDark.blue11,
},
2024-08-08 14:18:22 -05:00
}}
2024-08-06 13:33:39 -05:00
>
<Flex align="center" gap="1">
2026-03-31 14:11:45 -05:00
{useEmbedState("cardTitleClassIcon") &&
2024-11-04 10:38:48 -06:00
tank !== null &&
tank !== undefined && (
<>
2026-03-31 14:11:45 -05:00
{tank.class === TankClass.TANK_CLASS_LIGHT && (
2024-11-04 10:38:48 -06:00
<ClassLight width="1em" height="1em" />
)}
2026-03-31 14:11:45 -05:00
{tank.class === TankClass.TANK_CLASS_MEDIUM && (
2024-11-04 10:38:48 -06:00
<ClassMedium width="1em" height="1em" />
)}
2026-03-31 14:11:45 -05:00
{tank.class === TankClass.TANK_CLASS_HEAVY && (
2024-11-04 10:38:48 -06:00
<ClassHeavy width="1em" height="1em" />
)}
2026-03-31 14:11:45 -05:00
{tank.class === TankClass.TANK_CLASS_TANK_DESTROYER && (
2024-11-04 10:38:48 -06:00
<ClassTankDestroyer width="1em" height="1em" />
)}
</>
2026-03-31 14:11:45 -05:00
)}{" "}
2024-11-04 10:38:48 -06:00
{tank === null
2026-03-31 14:11:45 -05:00
? "Total"
2024-11-04 10:38:48 -06:00
: tank === undefined
? `Unknown tank`
2026-03-31 14:11:45 -05:00
: unwrap(tank.name!)}
2024-08-06 13:33:39 -05:00
</Flex>
</Text>
2024-08-05 12:52:40 -05:00
</Flex>
2024-08-05 14:25:12 -05:00
2026-03-31 14:11:45 -05:00
<Flex p={useEmbedState("cardBodyPadding")}>
2024-08-05 14:25:12 -05:00
{times(4, (index) => {
const column = (index + 1) as 1 | 2 | 3 | 4;
2024-11-08 10:32:44 -06:00
const statKey = useEmbedState(`column${column}`) as CompositeStatsKey;
2024-10-28 10:30:53 -05:00
const customLabel = useEmbedState(`column${column}CustomLabel`);
2024-08-05 14:25:12 -05:00
return (
<Flex
2024-10-26 14:34:56 -05:00
key={column}
2024-08-05 14:25:12 -05:00
direction="column"
align="center"
2026-03-31 14:11:45 -05:00
gap={useEmbedState("columnGap")}
2024-08-05 14:25:12 -05:00
flexGrow="1"
>
2026-03-31 14:11:45 -05:00
<Text {...useRichText("columnValue")}>
2024-11-08 10:32:44 -06:00
{formatCompositeStat(composite[statKey], statKey, composite)}
2024-08-05 14:25:12 -05:00
</Text>
2026-03-31 14:11:45 -05:00
<Text {...useRichText("columnLabel")}>
2024-08-10 13:29:10 -05:00
{customLabel.length === 0
2024-11-08 10:32:44 -06:00
? strings.common.composite_stats[statKey]
2024-08-10 13:29:10 -05:00
: customLabel}
2024-08-05 14:25:12 -05:00
</Text>
</Flex>
);
})}
</Flex>
2024-08-05 12:52:40 -05:00
</Flex>
);
}