feat: persistant tankopedia

This commit is contained in:
TrèsAbhi committed 2024-01-21 10:34:52 -06:00
1 parent f51e365ec4
commit a70100c835
17 files changed
+156 -126

No files matched your search

@@ -25,7 +25,7 @@ import {
SHELL_NAMES,
tankNamesDiacritics,
} from '../../../../../../core/blitzkrieg/tankDefinitions';
import { useTankopedia } from '../../../../../../stores/tankopedia';
import { useTankopediaTemporary } from '../../../../../../stores/tankopedia';
import { Duel } from '../../page';
import { SearchResults } from './components/SearchResults';
@@ -38,7 +38,7 @@ export function AntagonistBar({
duel: { antagonist },
setDuel,
}: AntagonistBarProps) {
const mode = useTankopedia((state) => state.mode);
const mode = useTankopediaTemporary((state) => state.mode);
const awaitedTankNamesDiacritics = use(tankNamesDiacritics);
const [tab, setTab] = useState('search');
const searchInput = useRef<HTMLInputElement>(null);
@@ -3,8 +3,9 @@ import { produce } from 'immer';
import { Dispatch, SetStateAction, use } from 'react';
import { ModuleButton } from '../../../../../components/ModuleButton';
import { equipmentDefinitions } from '../../../../../core/blitzkrieg/equipmentDefinitions';
import mutateTankopedia, {
useTankopedia,
import {
mutateTankopediaTemporary,
useTankopediaTemporary,
} from '../../../../../stores/tankopedia';
import { Duel } from '../page';
@@ -17,7 +18,9 @@ export function Configure({ duel, setDuel }: ConfigureProps) {
const awaitedEquipmentDefinitions = use(equipmentDefinitions);
const equipmentRows =
awaitedEquipmentDefinitions.presets[duel.protagonist.tank.equipment];
const equipmentMatrix = useTankopedia((state) => state.equipmentMatrix);
const equipmentMatrix = useTankopediaTemporary(
(state) => state.equipmentMatrix,
);
return (
<Flex gap="4" direction="column">
@@ -97,7 +100,7 @@ export function Configure({ duel, setDuel }: ConfigureProps) {
rowChild
selected={equipmentMatrix[rowIndex][columnIndex] === 0}
onClick={() => {
mutateTankopedia((draft) => {
mutateTankopediaTemporary((draft) => {
draft.equipmentMatrix[rowIndex][columnIndex] = 0;
});
}}
@@ -109,7 +112,7 @@ export function Configure({ duel, setDuel }: ConfigureProps) {
rowChild
selected={equipmentMatrix[rowIndex][columnIndex] === 1}
onClick={() => {
mutateTankopedia((draft) => {
mutateTankopediaTemporary((draft) => {
draft.equipmentMatrix[rowIndex][columnIndex] = 1;
});
}}
@@ -7,7 +7,7 @@ import { OrbitControls as OrbitControlsClass } from 'three-stdlib';
import { applyPitchYawLimits } from '../../../../../core/blitz/applyPitchYawLimits';
import { modelDefinitions } from '../../../../../core/blitzkrieg/modelDefinitions';
import { Pose, poseEvent } from '../../../../../core/blitzkrieg/pose';
import { useTankopedia } from '../../../../../stores/tankopedia';
import { useTankopediaTemporary } from '../../../../../stores/tankopedia';
import { Duel } from '../page';
const poseDistances: Record<Pose, number> = {
@@ -55,7 +55,7 @@ export function Controls({ duel }: ControlsProps) {
camera.position.set(-4, 4, -16);
orbitControls.current?.target.set(0, antagonistGunHeight / 2, 0);
const unsubscribeTankopedia = useTankopedia.subscribe(
const unsubscribeTankopedia = useTankopediaTemporary.subscribe(
(state) => state.model.visual.controlsEnabled,
(enabled) => {
if (orbitControls.current) orbitControls.current.enabled = enabled;
@@ -144,7 +144,7 @@ export function Controls({ duel }: ControlsProps) {
return (
<OrbitControls
ref={orbitControls}
enabled={useTankopedia.getState().model.visual.controlsEnabled}
enabled={useTankopediaTemporary.getState().model.visual.controlsEnabled}
rotateSpeed={0.25}
enableDamping={false}
/>
@@ -7,9 +7,10 @@ import { modelDefinitions } from '../../../../../../core/blitzkrieg/modelDefinit
import { modelTransformEvent } from '../../../../../../core/blitzkrieg/modelTransform';
import { Pose, poseEvent } from '../../../../../../core/blitzkrieg/pose';
import { theme } from '../../../../../../stitches.config';
import mutateTankopedia, {
import {
TankopediaMode,
useTankopedia,
mutateTankopediaTemporary,
useTankopediaTemporary,
} from '../../../../../../stores/tankopedia';
import { Loader } from '../../../../components/Loader';
import { Duel } from '../../page';
@@ -30,7 +31,7 @@ export function TankSandbox({ duel }: TankSandboxProps) {
const awaitedModelDefinitions = use(modelDefinitions);
const canvasWrapper = useRef<HTMLDivElement>(null);
const [isFullScreen, setIsFullScreen] = useState(false);
const mode = useTankopedia((state) => state.mode);
const mode = useTankopediaTemporary((state) => state.mode);
const tankModelDefinition = awaitedModelDefinitions[duel.protagonist.tank.id];
const turretModelDefinition =
tankModelDefinition.turrets[duel.protagonist.turret.id];
@@ -59,7 +60,7 @@ export function TankSandbox({ duel }: TankSandboxProps) {
function handlePoseEvent(pose: Pose) {
switch (pose) {
case Pose.HullDown: {
mutateTankopedia((draft) => {
mutateTankopediaTemporary((draft) => {
const [pitch, yaw] = applyPitchYawLimits(
-Infinity,
0,
@@ -76,7 +77,7 @@ export function TankSandbox({ duel }: TankSandboxProps) {
}
case Pose.FaceHug: {
mutateTankopedia((draft) => {
mutateTankopediaTemporary((draft) => {
const [pitch, yaw] = applyPitchYawLimits(
Infinity,
0,
@@ -109,7 +110,7 @@ export function TankSandbox({ duel }: TankSandboxProps) {
useEffect(() => {
if (!duel.protagonist) return void 0;
mutateTankopedia((draft) => {
mutateTankopediaTemporary((draft) => {
[draft.model.physical.pitch, draft.model.physical.yaw] =
applyPitchYawLimits(
draft.model.physical.pitch,
@@ -141,7 +142,7 @@ export function TankSandbox({ duel }: TankSandboxProps) {
<Tabs.Root
value={mode}
onValueChange={(mode) => {
mutateTankopedia((draft) => {
mutateTankopediaTemporary((draft) => {
draft.mode = mode as TankopediaMode;
});
}}
@@ -7,8 +7,9 @@ import {
import { Button, DropdownMenu, Flex } from '@radix-ui/themes';
import { RefObject } from 'react';
import { Pose, poseEvent } from '../../../../../../../core/blitzkrieg/pose';
import mutateTankopedia, {
useTankopedia,
import {
mutateTankopediaTemporary,
useTankopediaTemporary,
} from '../../../../../../../stores/tankopedia';
interface OptionsProps {
@@ -17,8 +18,10 @@ interface OptionsProps {
}
export function Options({ isFullScreen, canvas }: OptionsProps) {
const showGrid = useTankopedia((state) => state.model.visual.showGrid);
const greenPenetration = useTankopedia(
const showGrid = useTankopediaTemporary(
(state) => state.model.visual.showGrid,
);
const greenPenetration = useTankopediaTemporary(
(state) => state.model.visual.greenPenetration,
);
const fullScreenAvailable = document.fullscreenEnabled;
@@ -65,7 +68,7 @@ export function Options({ isFullScreen, canvas }: OptionsProps) {
<DropdownMenu.CheckboxItem
checked={showGrid}
onCheckedChange={(checked) => {
mutateTankopedia((draft) => {
mutateTankopediaTemporary((draft) => {
draft.model.visual.showGrid = checked;
});
}}
@@ -76,7 +79,7 @@ export function Options({ isFullScreen, canvas }: OptionsProps) {
<DropdownMenu.CheckboxItem
checked={greenPenetration}
onCheckedChange={(checked) => {
mutateTankopedia((draft) => {
mutateTankopediaTemporary((draft) => {
draft.model.visual.greenPenetration = checked;
});
}}
@@ -15,7 +15,7 @@ import { nameToArmorId } from '../../../../../../../../../core/blitzkrieg/nameTo
import { resolveArmor } from '../../../../../../../../../core/blitzkrieg/resolveThickness';
import { useArmor } from '../../../../../../../../../hooks/useArmor';
import { useModelDefinitions } from '../../../../../../../../../hooks/useModelDefinitions';
import { useTankopedia } from '../../../../../../../../../stores/tankopedia';
import { useTankopediaTemporary } from '../../../../../../../../../stores/tankopedia';
import { Duel } from '../../../../../page';
interface ArmorHighlightingProps {
@@ -27,7 +27,7 @@ export function ArmorHighlighting({ duel }: ArmorHighlightingProps) {
const modelDefinitions = useModelDefinitions();
const turretContainer = useRef<Group>(null);
const gunContainer = useRef<Group>(null);
const initialTankopediaState = useTankopedia.getState();
const initialTankopediaState = useTankopediaTemporary.getState();
useEffect(() => {
const turretOrigin = new Vector3(
@@ -86,7 +86,7 @@ export function ArmorHighlighting({ duel }: ArmorHighlightingProps) {
turretContainer.current?.rotation.copy(turretRotation);
}
handleModelTransform(useTankopedia.getState().model.physical);
handleModelTransform(useTankopediaTemporary.getState().model.physical);
modelTransformEvent.on(handleModelTransform);
return () => {
@@ -95,7 +95,7 @@ export function ArmorHighlighting({ duel }: ArmorHighlightingProps) {
});
useEffect(() => {
const unsubscribe = useTankopedia.subscribe(
const unsubscribe = useTankopediaTemporary.subscribe(
(state) => state.mode,
(mode) => {
if (wrapper.current) wrapper.current.visible = mode === 'armor';
@@ -16,7 +16,7 @@ import { resolveArmor } from '../../../../../../../../../core/blitzkrieg/resolve
import { useArmor } from '../../../../../../../../../hooks/useArmor';
import { useModel } from '../../../../../../../../../hooks/useModel';
import { useModelDefinitions } from '../../../../../../../../../hooks/useModelDefinitions';
import { useTankopedia } from '../../../../../../../../../stores/tankopedia';
import { useTankopediaTemporary } from '../../../../../../../../../stores/tankopedia';
import { Duel } from '../../../../../page';
interface ExternalModuleMaskProps {
@@ -35,7 +35,7 @@ export const ExternalModuleMask = memo<ExternalModuleMaskProps>(({ duel }) => {
const modelDefinitions = useModelDefinitions();
const turretContainer = useRef<Group>(null);
const gunContainer = useRef<Group>(null);
const initialTankopediaState = useTankopedia.getState();
const initialTankopediaState = useTankopediaTemporary.getState();
useEffect(() => {
const turretOrigin = new Vector3(
@@ -94,7 +94,7 @@ export const ExternalModuleMask = memo<ExternalModuleMaskProps>(({ duel }) => {
turretContainer.current?.rotation.copy(turretRotation);
}
handleModelTransform(useTankopedia.getState().model.physical);
handleModelTransform(useTankopediaTemporary.getState().model.physical);
modelTransformEvent.on(handleModelTransform);
return () => {
@@ -103,7 +103,7 @@ export const ExternalModuleMask = memo<ExternalModuleMaskProps>(({ duel }) => {
});
useEffect(() => {
const unsubscribe = useTankopedia.subscribe(
const unsubscribe = useTankopediaTemporary.subscribe(
(state) => state.mode,
(mode) => {
if (wrapper.current) wrapper.current.visible = mode === 'armor';
@@ -16,7 +16,7 @@ import { resolveArmor } from '../../../../../../../../../core/blitzkrieg/resolve
import { useArmor } from '../../../../../../../../../hooks/useArmor';
import { useModel } from '../../../../../../../../../hooks/useModel';
import { useModelDefinitions } from '../../../../../../../../../hooks/useModelDefinitions';
import { useTankopedia } from '../../../../../../../../../stores/tankopedia';
import { useTankopediaTemporary } from '../../../../../../../../../stores/tankopedia';
import { Duel } from '../../../../../page';
interface SpacedArmorDepthProps {
@@ -39,7 +39,7 @@ export const SpacedArmorDepth = memo<SpacedArmorDepthProps>(({ duel }) => {
const modelDefinitions = useModelDefinitions();
const turretContainer = useRef<Group>(null);
const gunContainer = useRef<Group>(null);
const initialTankopediaState = useTankopedia.getState();
const initialTankopediaState = useTankopediaTemporary.getState();
useEffect(() => {
if (!modelDefinitions) return;
@@ -100,7 +100,7 @@ export const SpacedArmorDepth = memo<SpacedArmorDepthProps>(({ duel }) => {
turretContainer.current?.rotation.copy(turretRotation);
}
handleModelTransform(useTankopedia.getState().model.physical);
handleModelTransform(useTankopediaTemporary.getState().model.physical);
modelTransformEvent.on(handleModelTransform);
return () => {
@@ -109,7 +109,7 @@ export const SpacedArmorDepth = memo<SpacedArmorDepthProps>(({ duel }) => {
});
useEffect(() => {
const unsubscribe = useTankopedia.subscribe(
const unsubscribe = useTankopediaTemporary.subscribe(
(state) => state.mode,
(mode) => {
if (wrapper.current) wrapper.current.visible = mode === 'armor';
@@ -22,8 +22,9 @@ import {
import { resolveJsxTree } from '../../../../../../../core/blitzkrieg/resolveJsxTree';
import { normalizeAnglePI } from '../../../../../../../core/math/normalizeAngle180';
import { useModel } from '../../../../../../../hooks/useModel';
import mutateTankopedia, {
useTankopedia,
import {
mutateTankopediaTemporary,
useTankopediaTemporary,
} from '../../../../../../../stores/tankopedia';
import { Duel } from '../../../page';
@@ -37,7 +38,7 @@ export const TankModel = memo(({ duel: { protagonist } }: TankModelProps) => {
>(undefined);
const canvas = useThree((state) => state.gl.domElement);
const physical = useTankopedia((state) => state.model.physical);
const physical = useTankopediaTemporary((state) => state.model.physical);
const hullContainer = useRef<Group>(null);
const turretContainer = useRef<Group>(null);
const gunContainer = useRef<Group>(null);
@@ -136,7 +137,7 @@ export const TankModel = memo(({ duel: { protagonist } }: TankModelProps) => {
event.stopPropagation();
if (isTrack) {
mutateTankopedia((draft) => {
mutateTankopediaTemporary((draft) => {
draft.model.visual.controlsEnabled = false;
});
@@ -158,7 +159,7 @@ export const TankModel = memo(({ duel: { protagonist } }: TankModelProps) => {
material.normalMap?.offset.add(offset);
}
function handlePointerUp() {
mutateTankopedia((draft) => {
mutateTankopediaTemporary((draft) => {
draft.model.visual.controlsEnabled = true;
});
window.removeEventListener('pointermove', handlePointerMove);
@@ -200,7 +201,7 @@ export const TankModel = memo(({ duel: { protagonist } }: TankModelProps) => {
yaw = physical.yaw;
pitch = physical.pitch;
mutateTankopedia((draft) => {
mutateTankopediaTemporary((draft) => {
draft.model.visual.controlsEnabled = false;
});
window.addEventListener('pointermove', handlePointerMove);
@@ -217,7 +218,7 @@ export const TankModel = memo(({ duel: { protagonist } }: TankModelProps) => {
modelTransformEvent.emit({ pitch, yaw });
}
function handlePointerUp() {
mutateTankopedia((state) => {
mutateTankopediaTemporary((state) => {
state.model.visual.controlsEnabled = true;
state.model.physical.pitch = normalizeAnglePI(pitch);
state.model.physical.yaw = normalizeAnglePI(yaw);
@@ -262,7 +263,7 @@ export const TankModel = memo(({ duel: { protagonist } }: TankModelProps) => {
function handlePointerDown(event: ThreeEvent<PointerEvent>) {
event.stopPropagation();
mutateTankopedia((draft) => {
mutateTankopediaTemporary((draft) => {
draft.model.visual.controlsEnabled = false;
});
pitch = physical.pitch;
@@ -280,7 +281,7 @@ export const TankModel = memo(({ duel: { protagonist } }: TankModelProps) => {
modelTransformEvent.emit({ pitch, yaw });
}
function handlePointerUp() {
mutateTankopedia((state) => {
mutateTankopediaTemporary((state) => {
state.model.visual.controlsEnabled = true;
state.model.physical.pitch = normalizeAnglePI(pitch);
state.model.physical.yaw = normalizeAnglePI(yaw);
@@ -3,8 +3,9 @@ import { use, useEffect, useRef } from 'react';
import { applyPitchYawLimits } from '../../../../../core/blitz/applyPitchYawLimits';
import { modelDefinitions } from '../../../../../core/blitzkrieg/modelDefinitions';
import { modelTransformEvent } from '../../../../../core/blitzkrieg/modelTransform';
import mutateTankopedia, {
useTankopedia,
import {
mutateTankopediaTemporary,
useTankopediaTemporary,
} from '../../../../../stores/tankopedia';
import { Duel } from '../page';
@@ -13,7 +14,7 @@ interface RotationInputsProps {
}
export function RotationInputs({ duel: { protagonist } }: RotationInputsProps) {
const physical = useTankopedia((state) => state.model.physical);
const physical = useTankopediaTemporary((state) => state.model.physical);
const awaitedModelDefinitions = use(modelDefinitions);
const turretYawInput = useRef<HTMLInputElement>(null);
const gunPitchInput = useRef<HTMLInputElement>(null);
@@ -67,7 +68,7 @@ export function RotationInputs({ duel: { protagonist } }: RotationInputsProps) {
turretModelDefinition.yaw,
);
modelTransformEvent.emit({ pitch, yaw });
mutateTankopedia((state) => {
mutateTankopediaTemporary((state) => {
state.model.physical.pitch = pitch;
state.model.physical.yaw = yaw;
});
@@ -103,7 +104,7 @@ export function RotationInputs({ duel: { protagonist } }: RotationInputsProps) {
turretModelDefinition.yaw,
);
modelTransformEvent.emit({ pitch, yaw });
mutateTankopedia((state) => {
mutateTankopediaTemporary((state) => {
state.model.physical.pitch = pitch;
state.model.physical.yaw = yaw;
});
@@ -1,9 +1,11 @@
import { Color } from 'three';
import InfiniteGridHelper from '../../../../../components/InfiniteGridHelper';
import { useTankopedia } from '../../../../../stores/tankopedia';
import { useTankopediaTemporary } from '../../../../../stores/tankopedia';
export function SceneProps() {
const showGrid = useTankopedia((state) => state.model.visual.showGrid);
const showGrid = useTankopediaTemporary(
(state) => state.model.visual.showGrid,
);
if (!showGrid) return null;