feat: segmented control mode

This commit is contained in:
TrèsAbhi committed 2024-07-28 13:32:52 -05:00
1 parent 6e7df526ff
commit 6ebced6f01
11 files changed
+160 -237

No files matched your search

BIN
View File
Binary file not shown.
+2 -2
View File
@@ -18,7 +18,7 @@
"start:bot": "bun dist/bot/index.js", "start:bot": "bun dist/bot/index.js",
"start:website": "next start", "start:website": "next start",
"host:docs": "vitepress preview docs", "host:docs": "vitepress preview docs",
"lint": "npx tsc", "lint": "tsc",
"lint:website": "next lint", "lint:website": "next lint",
"format": "prettier --write \"**/*.@(json|js|jsx|css|md|ts|tsx|html|xml|yml|gltf)\"", "format": "prettier --write \"**/*.@(json|js|jsx|css|md|ts|tsx|html|xml|yml|gltf)\"",
"knip": "knip", "knip": "knip",
@@ -103,7 +103,7 @@
"knip": "^3.13.2", "knip": "^3.13.2",
"prettier": "^3.3.2", "prettier": "^3.3.2",
"prisma": "^5.16.2", "prisma": "^5.16.2",
"typescript": "^5.5.3" "typescript": "^5.5.4"
}, },
"packageManager": "[email protected]", "packageManager": "[email protected]",
"trustedDependencies": [ "trustedDependencies": [
@@ -12,6 +12,7 @@ import { useEquipment } from '../../../../../../hooks/useEquipment';
import * as Duel from '../../../../../../stores/duel'; import * as Duel from '../../../../../../stores/duel';
import * as TankopediaEphemeral from '../../../../../../stores/tankopediaEphemeral'; import * as TankopediaEphemeral from '../../../../../../stores/tankopediaEphemeral';
import * as TankopediaPersistent from '../../../../../../stores/tankopediaPersistent'; import * as TankopediaPersistent from '../../../../../../stores/tankopediaPersistent';
import { TankopediaDisplay } from '../../../../../../stores/tankopediaPersistent/constants';
import { Controls } from '../Control'; import { Controls } from '../Control';
import { Lighting } from '../Lighting'; import { Lighting } from '../Lighting';
import { SceneProps } from '../SceneProps'; import { SceneProps } from '../SceneProps';
@@ -30,7 +31,7 @@ export function TankSandbox() {
const turretModelDefinition = const turretModelDefinition =
tankModelDefinition.turrets[protagonist.turret.id]; tankModelDefinition.turrets[protagonist.turret.id];
const gunModelDefinition = turretModelDefinition.guns[protagonist.gun.id]; const gunModelDefinition = turretModelDefinition.guns[protagonist.gun.id];
const armorMode = TankopediaPersistent.use((state) => state.armorMode); const display = TankopediaPersistent.use((state) => state.display);
function handlePointerDown() { function handlePointerDown() {
window.addEventListener('pointermove', handlePointerMove); window.addEventListener('pointermove', handlePointerMove);
@@ -123,6 +124,20 @@ export function TankSandbox() {
}); });
}, [protagonist.gun, protagonist.turret]); }, [protagonist.gun, protagonist.turret]);
useEffect(() => {
if (display !== TankopediaDisplay.DynamicArmor) {
mutateTankopediaEphemeral((draft) => {
draft.shot = undefined;
});
}
if (display !== TankopediaDisplay.StaticArmor) {
mutateTankopediaEphemeral((draft) => {
draft.highlightArmor = undefined;
});
}
}, [display]);
return ( return (
<Canvas <Canvas
gl={{ clippingPlanes: Object.freeze([]), localClippingEnabled: true }} gl={{ clippingPlanes: Object.freeze([]), localClippingEnabled: true }}
@@ -140,12 +155,12 @@ export function TankSandbox() {
> >
<Controls /> <Controls />
<SceneProps /> <SceneProps />
<TankModel /> {display !== TankopediaDisplay.StaticArmor && <TankModel />}
{/* idk why the shot display doesn't work without suspense here lol */} {/* idk why the shot display doesn't work without suspense here lol */}
<Suspense fallback={<ModelLoader />}> <Suspense fallback={<ModelLoader />}>
{armorMode === 'blitz' && <Armor />} {display === TankopediaDisplay.DynamicArmor && <Armor />}
{armorMode === 'static' && ( {display === TankopediaDisplay.StaticArmor && (
<StaticArmor awaitedTankDefinitions={awaitedTankDefinitions} /> <StaticArmor awaitedTankDefinitions={awaitedTankDefinitions} />
)} )}
<Lighting /> <Lighting />
@@ -14,8 +14,8 @@ import {
Heading, Heading,
IconButton, IconButton,
Popover, Popover,
SegmentedControl,
Strong, Strong,
Switch,
Tabs, Tabs,
Text, Text,
} from '@radix-ui/themes'; } from '@radix-ui/themes';
@@ -25,6 +25,7 @@ import { SmallTankIcon } from '../../../../../../../components/SmallTankIcon';
import { resolveNearPenetration } from '../../../../../../../core/blitz/resolveNearPenetration'; import { resolveNearPenetration } from '../../../../../../../core/blitz/resolveNearPenetration';
import { resolvePenetrationCoefficient } from '../../../../../../../core/blitz/resolvePenetrationCoefficient'; import { resolvePenetrationCoefficient } from '../../../../../../../core/blitz/resolvePenetrationCoefficient';
import { asset } from '../../../../../../../core/blitzkit/asset'; import { asset } from '../../../../../../../core/blitzkit/asset';
import { imgur } from '../../../../../../../core/blitzkit/imgur';
import { Pose, poseEvent } from '../../../../../../../core/blitzkit/pose'; import { Pose, poseEvent } from '../../../../../../../core/blitzkit/pose';
import { import {
SHELL_NAMES, SHELL_NAMES,
@@ -38,6 +39,7 @@ import * as App from '../../../../../../../stores/app';
import * as Duel from '../../../../../../../stores/duel'; import * as Duel from '../../../../../../../stores/duel';
import * as TankopediaEphemeral from '../../../../../../../stores/tankopediaEphemeral'; import * as TankopediaEphemeral from '../../../../../../../stores/tankopediaEphemeral';
import * as TankopediaPersistent from '../../../../../../../stores/tankopediaPersistent'; import * as TankopediaPersistent from '../../../../../../../stores/tankopediaPersistent';
import { TankopediaDisplay } from '../../../../../../../stores/tankopediaPersistent/constants';
import { TankSearch } from '../../../../components/TankSearch'; import { TankSearch } from '../../../../components/TankSearch';
import { ENVIRONMENTS } from '../../Lighting'; import { ENVIRONMENTS } from '../../Lighting';
import { RotationInputs } from '../../QuickInputs'; import { RotationInputs } from '../../QuickInputs';
@@ -45,9 +47,10 @@ import { RotationInputs } from '../../QuickInputs';
export function Options() { export function Options() {
const mutateTankopediaEphemeral = TankopediaEphemeral.useMutation(); const mutateTankopediaEphemeral = TankopediaEphemeral.useMutation();
const mutateTankopediaPersistent = TankopediaPersistent.useMutation(); const mutateTankopediaPersistent = TankopediaPersistent.useMutation();
const modeRaw = TankopediaPersistent.use((state) => state.mode); const displayRaw = TankopediaPersistent.use((state) => state.display);
const [mode, setMode] = const [display, setDisplay] = useState<TankopediaDisplay>(
useState<TankopediaPersistent.TankopediaMode>('model'); TankopediaDisplay.Model,
);
const isFullScreen = useFullScreen(); const isFullScreen = useFullScreen();
const showGrid = TankopediaPersistent.use( const showGrid = TankopediaPersistent.use(
(state) => state.model.visual.showGrid, (state) => state.model.visual.showGrid,
@@ -81,7 +84,7 @@ export function Options() {
const hasEnhancedArmor = useEquipment(110); const hasEnhancedArmor = useEquipment(110);
const antagonistUniqueGuns = uniqueGuns(antagonistTank.turrets); const antagonistUniqueGuns = uniqueGuns(antagonistTank.turrets);
useEffect(() => setMode(modeRaw), [modeRaw]); useEffect(() => setDisplay(displayRaw), [displayRaw]);
return ( return (
<> <>
@@ -112,7 +115,7 @@ export function Options() {
<RotationInputs /> <RotationInputs />
{mode === 'armor' && ( {display === TankopediaDisplay.DynamicArmor && (
<Flex <Flex
gap="2" gap="2"
direction="column" direction="column"
@@ -309,7 +312,7 @@ export function Options() {
align="center" align="center"
gap="2" gap="2"
> >
{mode === 'armor' && ( {display === TankopediaDisplay.DynamicArmor && (
<Flex align="center" gap="2"> <Flex align="center" gap="2">
<Text color="gray" size="2"> <Text color="gray" size="2">
Shooter: Shooter:
@@ -470,25 +473,30 @@ export function Options() {
)} )}
<Flex gap="3" align="center"> <Flex gap="3" align="center">
<Flex <SegmentedControl.Root
style={{ value={`${display}`}
cursor: 'default', onValueChange={(value) => {
userSelect: 'none',
}}
align="center"
gap="2"
onClick={() => {
mutateTankopediaPersistent((draft) => { mutateTankopediaPersistent((draft) => {
draft.mode = draft.mode === 'armor' ? 'model' : 'armor'; draft.display = Number(value);
}); });
}} }}
mr="1"
> >
<Switch size="1" checked={mode === 'armor'} /> <SegmentedControl.Item value={`${TankopediaDisplay.Model}`}>
<Text color="gray" size="2"> <Flex height="100%" align="center">
Armor <img src={imgur('jAdYf0m')} style={{ height: '1.5em' }} />
</Text> </Flex>
</Flex> </SegmentedControl.Item>
<SegmentedControl.Item value={`${TankopediaDisplay.DynamicArmor}`}>
<Flex height="100%" align="center">
<img src={imgur('oe4Cq0g')} style={{ height: '1.5em' }} />
</Flex>
</SegmentedControl.Item>
<SegmentedControl.Item value={`${TankopediaDisplay.StaticArmor}`}>
<Flex height="100%" align="center">
<img src={imgur('VQ4uDno')} style={{ height: '1.5em' }} />
</Flex>
</SegmentedControl.Item>
</SegmentedControl.Root>
<DropdownMenu.Root> <DropdownMenu.Root>
<DropdownMenu.Trigger> <DropdownMenu.Trigger>
@@ -511,7 +519,6 @@ export function Options() {
</DropdownMenu.Item> </DropdownMenu.Item>
</DropdownMenu.Content> </DropdownMenu.Content>
</DropdownMenu.Root> </DropdownMenu.Root>
<DropdownMenu.Root> <DropdownMenu.Root>
<DropdownMenu.Trigger> <DropdownMenu.Trigger>
<IconButton variant="ghost" color="gray"> <IconButton variant="ghost" color="gray">
@@ -520,7 +527,7 @@ export function Options() {
</DropdownMenu.Trigger> </DropdownMenu.Trigger>
<DropdownMenu.Content> <DropdownMenu.Content>
{mode === 'armor' && ( {display !== TankopediaDisplay.Model && (
<> <>
<DropdownMenu.Label>Armor</DropdownMenu.Label> <DropdownMenu.Label>Armor</DropdownMenu.Label>
@@ -622,7 +629,6 @@ export function Options() {
</DropdownMenu.Sub> </DropdownMenu.Sub>
</DropdownMenu.Content> </DropdownMenu.Content>
</DropdownMenu.Root> </DropdownMenu.Root>
{fullScreenAvailable && ( {fullScreenAvailable && (
<IconButton <IconButton
color="gray" color="gray"
@@ -1,5 +1,5 @@
import { ThreeEvent, useThree } from '@react-three/fiber'; import { ThreeEvent, useThree } from '@react-three/fiber';
import { memo, useEffect, useRef } from 'react'; import { memo, useRef } from 'react';
import { Group, Mesh, MeshStandardMaterial, Vector2 } from 'three'; import { Group, Mesh, MeshStandardMaterial, Vector2 } from 'three';
import { ModelTankWrapper } from '../../../../../../../components/Armor/components/ModelTankWrapper'; import { ModelTankWrapper } from '../../../../../../../components/Armor/components/ModelTankWrapper';
import { applyPitchYawLimits } from '../../../../../../../core/blitz/applyPitchYawLimits'; import { applyPitchYawLimits } from '../../../../../../../core/blitz/applyPitchYawLimits';
@@ -14,6 +14,7 @@ import { useTankTransform } from '../../../../../../../hooks/useTankTransform';
import * as Duel from '../../../../../../../stores/duel'; import * as Duel from '../../../../../../../stores/duel';
import * as TankopediaEphemeral from '../../../../../../../stores/tankopediaEphemeral'; import * as TankopediaEphemeral from '../../../../../../../stores/tankopediaEphemeral';
import * as TankopediaPersistent from '../../../../../../../stores/tankopediaPersistent'; import * as TankopediaPersistent from '../../../../../../../stores/tankopediaPersistent';
import { TankopediaDisplay } from '../../../../../../../stores/tankopediaPersistent/constants';
export const TankModel = memo(() => { export const TankModel = memo(() => {
const mutateDuel = Duel.useMutation(); const mutateDuel = Duel.useMutation();
@@ -38,32 +39,6 @@ export const TankModel = memo(() => {
const { gltf } = useModel(protagonist.tank.id); const { gltf } = useModel(protagonist.tank.id);
const nodes = Object.values(gltf.nodes); const nodes = Object.values(gltf.nodes);
useEffect(() => {
function handleVisibility() {
if (!hullContainer.current) return;
const state = tankopediaPersistentStore.getState();
hullContainer.current.visible =
state.mode === 'model' || state.armorMode === 'blitz';
}
const unsubscribes = [
tankopediaPersistentStore.subscribe(
(state) => state.mode,
handleVisibility,
),
tankopediaPersistentStore.subscribe(
(state) => state.armorMode,
handleVisibility,
),
];
handleVisibility();
return () => unsubscribes.forEach((unsubscribe) => unsubscribe());
}, []);
return ( return (
<ModelTankWrapper ref={hullContainer}> <ModelTankWrapper ref={hullContainer}>
{nodes.map((node) => { {nodes.map((node) => {
@@ -92,7 +67,8 @@ export const TankModel = memo(() => {
function onPointerDown(event: ThreeEvent<PointerEvent>) { function onPointerDown(event: ThreeEvent<PointerEvent>) {
if ( if (
isTrack && isTrack &&
tankopediaPersistentStore.getState().mode === 'model' tankopediaPersistentStore.getState().display ===
TankopediaDisplay.Model
) { ) {
position.set(event.clientX, event.clientY); position.set(event.clientX, event.clientY);
event.stopPropagation(); event.stopPropagation();
@@ -1,5 +1,5 @@
import { HeightIcon, WidthIcon } from '@radix-ui/react-icons'; import { HeightIcon, WidthIcon } from '@radix-ui/react-icons';
import { Box, Flex, TextField } from '@radix-ui/themes'; import { Flex, TextField } from '@radix-ui/themes';
import { use, useEffect, useRef } from 'react'; import { use, useEffect, useRef } from 'react';
import { degToRad, radToDeg } from 'three/src/math/MathUtils'; import { degToRad, radToDeg } from 'three/src/math/MathUtils';
import { applyPitchYawLimits } from '../../../../../../core/blitz/applyPitchYawLimits'; import { applyPitchYawLimits } from '../../../../../../core/blitz/applyPitchYawLimits';
@@ -27,8 +27,6 @@ export function RotationInputs() {
const initialGunPitch = tankModelDefinition.turretRotation?.pitch ?? 0; const initialGunPitch = tankModelDefinition.turretRotation?.pitch ?? 0;
const hasImprovedVerticalStabilizer = useEquipment(122); const hasImprovedVerticalStabilizer = useEquipment(122);
const isFullScreen = useFullScreen(); const isFullScreen = useFullScreen();
const mode = TankopediaPersistent.use((state) => state.mode);
const armorMode = TankopediaPersistent.use((state) => state.armorMode);
const mutateTankopediaPersistent = TankopediaPersistent.useMutation(); const mutateTankopediaPersistent = TankopediaPersistent.useMutation();
useEffect(() => { useEffect(() => {
@@ -61,9 +59,7 @@ export function RotationInputs() {
return ( return (
<Flex <Flex
className={ className={styles.container}
isFullScreen || mode === 'armor' ? undefined : styles.container
}
style={{ style={{
width: 128 + 32, width: 128 + 32,
pointerEvents: 'auto', pointerEvents: 'auto',
@@ -72,145 +68,108 @@ export function RotationInputs() {
top: 16, top: 16,
transform: 'translateX(-50%)', transform: 'translateX(-50%)',
}} }}
direction="column"
align="center" align="center"
gap="2" gap="2"
> >
<Flex gap="2"> <TextField.Root
<TextField.Root size="1"
size="1" radius="full"
radius="full" style={{
style={{ flex: 1,
flex: 1, textAlign: 'right',
textAlign: 'right', }}
}} onBlur={() => {
onBlur={() => { const value = Number(yawInput.current!.value);
const value = Number(yawInput.current!.value); if (isNaN(value)) {
if (isNaN(value)) {
yawInput.current!.value = radToDeg(protagonist.yaw).toFixed(1);
return;
}
const [pitch, yaw] = applyPitchYawLimits(
protagonist.pitch,
degToRad(value),
gunModelDefinition.pitch,
turretModelDefinition.yaw,
hasImprovedVerticalStabilizer,
);
modelTransformEvent.emit({ pitch, yaw });
mutateDuel((state) => {
state.protagonist.pitch = pitch;
state.protagonist.yaw = yaw;
});
yawInput.current!.value = radToDeg(protagonist.yaw).toFixed(1); yawInput.current!.value = radToDeg(protagonist.yaw).toFixed(1);
}} return;
onKeyDown={(event) => { }
if (event.key === 'Enter') { const [pitch, yaw] = applyPitchYawLimits(
yawInput.current?.blur(); protagonist.pitch,
} degToRad(value),
}} gunModelDefinition.pitch,
onFocus={() => yawInput.current?.focus()} turretModelDefinition.yaw,
ref={yawInput} hasImprovedVerticalStabilizer,
> );
<TextField.Slot modelTransformEvent.emit({ pitch, yaw });
style={{ mutateDuel((state) => {
userSelect: 'none', state.protagonist.pitch = pitch;
}} state.protagonist.yaw = yaw;
> });
<WidthIcon /> yawInput.current!.value = radToDeg(protagonist.yaw).toFixed(1);
</TextField.Slot> }}
<TextField.Slot style={{ userSelect: 'none' }}>°</TextField.Slot> onKeyDown={(event) => {
</TextField.Root> if (event.key === 'Enter') {
yawInput.current?.blur();
<TextField.Root }
size="1" }}
radius="full" onFocus={() => yawInput.current?.focus()}
ref={yawInput}
>
<TextField.Slot
style={{ style={{
flex: 1, userSelect: 'none',
textAlign: 'right',
}} }}
onBlur={() => { >
const value = Number(pitchInput.current!.value); <WidthIcon />
if (isNaN(value)) { </TextField.Slot>
pitchInput.current!.value = ( <TextField.Slot style={{ userSelect: 'none' }}>°</TextField.Slot>
-radToDeg(protagonist.pitch) + initialGunPitch </TextField.Root>
).toFixed(1);
return; <TextField.Root
} size="1"
const [pitch, yaw] = applyPitchYawLimits( radius="full"
degToRad(-value + initialGunPitch), style={{
protagonist.yaw, flex: 1,
gunModelDefinition.pitch, textAlign: 'right',
turretModelDefinition.yaw, }}
hasImprovedVerticalStabilizer, onBlur={() => {
); const value = Number(pitchInput.current!.value);
modelTransformEvent.emit({ pitch, yaw }); if (isNaN(value)) {
mutateDuel((state) => {
state.protagonist.pitch = pitch;
state.protagonist.yaw = yaw;
});
pitchInput.current!.value = ( pitchInput.current!.value = (
-radToDeg(protagonist.pitch) + initialGunPitch -radToDeg(protagonist.pitch) + initialGunPitch
).toFixed(1); ).toFixed(1);
}} return;
onKeyDown={(event) => { }
if (event.key === 'Enter') { const [pitch, yaw] = applyPitchYawLimits(
pitchInput.current?.blur(); degToRad(-value + initialGunPitch),
} protagonist.yaw,
}} gunModelDefinition.pitch,
onFocus={() => pitchInput.current?.focus()} turretModelDefinition.yaw,
ref={pitchInput} hasImprovedVerticalStabilizer,
> );
<TextField.Slot modelTransformEvent.emit({ pitch, yaw });
style={{ mutateDuel((state) => {
userSelect: 'none', state.protagonist.pitch = pitch;
}} state.protagonist.yaw = yaw;
> });
<HeightIcon /> pitchInput.current!.value = (
</TextField.Slot> -radToDeg(protagonist.pitch) + initialGunPitch
<TextField.Slot ).toFixed(1);
style={{ }}
userSelect: 'none', onKeyDown={(event) => {
}} if (event.key === 'Enter') {
> pitchInput.current?.blur();
° }
</TextField.Slot> }}
</TextField.Root> onFocus={() => pitchInput.current?.focus()}
</Flex> ref={pitchInput}
>
<Flex gap="2"> <TextField.Slot
<Box
width="var(--space-6)"
height="var(--space-4)"
style={{ style={{
borderRadius: 'var(--radius-1)', userSelect: 'none',
background: 'linear-gradient(90deg, #FF2020, #FF8080)',
opacity: armorMode === 'blitz' ? 1 : 0.5,
}}
onClick={() => {
mutateTankopediaPersistent((draft) => {
draft.armorMode = 'blitz';
});
}}
/>
<Flex
width="var(--space-6)"
height="var(--space-4)"
style={{
borderRadius: 'var(--radius-1)',
overflow: 'hidden',
opacity: armorMode === 'static' ? 1 : 0.5,
}}
onClick={() => {
mutateTankopediaPersistent((draft) => {
draft.armorMode = 'static';
});
}} }}
> >
<Box flexGrow="1" style={{ backgroundColor: '#8000FF' }} /> <HeightIcon />
<Box flexGrow="1" style={{ backgroundColor: '#FF0080' }} /> </TextField.Slot>
</Flex> <TextField.Slot
</Flex> style={{
userSelect: 'none',
}}
>
°
</TextField.Slot>
</TextField.Root>
</Flex> </Flex>
); );
} }
@@ -1,4 +1,4 @@
import { memo, useEffect, useRef } from 'react'; import { memo, useRef } from 'react';
import { Group } from 'three'; import { Group } from 'three';
import { correctZYTuple } from '../../../core/blitz/correctZYTuple'; import { correctZYTuple } from '../../../core/blitz/correctZYTuple';
import { nameToArmorId } from '../../../core/blitzkit/nameToArmorId'; import { nameToArmorId } from '../../../core/blitzkit/nameToArmorId';
@@ -31,26 +31,11 @@ export const CoreArmorScene = memo(() => {
const turretOrigin = correctZYTuple(tankModelDefinition.turretOrigin); const turretOrigin = correctZYTuple(tankModelDefinition.turretOrigin);
const gunOrigin = correctZYTuple(turretModelDefinition.gunOrigin); const gunOrigin = correctZYTuple(turretModelDefinition.gunOrigin);
const tankopediaPersistentStore = TankopediaPersistent.useStore(); const tankopediaPersistentStore = TankopediaPersistent.useStore();
const initialTankopediaState = tankopediaPersistentStore.getState();
useTankTransform(protagonist, turretContainer, gunContainer); useTankTransform(protagonist, turretContainer, gunContainer);
useEffect(() => {
const unsubscribe = tankopediaPersistentStore.subscribe(
(state) => state.mode,
(mode) => {
if (wrapper.current) wrapper.current.visible = mode === 'armor';
},
);
return unsubscribe;
});
return ( return (
<ModelTankWrapper <ModelTankWrapper ref={wrapper}>
ref={wrapper}
visible={initialTankopediaState.mode === 'armor'}
>
<group position={hullOrigin}> <group position={hullOrigin}>
{armorNodes.map((node) => { {armorNodes.map((node) => {
const isHull = node.name.startsWith('hull_'); const isHull = node.name.startsWith('hull_');
@@ -1,4 +1,4 @@
import { memo, useEffect, useMemo, useRef } from 'react'; import { memo, useMemo, useRef } from 'react';
import { Group, Plane, Scene, Vector3 } from 'three'; import { Group, Plane, Scene, Vector3 } from 'three';
import { correctZYTuple } from '../../../core/blitz/correctZYTuple'; import { correctZYTuple } from '../../../core/blitz/correctZYTuple';
import { nameToArmorId } from '../../../core/blitzkit/nameToArmorId'; import { nameToArmorId } from '../../../core/blitzkit/nameToArmorId';
@@ -9,7 +9,6 @@ import { useModel } from '../../../hooks/useModel';
import { useModelDefinitions } from '../../../hooks/useModelDefinitions'; import { useModelDefinitions } from '../../../hooks/useModelDefinitions';
import { useTankTransform } from '../../../hooks/useTankTransform'; import { useTankTransform } from '../../../hooks/useTankTransform';
import * as Duel from '../../../stores/duel'; import * as Duel from '../../../stores/duel';
import * as TankopediaPersistent from '../../../stores/tankopediaPersistent';
import { ModelTankWrapper } from '../../Armor/components/ModelTankWrapper'; import { ModelTankWrapper } from '../../Armor/components/ModelTankWrapper';
import { ArmorType } from '../../Armor/components/SpacedArmorScene'; import { ArmorType } from '../../Armor/components/SpacedArmorScene';
import { SpacedArmorSceneComponent } from '../../Armor/components/SpacedArmorSceneComponent'; import { SpacedArmorSceneComponent } from '../../Armor/components/SpacedArmorSceneComponent';
@@ -27,7 +26,6 @@ export interface ThicknessRange {
export const StaticArmorScene = memo<StaticArmorSceneProps>( export const StaticArmorScene = memo<StaticArmorSceneProps>(
({ scene, awaitedTankDefinitions }) => { ({ scene, awaitedTankDefinitions }) => {
const wrapper = useRef<Group>(null); const wrapper = useRef<Group>(null);
const tankopediaPersistentStore = TankopediaPersistent.useStore();
const awaitedTankModelDefinitions = useModelDefinitions(); const awaitedTankModelDefinitions = useModelDefinitions();
const turretContainer = useRef<Group>(null); const turretContainer = useRef<Group>(null);
const gunContainer = useRef<Group>(null); const gunContainer = useRef<Group>(null);
@@ -98,22 +96,6 @@ export const StaticArmorScene = memo<StaticArmorSceneProps>(
useTankTransform(protagonist, turretContainer, gunContainer); useTankTransform(protagonist, turretContainer, gunContainer);
useEffect(() => {
function handleMode(mode: TankopediaPersistent.TankopediaMode) {
if (!wrapper.current) return;
wrapper.current.visible = mode === 'armor';
}
const unsubscribe = tankopediaPersistentStore.subscribe(
(state) => state.mode,
handleMode,
);
handleMode(tankopediaPersistentStore.getState().mode);
return unsubscribe;
}, []);
return ( return (
<ModelTankWrapper ref={wrapper}> <ModelTankWrapper ref={wrapper}>
<group position={hullOrigin}> <group position={hullOrigin}>
@@ -58,3 +58,8 @@ export const SORT_NAMES = {
'maneuverability.weight': 'weight', 'maneuverability.weight': 'weight',
'maneuverability.traverseSpeed': 'traverse speed', 'maneuverability.traverseSpeed': 'traverse speed',
} as const; } as const;
export enum TankopediaDisplay {
Model,
DynamicArmor,
StaticArmor,
}
+3 -8
View File
@@ -7,14 +7,11 @@ import { ENVIRONMENTS } from '../../app/tools/tankopedia/[id]/components/Lightin
import { TankClass, TreeType } from '../../components/Tanks'; import { TankClass, TreeType } from '../../components/Tanks';
import { Tier } from '../../core/blitzkit/tankDefinitions'; import { Tier } from '../../core/blitzkit/tankDefinitions';
import { createNextSafeStore } from '../../core/zustand/createNextSafeStore'; import { createNextSafeStore } from '../../core/zustand/createNextSafeStore';
import { SORT_NAMES } from './constants'; import { SORT_NAMES, TankopediaDisplay } from './constants';
export type TankopediaSortBy = keyof typeof SORT_NAMES; export type TankopediaSortBy = keyof typeof SORT_NAMES;
export type TankopediaSortDirection = 'ascending' | 'descending'; export type TankopediaSortDirection = 'ascending' | 'descending';
export type TankopediaTestTankDisplay = 'include' | 'exclude' | 'only'; export type TankopediaTestTankDisplay = 'include' | 'exclude' | 'only';
export type TankopediaMode = 'model' | 'armor';
export type TankopediaArmorMode = 'blitz' | 'static';
export interface TankopediaPersistent { export interface TankopediaPersistent {
model: { model: {
visual: { visual: {
@@ -39,8 +36,7 @@ export interface TankopediaPersistent {
test: TankopediaTestTankDisplay; test: TankopediaTestTankDisplay;
page: number; page: number;
}; };
mode: TankopediaMode; display: TankopediaDisplay;
armorMode: TankopediaArmorMode;
} }
export const { Provider, use, useMutation, useStore } = createNextSafeStore( export const { Provider, use, useMutation, useStore } = createNextSafeStore(
@@ -71,8 +67,7 @@ export const { Provider, use, useMutation, useStore } = createNextSafeStore(
test: 'include', test: 'include',
page: 0, page: 0,
}, },
mode: 'model', display: TankopediaDisplay.Model,
armorMode: 'blitz',
})), })),
{ name: 'tankopedia', merge: (a, b) => merge(b, a) }, { name: 'tankopedia', merge: (a, b) => merge(b, a) },
), ),
+1 -1
View File
@@ -21,5 +21,5 @@
] ]
}, },
"include": ["src/**/*", "scripts/**/*", "dist/website/types/**/*.ts"], "include": ["src/**/*", "scripts/**/*", "dist/website/types/**/*.ts"],
"exclude": ["node_modules", "dist", "scripts"] "exclude": ["node_modules/**/*", "dist"]
} }