refactor: replace ref with class#23
Merged
faithia-anastasia merged 8 commits intomainfrom Mar 22, 2026
Merged
Conversation
Deploying space-simulator with
|
| Latest commit: |
39584f1
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://531b43ce.space-simulator.pages.dev |
| Branch Preview URL: | https://refactor-replace-ref-with-cl.space-simulator.pages.dev |
Contributor
Author
|
@copilot |
Contributor
There was a problem hiding this comment.
Pull request overview
Simulation ページの Three.js/物理/追尾/爆発まわりのロジックを React コンポーネントから段階的に分離し、状態管理と計算責務をクラスへ集約するリファクタです。React 側は SimulationWorld の snapshot を描画する役割に寄せられています。
Changes:
SimulationWorldを追加し、惑星の追加/削除・追尾対象・爆発の登録/完了を集約して snapshot ベースで描画- 重力計算を
GravitySystemに切り出し、惑星間の力の合算をクラスで実施 - カメラ追尾を
CameraFollowControllerに切り出し、参照管理をPlanetRegistryに統一(useRef依存を削減)
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/pages/Simulation/index.tsx | SimulationWorld の snapshot を state として保持し、追加/削除/追尾/爆発の更新を world 経由に変更。OrbitControls を state で保持。 |
| src/pages/Simulation/core/SimulationWorld.ts | 惑星/爆発/追尾IDの集約管理と snapshot 作成を担う新クラスを追加。 |
| src/pages/Simulation/core/PlanetRegistry.ts | 惑星 Mesh と位置参照の登録/参照を Map ラップで統一。 |
| src/pages/Simulation/core/GravitySystem.ts | 惑星間重力の合算ロジックをクラス化し、再利用可能なベクトルで計算。 |
| src/pages/Simulation/core/CameraFollowController.ts | 前フレームとの差分でカメラ追尾する処理をクラス化。 |
| src/pages/Simulation/components/PlanetMesh.tsx | 重力計算を GravitySystem 経由に変更し、参照登録を PlanetRegistry に統一。 |
| src/pages/Simulation/components/CameraController.tsx | 追尾処理を CameraFollowController の呼び出しラッパーに整理。 |
| src/pages/Simulation/components/Explosion.tsx | 不要になった ref を削除し、完了通知フローに合わせた軽微な整理。 |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
09fdc29 to
eed92b9
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
このPRは、SimulationページのThree.jsロジックをReactコンポーネントから段階的に分離して、責務をクラスへ寄せたリファクタです。
シミュレーション状態の中心をクラス化
SimulationWorld を追加し、惑星の追加・削除、追尾対象、爆発の登録/完了を管理するようにしました。
Simulation page は world の snapshot を描画する役割に寄っています。
重力計算をクラス化
GravitySystem を追加し、惑星間の重力合算をここで実行するように変更しました。
PlanetMesh は「現在位置を渡して力を適用する」だけになっています。
カメラ追尾ロジックをクラス化
CameraFollowController を追加し、前フレームとの差分移動でカメラを追尾させる処理を移しました。
CameraController は呼び出しのラッパーになっています。
参照管理をクラス化
PlanetRegistry を追加し、惑星メッシュと位置参照の登録/参照を統一しました。
これによりMap直操作を減らしています。
爆発ライフサイクルをworld側へ統合
SimulationWorld に爆発登録と完了処理を持たせ、
Simulation page で Explosion 完了時に world を更新する流れにしました。
Explosion component は表示とアニメーションに集中しています。
useRef削減
Simulation配下で useRef 依存を削減しました。
変更点は Simulation page, CameraController, PlanetMesh, Explosion component です。
このPRの狙い
React側は描画とイベント接続、Three.js/シミュレーションロジックはクラス側、という分離を進めて、保守性とテストしやすさを上げることです。