mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-11-19 11:53:25 +01:00
feat: persistant tankopedia
This commit is contained in:
1 parent
f51e365ec4
commit
a70100c835
17 files changed
+156
-126
No files matched your search
@@ -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;
|
||||
});
|
||||
}}
|
||||
|
||||
+4
-4
@@ -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';
|
||||
|
||||
+4
-4
@@ -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';
|
||||
|
||||
+4
-4
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user