mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-12-05 07:43:49 +01:00
migrate mixer
This commit is contained in:
49 files changed
+659
-859
No files matched your search
@@ -1,5 +1,6 @@
|
||||
.content {
|
||||
position: relative;
|
||||
height: 100dvh;
|
||||
background-color: black;
|
||||
|
||||
flex: 1;
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
.wrapper {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.content {
|
||||
position: relative;
|
||||
flex-grow: 1;
|
||||
}
|
||||
|
||||
.scene {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
|
||||
background-color: black;
|
||||
}
|
||||
|
||||
.controls {
|
||||
position: absolute;
|
||||
bottom: var(--space-4);
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: var(--space-3);
|
||||
}
|
||||
|
||||
.row {
|
||||
display: flex;
|
||||
gap: var(--space-3);
|
||||
}
|
||||
|
||||
.modules {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--space-1);
|
||||
}
|
||||
@@ -1,214 +1,33 @@
|
||||
import {
|
||||
alias,
|
||||
romanize,
|
||||
} from "@blitzkit/core";
|
||||
import { literals } from "@blitzkit/i18n";
|
||||
import {
|
||||
GunDefinition,
|
||||
TankDefinition,
|
||||
TurretDefinition,
|
||||
} from "@blitzkit/protos";
|
||||
import { CaretRightIcon, CaretUpIcon, UpdateIcon } from "@radix-ui/react-icons";
|
||||
import {
|
||||
Box,
|
||||
Button,
|
||||
Dialog,
|
||||
Flex,
|
||||
IconButton,
|
||||
Popover,
|
||||
Skeleton,
|
||||
Text,
|
||||
type ButtonProps,
|
||||
} from "@radix-ui/themes";
|
||||
import { useRef, useState } from "react";
|
||||
import { api } from "../../../../api/dynamic";
|
||||
import { UpdateIcon } from "@radix-ui/react-icons";
|
||||
import { useRef } from "react";
|
||||
import { Button } from "../../../../components/Button";
|
||||
import { MixerModuleChooser } from "../../../../components/MixerModuleChooser";
|
||||
import { MixerModuleSeparator } from "../../../../components/MixerModuleSeparator";
|
||||
import { MixerScene } from "../../../../components/MixerScene";
|
||||
import { ModuleButton } from "../../../../components/ModuleButtons/ModuleButton";
|
||||
import { PageWrapper } from "../../../../components/PageWrapper";
|
||||
import { ScreenshotButton } from "../../../../components/ScreenshotButton";
|
||||
import { TankSearch } from "../../../../components/TankSearch";
|
||||
import { curateMixer } from "../../../../core/blitzkit/curateMixer";
|
||||
import {
|
||||
LocaleProvider,
|
||||
useLocale,
|
||||
type LocaleAcceptorProps,
|
||||
} from "../../../../hooks/useLocale";
|
||||
import { withErrorWrapper } from "../../../../hocs/withErrorWrapper";
|
||||
import { withLocale } from "../../../../hocs/withLocale";
|
||||
import { useStrings } from "../../../../hooks/useStrings";
|
||||
import { Mixer } from "../../../../stores/mixer";
|
||||
import { Tankopedia } from "../../../../stores/tankopedia";
|
||||
import type { MaybeSkeletonComponentProps } from "../../../../types/maybeSkeletonComponentProps";
|
||||
import styles from "./_index.module.css";
|
||||
|
||||
const modelDefinition = await api.models().then(({ models }) => models[1]);
|
||||
const tankDefinitions = await api.tanks();
|
||||
export const Page = withLocale(
|
||||
withErrorWrapper(({ skeleton }: MaybeSkeletonComponentProps) => {
|
||||
const initial = useRef(curateMixer());
|
||||
|
||||
export function Page({
|
||||
locale,
|
||||
skeleton,
|
||||
}: LocaleAcceptorProps & MaybeSkeletonComponentProps) {
|
||||
const initial = useRef(curateMixer());
|
||||
Mixer.useInitialization(initial.current);
|
||||
Tankopedia.useInitialization(initial.current.hull);
|
||||
|
||||
Mixer.useInitialization(initial.current);
|
||||
Tankopedia.useInitialization(modelDefinition);
|
||||
|
||||
return (
|
||||
<PageWrapper color="gray" p="0" maxWidth="unset">
|
||||
<LocaleProvider locale={locale}>
|
||||
return (
|
||||
<div className={styles.wrapper}>
|
||||
<Content skeleton={skeleton} />
|
||||
</LocaleProvider>
|
||||
</PageWrapper>
|
||||
);
|
||||
}
|
||||
|
||||
type ModuleButtonProps = Omit<ButtonProps, "onSelect"> &
|
||||
MaybeSkeletonComponentProps & {
|
||||
tank: number;
|
||||
onSelect: (
|
||||
tank: TankDefinition,
|
||||
turret?: TurretDefinition,
|
||||
gun?: GunDefinition,
|
||||
) => void;
|
||||
turret?: number;
|
||||
gun?: number;
|
||||
};
|
||||
|
||||
function ModuleChooser({
|
||||
skeleton,
|
||||
tank,
|
||||
onSelect,
|
||||
turret,
|
||||
gun,
|
||||
...props
|
||||
}: ModuleButtonProps) {
|
||||
const { strings } = useLocale();
|
||||
const [open, setOpen] = useState(false);
|
||||
const tankDefinition = tankDefinitions.tanks[tank];
|
||||
const turretDefinition = tankDefinition.turrets.find((t) => t.id === turret);
|
||||
const gunDefinition = turretDefinition?.guns.find((g) => g.id === gun);
|
||||
const subSelector =
|
||||
turret !== undefined &&
|
||||
(tankDefinition.turrets.length > 1 ||
|
||||
(gun !== undefined && turretDefinition!.guns.length > 1));
|
||||
|
||||
return (
|
||||
<Flex>
|
||||
<Dialog.Root open={open} onOpenChange={setOpen}>
|
||||
<Dialog.Trigger>
|
||||
<Button
|
||||
variant="surface"
|
||||
size={{ initial: "2", xs: "3", md: "4" }}
|
||||
style={{
|
||||
overflow: "clip",
|
||||
borderTopRightRadius: subSelector ? 0 : undefined,
|
||||
borderBottomRightRadius: subSelector ? 0 : undefined,
|
||||
}}
|
||||
{...props}
|
||||
>
|
||||
{skeleton ? (
|
||||
<Skeleton width="4em" height="2em" />
|
||||
) : (
|
||||
<img
|
||||
style={{
|
||||
width: "4em",
|
||||
height: "4em",
|
||||
objectFit: "contain",
|
||||
}}
|
||||
src={alias("api", `/tanks/${tank}/icons/big.webp`)}
|
||||
/>
|
||||
)}
|
||||
</Button>
|
||||
</Dialog.Trigger>
|
||||
|
||||
<Dialog.Content maxHeight={DIALOG_MAX_HEIGHT}>
|
||||
<Dialog.Title>
|
||||
{strings.website.common.tank_search.select_dialog_title}
|
||||
</Dialog.Title>
|
||||
|
||||
<TankSearch
|
||||
compact
|
||||
onSelect={(tank) => {
|
||||
onSelect?.(tank);
|
||||
setOpen(false);
|
||||
}}
|
||||
/>
|
||||
</Dialog.Content>
|
||||
</Dialog.Root>
|
||||
|
||||
{subSelector && (
|
||||
<Popover.Root>
|
||||
<Popover.Trigger>
|
||||
<IconButton
|
||||
variant="surface"
|
||||
size={{ initial: "2", xs: "3", md: "4" }}
|
||||
style={{
|
||||
overflow: "clip",
|
||||
borderTopLeftRadius: 0,
|
||||
borderBottomLeftRadius: 0,
|
||||
marginLeft: -1,
|
||||
}}
|
||||
{...props}
|
||||
>
|
||||
<CaretUpIcon />
|
||||
</IconButton>
|
||||
</Popover.Trigger>
|
||||
|
||||
<Popover.Content>
|
||||
<Flex direction="column" gap="2">
|
||||
{tankDefinition.turrets.length > 1 && (
|
||||
<Flex gap="2">
|
||||
{tankDefinition.turrets.map((turret) => (
|
||||
<ModuleButton
|
||||
variant={
|
||||
turret.id === turretDefinition?.id ? "solid" : undefined
|
||||
}
|
||||
key={turret.id}
|
||||
module="turret"
|
||||
discriminator={romanize(turret.tier)}
|
||||
onClick={() => {
|
||||
onSelect?.(tankDefinition, turret);
|
||||
}}
|
||||
/>
|
||||
))}
|
||||
</Flex>
|
||||
)}
|
||||
|
||||
{turretDefinition && turretDefinition.guns.length > 1 && (
|
||||
<Flex gap="2">
|
||||
{turretDefinition.guns.map((gun) => (
|
||||
<ModuleButton
|
||||
variant={
|
||||
gun.id === gunDefinition?.id ? "solid" : undefined
|
||||
}
|
||||
key={gun.id}
|
||||
module="gun"
|
||||
discriminator={romanize(gun.tier)}
|
||||
secondaryDiscriminator={
|
||||
<Text style={{ fontSize: "0.75em" }}>
|
||||
{literals(strings.common.units.mm, {
|
||||
value: gun.shells[0].caliber.toFixed(0),
|
||||
})}
|
||||
</Text>
|
||||
}
|
||||
onClick={() => {
|
||||
onSelect?.(tankDefinition, turretDefinition, gun);
|
||||
}}
|
||||
/>
|
||||
))}
|
||||
</Flex>
|
||||
)}
|
||||
</Flex>
|
||||
</Popover.Content>
|
||||
</Popover.Root>
|
||||
)}
|
||||
</Flex>
|
||||
);
|
||||
}
|
||||
|
||||
function ModuleSeparator() {
|
||||
return (
|
||||
<Text size={{ initial: "3", xs: "5" }} color="gray" trim="end">
|
||||
<CaretRightIcon width="1em" height="1em" />
|
||||
</Text>
|
||||
);
|
||||
}
|
||||
</div>
|
||||
);
|
||||
})
|
||||
);
|
||||
|
||||
function Content({ skeleton }: MaybeSkeletonComponentProps) {
|
||||
const hullTankId = Mixer.use((state) => state.hull);
|
||||
@@ -218,34 +37,25 @@ function Content({ skeleton }: MaybeSkeletonComponentProps) {
|
||||
const gunTurretId = Mixer.use((state) => state.gun.turret.id);
|
||||
const gunGunId = Mixer.use((state) => state.gun.gun.id);
|
||||
const canvas = useRef<HTMLCanvasElement>(null!);
|
||||
const { strings } = useLocale();
|
||||
const strings = useStrings();
|
||||
|
||||
return (
|
||||
<Box flexGrow="1" position="relative">
|
||||
<Box position="absolute" width="100%" height="100%" top="0" left="0">
|
||||
<div className={styles.content}>
|
||||
<div className={styles.scene}>
|
||||
{!skeleton && <MixerScene ref={canvas} />}
|
||||
</Box>
|
||||
</div>
|
||||
|
||||
<Flex
|
||||
align="center"
|
||||
direction="column"
|
||||
position="absolute"
|
||||
bottom="4"
|
||||
left="50%"
|
||||
style={{ transform: "translateX(-50%)" }}
|
||||
gap="4"
|
||||
>
|
||||
<Flex gap="2">
|
||||
<div className={styles.controls}>
|
||||
<div className={styles.row}>
|
||||
<ScreenshotButton
|
||||
name={hullTankId.slug}
|
||||
canvas={canvas}
|
||||
highContrast
|
||||
variant="surface"
|
||||
>
|
||||
{strings.website.tools.mixer.screenshot}
|
||||
{strings.mixer.screenshot}
|
||||
</ScreenshotButton>
|
||||
|
||||
<Button
|
||||
highContrast
|
||||
variant="surface"
|
||||
onClick={() => {
|
||||
const mixed = curateMixer();
|
||||
@@ -256,12 +66,12 @@ function Content({ skeleton }: MaybeSkeletonComponentProps) {
|
||||
}}
|
||||
>
|
||||
<UpdateIcon />
|
||||
{strings.website.tools.mixer.randomize}
|
||||
{strings.mixer.randomize}
|
||||
</Button>
|
||||
</Flex>
|
||||
</div>
|
||||
|
||||
<Flex gap={{ initial: "1", xs: "2" }} align="center">
|
||||
<ModuleChooser
|
||||
<div className={styles.modules}>
|
||||
<MixerModuleChooser
|
||||
skeleton={skeleton}
|
||||
tank={hullTankId.id}
|
||||
onSelect={(tank) => {
|
||||
@@ -270,8 +80,8 @@ function Content({ skeleton }: MaybeSkeletonComponentProps) {
|
||||
});
|
||||
}}
|
||||
/>
|
||||
<ModuleSeparator />
|
||||
<ModuleChooser
|
||||
<MixerModuleSeparator />
|
||||
<MixerModuleChooser
|
||||
skeleton={skeleton}
|
||||
tank={turretTankId}
|
||||
turret={turretTurretId}
|
||||
@@ -284,8 +94,8 @@ function Content({ skeleton }: MaybeSkeletonComponentProps) {
|
||||
});
|
||||
}}
|
||||
/>
|
||||
<ModuleSeparator />
|
||||
<ModuleChooser
|
||||
<MixerModuleSeparator />
|
||||
<MixerModuleChooser
|
||||
skeleton={skeleton}
|
||||
tank={gunTankId}
|
||||
turret={gunTurretId}
|
||||
@@ -303,8 +113,8 @@ function Content({ skeleton }: MaybeSkeletonComponentProps) {
|
||||
});
|
||||
}}
|
||||
/>
|
||||
</Flex>
|
||||
</Flex>
|
||||
</Box>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
+1
-1
@@ -11,7 +11,7 @@ const { locale } = Astro.props;
|
||||
|
||||
<ToolOpenGraph {locale} tool={tools.mixer} />
|
||||
|
||||
<BaseLayout {locale} integrated>
|
||||
<BaseLayout accent="gray" {locale} solidNavbar>
|
||||
<Page {locale} client:only="react">
|
||||
<Page {locale} skeleton slot="fallback" />
|
||||
</Page>
|
||||
Reference in new issue
Block a user