its functionning
This commit is contained in:
+27
-5
@@ -1,9 +1,10 @@
|
||||
import { Suspense, useEffect } from "react";
|
||||
import { Suspense, useEffect, useRef } from "react";
|
||||
import { Physics } from "@react-three/rapier";
|
||||
import {
|
||||
PLAYER_SPAWN_POSITION_GAME,
|
||||
PLAYER_SPAWN_POSITION_PHYSICS,
|
||||
} from "@/data/player/playerConfig";
|
||||
import { useRepairTransitionStore } from "@/managers/stores/useRepairTransitionStore";
|
||||
import { useCameraMode } from "@/hooks/debug/useCameraMode";
|
||||
import { useEnvironmentDebug } from "@/hooks/debug/useEnvironmentDebug";
|
||||
import { useMapPerformanceDebug } from "@/hooks/debug/useMapPerformanceDebug";
|
||||
@@ -53,10 +54,31 @@ export function World({ onLoadingStateChange }: WorldProps): React.JSX.Element {
|
||||
handleShadowWarmupStarted,
|
||||
shouldWarmUpShadows,
|
||||
} = useWorldSceneLoading({ sceneMode, onLoadingStateChange });
|
||||
const playerSpawnPosition =
|
||||
sceneMode === "game"
|
||||
? PLAYER_SPAWN_POSITION_GAME
|
||||
: PLAYER_SPAWN_POSITION_PHYSICS;
|
||||
// Capture the spawn position once on mount via a ref so it never changes
|
||||
// mid-session (spawnPosition is reactive in Player and would re-spawn the
|
||||
// character on every prop change). If the player returns from a repair
|
||||
// scene, savedPlayerPosition holds their world position; otherwise fall
|
||||
// back to the default spawn from playerConfig.
|
||||
const savedPlayerPosition = useRepairTransitionStore(
|
||||
(s) => s.savedPlayerPosition,
|
||||
);
|
||||
const playerSpawnPositionRef = useRef(
|
||||
savedPlayerPosition ??
|
||||
(sceneMode === "game"
|
||||
? PLAYER_SPAWN_POSITION_GAME
|
||||
: PLAYER_SPAWN_POSITION_PHYSICS),
|
||||
);
|
||||
const playerSpawnPosition = playerSpawnPositionRef.current;
|
||||
|
||||
// Clear the saved position right after capturing it so the next world
|
||||
// mount uses the default spawn instead of the stale repair-exit position.
|
||||
useEffect(() => {
|
||||
if (savedPlayerPosition !== null) {
|
||||
useRepairTransitionStore.getState().setSavedPlayerPosition(null);
|
||||
}
|
||||
// Only on mount — intentionally no deps
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, []);
|
||||
const showHandTrackingGloves =
|
||||
sceneMode === "physics" ||
|
||||
(status !== "idle" && usageStatus !== "inactive");
|
||||
|
||||
Reference in New Issue
Block a user