Skip to content

refactor: replace ref with class#23

Merged
faithia-anastasia merged 8 commits intomainfrom
refactor/replace-ref-with-class
Mar 22, 2026
Merged

refactor: replace ref with class#23
faithia-anastasia merged 8 commits intomainfrom
refactor/replace-ref-with-class

Conversation

@tknkaa
Copy link
Contributor

@tknkaa tknkaa commented Mar 19, 2026

概要
このPRは、SimulationページのThree.jsロジックをReactコンポーネントから段階的に分離して、責務をクラスへ寄せたリファクタです。

  1. シミュレーション状態の中心をクラス化
    SimulationWorld を追加し、惑星の追加・削除、追尾対象、爆発の登録/完了を管理するようにしました。
    Simulation page は world の snapshot を描画する役割に寄っています。

  2. 重力計算をクラス化
    GravitySystem を追加し、惑星間の重力合算をここで実行するように変更しました。
    PlanetMesh は「現在位置を渡して力を適用する」だけになっています。

  3. カメラ追尾ロジックをクラス化
    CameraFollowController を追加し、前フレームとの差分移動でカメラを追尾させる処理を移しました。
    CameraController は呼び出しのラッパーになっています。

  4. 参照管理をクラス化
    PlanetRegistry を追加し、惑星メッシュと位置参照の登録/参照を統一しました。
    これによりMap直操作を減らしています。

  5. 爆発ライフサイクルをworld側へ統合
    SimulationWorld に爆発登録と完了処理を持たせ、
    Simulation page で Explosion 完了時に world を更新する流れにしました。
    Explosion component は表示とアニメーションに集中しています。

  6. useRef削減
    Simulation配下で useRef 依存を削減しました。
    変更点は Simulation page, CameraController, PlanetMesh, Explosion component です。

このPRの狙い
React側は描画とイベント接続、Three.js/シミュレーションロジックはクラス側、という分離を進めて、保守性とテストしやすさを上げることです。

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Mar 19, 2026

Deploying space-simulator with  Cloudflare Pages  Cloudflare Pages

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

View logs

@tknkaa
Copy link
Contributor Author

tknkaa commented Mar 19, 2026

@copilot
このPRでの変更についてまとめて

@ut-code ut-code deleted a comment from Copilot AI Mar 19, 2026
@tknkaa tknkaa changed the title refactor/replace ref with class refactor: replace ref with class Mar 19, 2026
@tknkaa tknkaa requested a review from Copilot March 19, 2026 14:54
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
@tknkaa tknkaa force-pushed the refactor/replace-ref-with-class branch from 09fdc29 to eed92b9 Compare March 19, 2026 15:02
@faithia-anastasia faithia-anastasia merged commit 1f4fb61 into main Mar 22, 2026
1 check passed
@faithia-anastasia faithia-anastasia deleted the refactor/replace-ref-with-class branch March 22, 2026 01:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants