refactor: move mission flow state into game store
🔍 Lint / 🪄 Check lint (pull_request) Has been cancelled
🔍 Lint / 🎨 Check format (pull_request) Has been cancelled
🔍 Lint / 🔎 Typecheck (pull_request) Has been cancelled
🔍 Lint / 🏗 Build (pull_request) Has been cancelled
📊 Quality / 🔒 Security Audit (pull_request) Has been cancelled
📊 Quality / 📋 Dependency Freshness (pull_request) Has been cancelled
📊 Quality / 📦 Bundle Size (pull_request) Has been cancelled

This commit is contained in:
Tom Boullay
2026-05-11 18:02:00 +02:00
parent 91ebea8d99
commit 2c3f0db65b
21 changed files with 461 additions and 188 deletions
+5 -5
View File
@@ -1,13 +1,13 @@
import { useEffect, useRef } from "react";
import { AudioManager } from "@/managers/AudioManager";
import { useMissionFlowStore } from "@/managers/stores/useMissionFlowStore";
import { useGameStore } from "@/managers/stores/useGameStore";
import { AUDIO_PATHS } from "@/data/audioConfig";
export function GameFlow(): null {
const step = useMissionFlowStore((state) => state.step);
const setStep = useMissionFlowStore((state) => state.setStep);
const setActivityCity = useMissionFlowStore((state) => state.setActivityCity);
const setCanMove = useMissionFlowStore((state) => state.setCanMove);
const step = useGameStore((state) => state.missionFlow.step);
const setStep = useGameStore((state) => state.setFlowStep);
const setActivityCity = useGameStore((state) => state.setActivityCity);
const setCanMove = useGameStore((state) => state.setCanMove);
const hasInitialized = useRef(false);
useEffect(() => {
@@ -1,5 +1,5 @@
import { InteractableObject } from "@/components/three/interaction/InteractableObject";
import { useMissionFlowStore } from "@/managers/stores/useMissionFlowStore";
import { useGameStore } from "@/managers/stores/useGameStore";
import { Debug } from "@/utils/debug/Debug";
import type { Vector3Tuple } from "@/types/three/three";
@@ -10,10 +10,10 @@ interface CentralObjectProps {
export function CentralObject({
position,
}: CentralObjectProps): React.JSX.Element {
const step = useMissionFlowStore((state) => state.step);
const setStep = useMissionFlowStore((state) => state.setStep);
const setCanMove = useMissionFlowStore((state) => state.setCanMove);
const showDialog = useMissionFlowStore((state) => state.showDialog);
const step = useGameStore((state) => state.missionFlow.step);
const setStep = useGameStore((state) => state.setFlowStep);
const setCanMove = useGameStore((state) => state.setCanMove);
const showDialog = useGameStore((state) => state.showDialog);
const debug = Debug.getInstance();
const handlePress = (): void => {
@@ -1,5 +1,5 @@
import { InteractableObject } from "@/components/three/interaction/InteractableObject";
import { useMissionFlowStore } from "@/managers/stores/useMissionFlowStore";
import { useGameStore } from "@/managers/stores/useGameStore";
import { Debug } from "@/utils/debug/Debug";
import type { Vector3Tuple } from "@/types/three/three";
@@ -10,8 +10,8 @@ interface VillageoisHelperObjectProps {
export function VillageoisHelperObject({
position,
}: VillageoisHelperObjectProps): React.JSX.Element {
const step = useMissionFlowStore((state) => state.step);
const setStep = useMissionFlowStore((state) => state.setStep);
const step = useGameStore((state) => state.missionFlow.step);
const setStep = useGameStore((state) => state.setFlowStep);
const debug = Debug.getInstance();
const handlePress = (): void => {
+6 -6
View File
@@ -1,10 +1,10 @@
import { useState } from "react";
import { useMissionFlowStore } from "@/managers/stores/useMissionFlowStore";
import { useGameStore } from "@/managers/stores/useGameStore";
export function IntroUI(): React.JSX.Element | null {
const step = useMissionFlowStore((state) => state.step);
const setPlayerName = useMissionFlowStore((state) => state.setPlayerName);
const setStep = useMissionFlowStore((state) => state.setStep);
const step = useGameStore((state) => state.missionFlow.step);
const setPlayerName = useGameStore((state) => state.setPlayerName);
const setStep = useGameStore((state) => state.setFlowStep);
const [inputValue, setInputValue] = useState("");
if (step !== "naming") return null;
@@ -100,8 +100,8 @@ export function IntroUI(): React.JSX.Element | null {
}
export function BienvenueDisplay(): React.JSX.Element | null {
const step = useMissionFlowStore((state) => state.step);
const playerName = useMissionFlowStore((state) => state.playerName);
const step = useGameStore((state) => state.missionFlow.step);
const playerName = useGameStore((state) => state.missionFlow.playerName);
if (step !== "bienvenue") return null;
+6 -7
View File
@@ -2,8 +2,7 @@ import { useEffect, useRef, useState } from "react";
import { useFrame, useThree } from "@react-three/fiber";
import * as THREE from "three";
import { ZONES } from "@/data/zones";
import { GameStepManager } from "@/managers/GameStepManager";
import { useMissionFlowStore } from "@/managers/stores/useMissionFlowStore";
import { useGameStore } from "@/managers/stores/useGameStore";
import { Debug } from "@/utils/debug/Debug";
import type { GameStep } from "@/types/game";
@@ -25,10 +24,10 @@ const GAME_STEPS: GameStep[] = [
export function ZoneDetection(): null {
const camera = useThree((state) => state.camera);
const manager = GameStepManager.getInstance();
const triggeredZones = useRef<Set<string>>(new Set());
const debug = Debug.getInstance();
const step = useMissionFlowStore((state) => state.step);
const step = useGameStore((state) => state.missionFlow.step);
const setStep = useGameStore((state) => state.setFlowStep);
useEffect(() => {
if (!debug.active) return;
@@ -45,8 +44,8 @@ export function ZoneDetection(): null {
folder.add(playerPos, "y").name("Player Y").listen().disable();
folder.add(playerPos, "z").name("Player Z").listen().disable();
const unsubStore = useMissionFlowStore.subscribe((state) => {
gameState.step = state.step;
const unsubStore = useGameStore.subscribe((state) => {
gameState.step = state.missionFlow.step;
folder.controllersRecursive().forEach((c) => c.updateDisplay());
});
@@ -79,7 +78,7 @@ export function ZoneDetection(): null {
const distanceSq = _playerPos.distanceToSquared(_zonePos);
if (distanceSq <= zone.radius * zone.radius) {
manager.transitionTo(zone.targetStep);
setStep(zone.targetStep);
triggeredZones.current.add(zone.id);
break;
}