From 79b400fb00f18f8c4bad5c14252670b2df4de1f7 Mon Sep 17 00:00:00 2001
From: tknkaa
Date: Thu, 19 Mar 2026 22:20:39 +0800
Subject: [PATCH 1/8] refactor(simulation): extract camera follow and registry
classes
---
.../components/CameraController.tsx | 63 +++++--------------
.../Simulation/components/PlanetMesh.tsx | 21 ++-----
.../Simulation/core/CameraFollowController.ts | 53 ++++++++++++++++
src/pages/Simulation/core/PlanetRegistry.ts | 42 +++++++++++++
src/pages/Simulation/index.tsx | 8 +--
5 files changed, 118 insertions(+), 69 deletions(-)
create mode 100644 src/pages/Simulation/core/CameraFollowController.ts
create mode 100644 src/pages/Simulation/core/PlanetRegistry.ts
diff --git a/src/pages/Simulation/components/CameraController.tsx b/src/pages/Simulation/components/CameraController.tsx
index 569d4de..22a621f 100644
--- a/src/pages/Simulation/components/CameraController.tsx
+++ b/src/pages/Simulation/components/CameraController.tsx
@@ -1,17 +1,12 @@
import { useFrame, useThree } from "@react-three/fiber";
-import { useMemo, useRef } from "react";
-import * as THREE from "three";
+import { useEffect, useMemo } from "react";
import type { OrbitControls } from "three-stdlib";
-
-// 惑星レジストリのエントリの型を定義
-type PlanetRegistryEntry = {
- mesh: THREE.Mesh;
- position: React.MutableRefObject;
-};
+import { CameraFollowController } from "../core/CameraFollowController";
+import type { PlanetRegistry } from "../core/PlanetRegistry";
type CameraControllerProps = {
followedPlanetId: string | null;
- planetRegistry: React.MutableRefObject
- {followedPlanetId && (
+ {worldState.followedPlanetId && (
追尾中: {(() => {
- const planet = planets.find(
- (p) => p.id === followedPlanetId,
+ const planet = worldState.planets.find(
+ (p) => p.id === worldState.followedPlanetId,
);
return planet ? (
<>
@@ -278,7 +248,10 @@ export default function Page() {
)}
-
追加済み惑星 ({planets.length})
+
追加済み惑星 ({worldState.planets.length})
- {planets.map((planet) => (
+ {worldState.planets.map((planet) => (
-
- {followedPlanetId === planet.id ? (
+ {worldState.followedPlanetId === planet.id ? (
追尾中
) : (