antaognsist sleector

This commit is contained in:
tresabhi committed 2026-11-28 17:24:37 -06:00
1 parent 09cc303664
commit 80002e8c26
14 files changed
+231 -143

No files matched your search

+1
View File
@@ -1,5 +1,6 @@
import { environmentConfig } from "@blitzkit/core";
// TODO: remove the need for a `/ in the front of all paths
export function alias(alias: string, path: string) {
const environment = environmentConfig();
@@ -1,5 +1,6 @@
import type { TankDefinition } from "@blitzkit/protos";
import { PlusIcon, TrashIcon } from "@radix-ui/react-icons";
import { useMemo, useState } from "react";
import { useCallback, useMemo } from "react";
import { tankToCompareMember } from "../../core/blitzkit/tankToCompareMember";
import { withLocale } from "../../hocs/withLocale";
import { useStrings } from "../../hooks/useStrings";
@@ -11,9 +12,8 @@ import {
import { resolveTankModules } from "../../tankopedia/resolveTankModules";
import { Button } from "../Button";
import { Checkbox } from "../Checkbox";
import { Dialog } from "../Dialog";
import { SegmentedControl } from "../SegmentedControl";
import { TankSearchResults } from "../TankSearchResults";
import { TankSearchDialog } from "../TankSearchDialog";
import styles from "./index.module.css";
export const CompareControls = withLocale(Content);
@@ -22,7 +22,20 @@ function Content() {
const strings = useStrings();
const deltaMode = ComparePersistent.use((state) => state.deltaMode);
const syncShells = CompareEphemeral.use((state) => state.syncShells);
const [adding, setAdding] = useState(false);
const handleAdd = useCallback((tank: TankDefinition) => {
CompareEphemeral.mutate((draft) => {
draft.members.push(tankToCompareMember(tank));
draft.sorting.by = null;
});
}, []);
const handleAddAll = useCallback((tanks: TankDefinition[]) => {
CompareEphemeral.mutate((draft) => {
draft.members.push(...tanks.map(tankToCompareMember));
draft.sorting.by = null;
});
}, []);
const deltaOptions = useMemo<{ value: DeltaMode; label: string }[]>(
() => [
@@ -36,46 +49,17 @@ function Content() {
return (
<div className={styles.controls}>
<div className={styles.group}>
<Dialog.Root open={adding} onOpenChange={setAdding}>
<Dialog.Trigger asChild>
<Button variant="soft">
<PlusIcon />
{strings.compare.add.button}
</Button>
</Dialog.Trigger>
<Dialog.Portal>
<Dialog.Overlay />
<Dialog.Content>
<Dialog.Header>
<Dialog.Title>{strings.compare.add.title}</Dialog.Title>
<Dialog.Description>
{strings.compare.add.description}
</Dialog.Description>
</Dialog.Header>
<Dialog.Body>
<TankSearchResults
compact
onSelect={(tank) => {
CompareEphemeral.mutate((draft) => {
draft.members.push(tankToCompareMember(tank));
draft.sorting.by = null;
});
setAdding(false);
}}
onSelectAll={(tanks) => {
CompareEphemeral.mutate((draft) => {
draft.members.push(...tanks.map(tankToCompareMember));
draft.sorting.by = null;
});
setAdding(false);
}}
/>
</Dialog.Body>
</Dialog.Content>
</Dialog.Portal>
</Dialog.Root>
<TankSearchDialog
title={strings.compare.add.title}
description={strings.compare.add.description}
onSelect={handleAdd}
onSelectAll={handleAddAll}
>
<Button variant="soft">
<PlusIcon />
{strings.compare.add.button}
</Button>
</TankSearchDialog>
<Button
variant="soft"
@@ -1,13 +1,13 @@
import locales from "@blitzkit/i18n/locales.json";
import type { TankDefinition } from "@blitzkit/protos";
import { ExternalLinkIcon, LoopIcon, TrashIcon } from "@radix-ui/react-icons";
import { useCallback, useState } from "react";
import { useCallback } from "react";
import { tankToCompareMember } from "../../core/blitzkit/tankToCompareMember";
import { useLocale } from "../../hooks/useLocale";
import { useStrings } from "../../hooks/useStrings";
import { CompareEphemeral } from "../../stores/compareEphemeral";
import { Dialog } from "../Dialog";
import { IconButton } from "../IconButton";
import { TankSearchResults } from "../TankSearchResults";
import { TankSearchDialog } from "../TankSearchDialog";
import styles from "./index.module.css";
interface CompareTankControlProps {
@@ -18,7 +18,6 @@ interface CompareTankControlProps {
export function CompareTankControl({ index, slug }: CompareTankControlProps) {
const locale = useLocale();
const strings = useStrings();
const [swapping, setSwapping] = useState(false);
const handleRemove = useCallback(() => {
CompareEphemeral.mutate((draft) => {
@@ -27,44 +26,31 @@ export function CompareTankControl({ index, slug }: CompareTankControlProps) {
});
}, [index]);
const handleSwap = useCallback(
(tank: TankDefinition) => {
CompareEphemeral.mutate((draft) => {
draft.members[index] = tankToCompareMember(tank);
draft.sorting.by = null;
});
},
[index],
);
return (
<div className={styles.controls}>
<IconButton variant="ghost" size="minor" onClick={handleRemove}>
<TrashIcon />
</IconButton>
<Dialog.Root open={swapping} onOpenChange={setSwapping}>
<Dialog.Trigger asChild>
<IconButton variant="ghost" size="minor">
<LoopIcon />
</IconButton>
</Dialog.Trigger>
<Dialog.Portal>
<Dialog.Overlay />
<Dialog.Content>
<Dialog.Header>
<Dialog.Title>{strings.compare.swap_dialog.title}</Dialog.Title>
<Dialog.Description>
{strings.compare.swap_dialog.description}
</Dialog.Description>
</Dialog.Header>
<Dialog.Body>
<TankSearchResults
compact
onSelect={(tank) => {
CompareEphemeral.mutate((draft) => {
draft.members[index] = tankToCompareMember(tank);
draft.sorting.by = null;
});
setSwapping(false);
}}
/>
</Dialog.Body>
</Dialog.Content>
</Dialog.Portal>
</Dialog.Root>
<TankSearchDialog
title={strings.compare.swap_dialog.title}
description={strings.compare.swap_dialog.description}
onSelect={handleSwap}
>
<IconButton variant="ghost" size="minor">
<LoopIcon />
</IconButton>
</TankSearchDialog>
<IconButton
variant="ghost"
@@ -0,0 +1,7 @@
<script is:inline>
// Runs before hydration so fullscreen controls never pop in late
document.documentElement.style.setProperty(
"--fullscreen-display",
document.fullscreenEnabled ? "flex" : "none",
);
</script>
@@ -5,18 +5,15 @@ import type {
TurretDefinition,
} from "@blitzkit/protos";
import { CaretUpIcon } from "@radix-ui/react-icons";
import { useState } from "react";
import { api } from "../../api/dynamic";
import { useStrings } from "../../hooks/useStrings";
import type { MaybeSkeletonComponentProps } from "../../types/maybeSkeletonComponentProps";
import { Button } from "../Button";
import { Dialog } from "../Dialog";
import { Discriminator } from "../Discriminator";
import { IconButton } from "../IconButton";
import { LazyImage } from "../LazyImage";
import { Popover } from "../Popover";
import { Skeleton } from "../Skeleton";
import { TankSearchResults } from "../TankSearchResults";
import { TankSearchDialog } from "../TankSearchDialog";
import styles from "./index.module.css";
const tankDefinitions = await api.tanks();
@@ -39,8 +36,6 @@ export function MixerModuleChooser({
turret,
gun,
}: MixerModuleChooserProps) {
const strings = useStrings();
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);
@@ -52,52 +47,29 @@ export function MixerModuleChooser({
return (
<div className={styles["mixer-module-chooser"]}>
<Dialog.Root open={open} onOpenChange={setOpen}>
<Dialog.Trigger asChild>
<Button
variant="surface"
listChild="horizontal"
className={styles.trigger}
>
<div className={styles.sizer} />
<TankSearchDialog onSelect={onSelect}>
<Button
variant="surface"
listChild="horizontal"
className={styles.trigger}
>
<div className={styles.sizer} />
{skeleton ? (
<Skeleton className={styles.skeleton} />
) : (
<div
className={styles["tank-image"]}
style={{
backgroundImage: `url(${alias(
"api",
`/tanks/${tank}/icons/big.webp`,
)})`,
}}
/>
)}
</Button>
</Dialog.Trigger>
<Dialog.Portal>
<Dialog.Overlay />
<Dialog.Content>
<Dialog.Header>
<Dialog.Title>
{strings.website.common.tank_search.select_dialog_title}
</Dialog.Title>
</Dialog.Header>
<Dialog.Body>
<TankSearchResults
compact
onSelect={(tank) => {
onSelect?.(tank);
setOpen(false);
}}
/>
</Dialog.Body>
</Dialog.Content>
</Dialog.Portal>
</Dialog.Root>
{skeleton ? (
<Skeleton className={styles.skeleton} />
) : (
<div
className={styles["tank-image"]}
style={{
backgroundImage: `url(${alias(
"api",
`/tanks/${tank}/icons/big.webp`,
)})`,
}}
/>
)}
</Button>
</TankSearchDialog>
{subSelector && (
<Popover.Root>
@@ -1,13 +1,19 @@
import { Canvas, type CanvasProps } from "@react-three/fiber";
import { useRef } from "react";
import { useImperativeHandle, useRef, type Ref } from "react";
import { useOnScreen } from "../../hooks/useOnScreen";
import { classNames } from "../../ui/classNames";
import styles from "./index.module.css";
export function SmartCanvas({ className, ...props }: CanvasProps) {
interface SmartCanvasProps extends Omit<CanvasProps, "ref"> {
ref?: Ref<HTMLCanvasElement>;
}
export function SmartCanvas({ className, ref, ...props }: SmartCanvasProps) {
const canvas = useRef<HTMLCanvasElement>(null!);
const onScreen = useOnScreen(canvas);
useImperativeHandle(ref, () => canvas.current, []);
return (
<div className={classNames(styles.aligner, className)}>
<div className={styles.canvas}>
@@ -0,0 +1,3 @@
.filters {
overflow-x: auto;
}
@@ -0,0 +1,84 @@
import type { TankDefinition } from "@blitzkit/protos";
import { useCallback, useState, type ReactNode } from "react";
import { useLocale } from "../../hooks/useLocale";
import { useStrings } from "../../hooks/useStrings";
import { Dialog } from "../Dialog";
import { ScrollerCurtains } from "../ScrollerCurtains";
import { TankSearchBar } from "../TankSearchBar";
import { TankSearchFilters } from "../TankSearchFilters";
import { TankSearchResults } from "../TankSearchResults";
import styles from "./index.module.css";
interface TankSearchDialogProps {
// the trigger, passed to Dialog.Trigger with asChild
children: ReactNode;
title?: string;
description?: string;
onSelect: (tank: TankDefinition) => void;
onSelectAll?: (tanks: TankDefinition[]) => void;
}
export function TankSearchDialog({
children,
title,
description,
onSelect,
onSelectAll,
}: TankSearchDialogProps) {
const locale = useLocale();
const strings = useStrings();
const [open, setOpen] = useState(false);
const handleSelect = useCallback(
(tank: TankDefinition) => {
onSelect(tank);
setOpen(false);
},
[onSelect],
);
const handleSelectAll = useCallback(
(tanks: TankDefinition[]) => {
onSelectAll!(tanks);
setOpen(false);
},
[onSelectAll],
);
return (
<Dialog.Root open={open} onOpenChange={setOpen}>
<Dialog.Trigger asChild>{children}</Dialog.Trigger>
<Dialog.Portal>
<Dialog.Overlay />
<Dialog.Content>
<Dialog.Header>
<Dialog.Title>
{title ?? strings.website.common.tank_search.select_dialog_title}
</Dialog.Title>
{description && (
<Dialog.Description>{description}</Dialog.Description>
)}
</Dialog.Header>
<Dialog.Body>
<TankSearchBar locale={locale} onSelect={handleSelect} />
<div className={styles.filters}>
<ScrollerCurtains />
<TankSearchFilters locale={locale} />
</div>
<TankSearchResults
locale={locale}
compact
onSelect={handleSelect}
onSelectAll={onSelectAll && handleSelectAll}
/>
</Dialog.Body>
</Dialog.Content>
</Dialog.Portal>
</Dialog.Root>
);
}
@@ -1,6 +1,7 @@
import { alias, romanize, uniqueGuns } from "@blitzkit/core";
import { literals } from "@blitzkit/i18n";
import { useMemo } from "react";
import type { TankDefinition } from "@blitzkit/protos";
import { useCallback, useMemo } from "react";
import { useAbsoluteDisplay } from "../../hooks/useAbsoluteDisplay";
import { useDuelModules } from "../../hooks/useDuelModules";
import { useEquipment } from "../../hooks/useEquipment";
@@ -8,12 +9,13 @@ import { useStrings } from "../../hooks/useStrings";
import { useUnwrapper } from "../../hooks/useUnwrapper";
import { Tankopedia } from "../../stores/tankopedia";
import { TankopediaDisplay } from "../../stores/tankopediaPersistent/constants";
import { createTankState } from "../../tankopedia/createTankState";
import { CustomShellButton } from "../CustomShellButton";
import { EqualIcon } from "../EqualIcon";
import { IconButton } from "../IconButton";
import { Discriminator } from "../Discriminator";
import { LazyImage } from "../LazyImage";
import { TankSearchDialog } from "../TankSearchDialog";
import { Text } from "../Text";
import { Tooltip } from "../Tooltip";
import styles from "./index.module.css";
@@ -49,6 +51,14 @@ export function TankopediaAntagonistControl({
const isVisible = showControls && isDynamicArmorDisplay;
const handleTankSelect = useCallback((tank: TankDefinition) => {
Tankopedia.mutate((draft) => {
draft.antagonist = createTankState(tank);
draft.shot = undefined;
draft.customShell = undefined;
});
}, []);
return (
<div className={styles["antagonist-control"]} data-visible={isVisible}>
<Text lowContrast>
@@ -57,6 +67,15 @@ export function TankopediaAntagonistControl({
})}
</Text>
<TankSearchDialog onSelect={handleTankSelect}>
<IconButton variant="soft" color="gray" size="major">
<LazyImage
alt={unwrap(protagonist.tank.name)}
src={alias("api", `/tanks/${protagonist.tank.id}/icons/big.webp`)}
/>
</IconButton>
</TankSearchDialog>
{antagonistUniqueGuns.length > 1 && (
<div className={styles.group}>
{[...antagonistUniqueGuns].reverse().map((entry) => {
@@ -1,5 +1,4 @@
.fullscreen {
position: absolute;
right: var(--space-4);
bottom: var(--space-4);
/* set before hydration by FullscreenSupport.astro */
display: var(--fullscreen-display, none);
}
@@ -8,7 +8,6 @@ interface TankopediaFullscreenProps {
}
export function TankopediaFullscreen({ target }: TankopediaFullscreenProps) {
const [available, setAvailable] = useState(false);
const [isFullscreen, setIsFullscreen] = useState(false);
useEffect(() => {
@@ -16,7 +15,6 @@ export function TankopediaFullscreen({ target }: TankopediaFullscreenProps) {
setIsFullscreen(document.fullscreenElement === target.current);
}
setAvailable(document.fullscreenEnabled);
document.addEventListener("fullscreenchange", handleFullscreenChange);
return () => {
@@ -32,8 +30,6 @@ export function TankopediaFullscreen({ target }: TankopediaFullscreenProps) {
}
}, [isFullscreen]);
if (!available) return null;
return (
<IconButton
className={styles.fullscreen}
@@ -9,5 +9,21 @@
width: 100%;
height: 100%;
background-color: black;
.corner-actions {
display: flex;
gap: var(--space-4);
position: absolute;
right: var(--space-4);
bottom: var(--space-4);
transition-duration: var(--duration-brief);
transform: translateY(calc(100% + var(--space-4) + var(--space-1)));
&[data-visible="true"] {
transform: translateY(0);
}
}
}
}
@@ -22,6 +22,7 @@ import { CanvasControl } from "../CanvasControl";
import { InitialCameraAligner } from "../InitialCameraAligner";
import { Lighting, transitionEvent } from "../Lighting";
import { SceneProps } from "../SceneProps";
import { ScreenshotButton } from "../ScreenshotButton";
import { ShotCard } from "../ShotCard";
import { SmartCanvas } from "../SmartCanvas";
import { TankDynamicArmor } from "../TankDynamicArmor";
@@ -52,8 +53,10 @@ function Sandbox({ id }: TankopediaSandboxProps) {
Tankopedia.useInitialization(() => protagonistTank, import.meta.env.SSR);
const equalize = Tankopedia.use((state) => state.environment.equalize);
const showControls = Tankopedia.use((state) => state.showControls);
const mounted = useMounted();
const wrapper = useRef<HTMLDivElement>(null);
const canvas = useRef<HTMLCanvasElement>(null!);
const hasImprovedVerticalStabilizer = useEquipment("protagonist", 122);
const hasDownImprovedVerticalStabilizer = useEquipment("protagonist", 124);
@@ -191,6 +194,7 @@ function Sandbox({ id }: TankopediaSandboxProps) {
<div className={styles.wrapper} ref={wrapper}>
<div className={styles.cavity}>
<SmartCanvas
ref={canvas}
resize={{ debounce: 0 }}
gl={{
clippingPlanes: [],
@@ -215,7 +219,16 @@ function Sandbox({ id }: TankopediaSandboxProps) {
<Thicknesses thicknessRange={thicknessRange} />
<TankopediaAntagonistControl penetration={antagonistPenetration} />
<TankopediaOptions />
<TankopediaFullscreen target={wrapper} />
<div className={styles["corner-actions"]} data-visible={showControls}>
<ScreenshotButton
variant="ghost"
highContrast
canvas={canvas}
name={protagonistTank.slug}
/>
<TankopediaFullscreen target={wrapper} />
</div>
</div>
</div>
);
@@ -2,6 +2,7 @@
import AutoFocus from "../components/AutoFocus.astro";
import BaseMeta from "../components/BaseMeta.astro";
import BaseStyles from "../components/BaseStyles.astro";
import FullscreenSupport from "../components/FullscreenSupport.astro";
import ColorAlias from "../components/ColorAlias.astro";
import ColorScale from "../components/ColorScale.astro";
import NavbarSmall from "../components/NavbarSmall.astro";
@@ -35,6 +36,7 @@ const { locale, accent, solidNavbar = false, tool } = Astro.props;
<ColorAlias color={accent} alias="accent" />
<BaseStyles />
<FullscreenSupport />
<style>
:root {