From 7036b7b0f95d8c12d53187f76fc1e2204199f07d Mon Sep 17 00:00:00 2001 From: Tom Boullay Date: Mon, 11 May 2026 11:47:20 +0200 Subject: [PATCH] fix: preload repair mission assets --- src/components/three/gameplay/RepairGame.tsx | 40 +++++++++++++++++++- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/src/components/three/gameplay/RepairGame.tsx b/src/components/three/gameplay/RepairGame.tsx index 37b61f9..b017c45 100644 --- a/src/components/three/gameplay/RepairGame.tsx +++ b/src/components/three/gameplay/RepairGame.tsx @@ -1,4 +1,5 @@ -import { Suspense, useEffect, useState } from "react"; +import { Suspense, useEffect, useMemo, useState } from "react"; +import { useGLTF } from "@react-three/drei"; import { ExplodableModel } from "@/components/three/models/ExplodableModel"; import type { RepairCasePlaceholder } from "@/components/three/gameplay/RepairCaseModel"; import { RepairCompletionStep } from "@/components/three/gameplay/RepairCompletionStep"; @@ -10,8 +11,12 @@ import { RepairScanSequence, type RepairScannedBrokenPart, } from "@/components/three/gameplay/RepairScanSequence"; +import { REPAIR_CASE_MODEL_PATH } from "@/data/gameplay/repairCaseConfig"; import { REPAIR_FRAGMENTATION_SEQUENCE_SECONDS } from "@/data/gameplay/repairGameConfig"; -import { REPAIR_MISSIONS } from "@/data/gameplay/repairMissions"; +import { + REPAIR_MISSIONS, + type RepairMissionConfig, +} from "@/data/gameplay/repairMissions"; import { useRepairFragmentationInput } from "@/hooks/gameplay/useRepairFragmentationInput"; import { useRepairMissionStep } from "@/hooks/gameplay/useRepairMissionStep"; import type { RepairMissionId } from "@/types/gameplay/repairMission"; @@ -27,6 +32,23 @@ interface RepairGameProps extends Required< scale?: ModelTransformProps["scale"]; } +interface RepairMissionAssetPreloaderProps { + config: RepairMissionConfig; +} + +function RepairMissionAssetPreloader({ + config, +}: RepairMissionAssetPreloaderProps): null { + const modelPaths = useMemo( + () => getRepairMissionModelPaths(config), + [config], + ); + + useGLTF(modelPaths); + + return null; +} + export function RepairGame({ mission, position, @@ -71,6 +93,9 @@ export function RepairGame({ return ( + + + {step === "waiting" ? ( ); } + +function getRepairMissionModelPaths(config: RepairMissionConfig): string[] { + return [ + ...new Set([ + REPAIR_CASE_MODEL_PATH, + config.modelPath, + ...config.brokenParts.flatMap((part) => part.modelPath ?? []), + ...config.replacementParts.flatMap((part) => part.modelPath ?? []), + ]), + ]; +}