Skip to content

refactor(engine): tween-to-galaxy helper dedup#42

Merged
rulkens merged 2 commits intomainfrom
chore/tween-to-galaxy-helper
May 7, 2026
Merged

refactor(engine): tween-to-galaxy helper dedup#42
rulkens merged 2 commits intomainfrom
chore/tween-to-galaxy-helper

Conversation

@rulkens
Copy link
Copy Markdown
Owner

@rulkens rulkens commented May 7, 2026

Summary

  • New src/services/engine/tweenToGalaxy.ts collapses three near-identical "build CameraTween from a galaxy + start it + requestRender" implementations into one helper.
  • focusOn, selectFamous, and selectByAlias each become a one-liner tweenToGalaxy(state, info) after their existing pre-tween bookkeeping (selection, onFocusChange).
  • focusOnHome keeps its bespoke tween (different toTarget / yaw / pitch shape) — no duplication to dedup there.
  • engine.ts -33 net lines (30 added, 63 removed); 50 lines of duplicated tween-construction gone.

Implementation notes

  • The helper takes a structural minimum TweenTarget = { x, y, z, diameterKpc } rather than PointInfo so the contract documents exactly what the helper reads. PointInfo is structurally compatible — production callers pass info directly.
  • Cam-null guard moved into the helper. In focusOn we keep a separate early-return ahead of cb.onFocusChange so the URL-sync hook doesn't fire during the pre-bootstrap window; in selectFamous / selectByAlias the callback already fires before the tween, so removing their local cam-null check changes nothing observable.
  • The plan's sketch had the helper read cloud.x[localIdx] / cloud.y[localIdx] / etc., but PointCloud actually stores positions as an interleaved positions: Float32Array. Each call site already builds a PointInfo (for the InfoCard / focus callback), so taking the info directly is both more correct and cheaper than re-deriving xyz inside the helper.

Test plan

  • tweenToGalaxy.test.ts (3/3): happy path, cam.target snapshot isolation, cam-null no-op
  • npx tsc --noEmit clean
  • full suite green (915 tests)
  • manual smoke: clicking a famous galaxy in the palette, Cmd+K alias select, dblclick on canvas, and the Focus button all still tween correctly

Spec: docs/superpowers/specs/2026-05-08-engine-internal-restructure-design.md
Plan: docs/superpowers/plans/2026-05-08-engine-internal-restructure.md (Phase 2)

Co-Authored-By: Claude Opus 4.7 noreply@anthropic.com

rulkens and others added 2 commits May 8, 2026 01:31
Extract the cloud-row -> camera tween dispatch shared by selectFamous,
selectByAlias, and focusOn into one helper.  Cam-null guard included
defensively for the post-destroy / pre-bootstrap race window.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…/focusOn

Three duplicated cloud-row -> camera tween dispatches collapse to one
helper call each.  ~50 lines removed from engine.ts; focusOnHome keeps
its bespoke tween (different toTarget / yaw / pitch shape).

The cam-null guard stays in focusOn ahead of cb.onFocusChange so the
URL-sync hook doesn't fire during the pre-bootstrap window; the helper's
own guard absorbs the no-op for selectFamous and selectByAlias where
the callback already fired.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
skymap 50836c5 Commit Preview URL

Branch Preview URL
May 07 2026, 11:36 PM

@rulkens rulkens merged commit e02f074 into main May 7, 2026
2 checks passed
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.

1 participant