feat(repair): make fragmented -> scanning event-driven via onSplitSettled

The fragmented -> scanning transition used to fire on a blind
setTimeout of REPAIR_FRAGMENTATION_SEQUENCE_SECONDS regardless of
whether the explode lerp had actually finished. With the new sphere-
reveal flow this got out of sync (sphere grows for 2.5s before
fragmented even mounts), so the timer could fire too early or while
the parts were still flying out.

Now the ExplodedModel emits a single 'settled' callback when its
internal lerp converges on its target (1 = fully exploded, 0 = fully
reassembled). RepairGame listens for settled-at-1 on the fragmented
ExplodableModel and advances to scanning on that event.

The legacy timer is kept as a generous safety net
(REPAIR_FRAGMENTATION_SEQUENCE_SECONDS + 2 seconds) so that if the
model fails to load (no parts -> no settled event ever fires) the
flow can never get stuck on the fragmented step.

Changes:
- ExplodedModel.ts:
  - new ExplodedModelOptions.onSettled: (settledAt: 0 | 1) => void
  - track settledAtTarget to ensure the callback fires exactly once
    per lerp (re-armed when setSplit() flips the target).
- ExplodableModel.tsx: new onSplitSettled prop, forwarded to the
  underlying ExplodedModel via a stable useCallback that reads the
  latest prop through a ref so the instance is not recreated mid-anim.
- RepairGame.tsx:
  - wire onSplitSettled on the fragmented ExplodableModel to
    setMissionStep(mission, 'scanning').
  - keep the existing setTimeout but extend it as a fallback only.

Pylon and farm benefit from the same fix automatically since they
share the same RepairGame fragmented branch.
This commit is contained in:
Tom Boullay
2026-06-03 04:18:10 +02:00
parent fe30596a5a
commit 317db48bcc
3 changed files with 65 additions and 7 deletions
+17 -3
View File
@@ -149,14 +149,25 @@ export function RepairGame({
};
}, [mainState, mission, setMissionStep, step]);
// fragmented -> scanning is now driven by `onSplitSettled` from the
// ExplodableModel below (fires once the lerp actually converges on
// progress=1). The legacy REPAIR_FRAGMENTATION_SEQUENCE_SECONDS timer
// is kept as a safety-net fallback in case the model fails to load
// (no part anchors -> no settled event) so the flow can never get
// stuck on the fragmented step.
useEffect(() => {
if (mainState !== mission) return undefined;
if (step !== "fragmented") return undefined;
const timeoutId = window.setTimeout(() => {
setMissionStep(mission, "scanning");
}, REPAIR_FRAGMENTATION_SEQUENCE_SECONDS * 1000);
const timeoutId = window.setTimeout(
() => {
setMissionStep(mission, "scanning");
},
// Generous fallback: actual anim usually finishes in <1s, so this
// only fires if something went wrong.
(REPAIR_FRAGMENTATION_SEQUENCE_SECONDS + 2) * 1000,
);
return () => {
window.clearTimeout(timeoutId);
@@ -185,6 +196,9 @@ export function RepairGame({
rotation={config.modelRotation ?? [0, 0, 0]}
scale={config.modelScale ?? 1}
split
onSplitSettled={(settledAt) => {
if (settledAt === 1) setMissionStep(mission, "scanning");
}}
/>
) : null}
{step === "scanning" ? (