Skip to content

refactor(collision): align CollisionComponent with CameraComponent architecture#8871

Merged
willeastcott merged 2 commits into
mainfrom
refactor-collision-component-architecture
Jun 11, 2026
Merged

refactor(collision): align CollisionComponent with CameraComponent architecture#8871
willeastcott merged 2 commits into
mainfrom
refactor-collision-component-architecture

Conversation

@willeastcott

Copy link
Copy Markdown
Contributor

Description

Migrates CollisionComponent to the architecture established by CameraComponent and applied in #8666 (light), #8693 (scrollbar), #8777 (scrollview) and #8870 (button).

What changed

  • component.js — owns its 14 properties as private class fields with real setters/getters. The _setValue indirection, the 12 set_* listener registrations and all onSet* handlers are gone; side effects are inlined in the setters, gated on _initialized. The init-time array conversions move into the halfExtents/linearOffset/angularOffset setters (including 3-element euler arrays for angularOffset), so they now also work post-initialization instead of storing raw arrays. Vec3/Quat inputs are copied so caller mutations do not leak; these setters have no equality early-return, so the documented mutate-then-reassign idiom still rebuilds the shape.
  • system.js — the seven CollisionSystemImpl classes operate on the component directly instead of a separate data object, writing private fields where a public setter would double-rebuild the shape (mesh loadAsset, asset clearing). The type-independent impl remove()/clone() are hoisted into the system as onRemove/cloneComponent — necessary because the post-removal remove event payload no longer carries type. initializeComponentData preserves the load-bearing ordering: type resolved first via a direct private write, asset-over-model/render pruning, property loop through inert setters, beforeInitialize, enabled via super, then afterInitialize. The enabled accessor is generated by Component._buildAccessors.
  • data.js — reduced to a single enabled field.
  • trigger.js — drops the redundant data constructor param and reads component.shape (Trigger is not publicly exported).
  • rigid-body/component.js_updateDynamic reads the collision offsets via their public getters instead of collision.data.

Adds a 26-test suite modelled on the ButtonComponent tests (defaults, round-trips, array conversions, asset id normalization and listener cleanup, type changes, per-type shape-recreation gating, offsets, clone fidelity, removal lifecycle).

Notes for reviewers

  • The pre-existing always-true if (!component.rigidbody) check in recreatePhysicalShapes (almost certainly meant entity.rigidbody) is preserved verbatim — fixing it changes compound physics behavior and belongs in its own PR.
  • Cloning a collision component still drops procedurally-assigned model/render (the clone data always carries an asset key, which wins the priority pruning) — preserved bug-for-bug.
  • Verified: full test suite (1796 passing), lint, types build + tsc check. Node tests cannot load Ammo, so a browser pass of physics/falling-shapes, physics/compound-collision and physics/offset-collision is recommended before merge.

Checklist

  • I have read the contributing guidelines
  • My code follows the project's coding standards
  • This PR focuses on a single change

🤖 Generated with Claude Code

…chitecture

CollisionComponent now owns its 14 properties as private fields with
real setters/getters, inlining the side effects that previously lived
in set_* event listeners. CollisionComponentData is reduced to a single
enabled field. The system drives initializeComponentData from an
explicit _properties list, hoists the type-independent impl remove()
and clone() into onRemove/cloneComponent (the post-removal 'remove'
event no longer carries type), and builds the enabled accessor via
Component._buildAccessors.

The old init-time array conversions move into the halfExtents,
linearOffset and angularOffset setters (including 3-element euler
arrays), so they now also work post-initialization instead of storing
raw arrays. Vec3/Quat inputs are copied so caller mutations do not
leak; the vec/quat setters have no equality early-return so the
documented mutate-then-reassign idiom still rebuilds the shape. The
CollisionSystemImpl classes operate on the component directly, writing
private fields where a public setter would double-rebuild the shape
(mesh loadAsset, asset clearing). Trigger drops its redundant data
constructor param and RigidBodyComponent reads the collision offsets
via their public getters.

Adds a 26-test suite modelled on the ButtonComponent tests.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Jun 11, 2026

Copy link
Copy Markdown

Public API report

This PR changes the public API surface (+5 / −5), per the docs' rules (@ignore / @Private / undocumented are excluded).

Show API diff
-ModelComponent.get type(): "box" | "plane" | "asset" | "sphere" | "capsule" | "cylinder" | "cone" | "torus"
+ModelComponent.get type(): "box" | "plane" | "sphere" | "capsule" | "cylinder" | "cone" | "asset" | "torus"
-ModelComponent.set type(value: "box" | "plane" | "asset" | "sphere" | "capsule" | "cylinder" | "cone" | "torus")
+ModelComponent.set type(value: "box" | "plane" | "sphere" | "capsule" | "cylinder" | "cone" | "asset" | "torus")
-RenderComponent.get type(): "box" | "plane" | "asset" | "sphere" | "capsule" | "cylinder" | "cone" | "torus"
+RenderComponent.get type(): "box" | "plane" | "sphere" | "capsule" | "cylinder" | "cone" | "asset" | "torus"
-RenderComponent.set type(value: "box" | "plane" | "asset" | "sphere" | "capsule" | "cylinder" | "cone" | "torus")
+RenderComponent.set type(value: "box" | "plane" | "sphere" | "capsule" | "cylinder" | "cone" | "asset" | "torus")
-Trigger.constructor(app: AppBase, component: Component, data: any)
+Trigger.constructor(app: AppBase, component: CollisionComponent)

Informational only — this never fails the build.

@willeastcott willeastcott requested a review from Copilot June 11, 2026 13:43
@willeastcott willeastcott self-assigned this Jun 11, 2026
@willeastcott willeastcott added the enhancement Request for a new feature label Jun 11, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Refactors CollisionComponent to follow the “component owns its state via private fields + real accessors” architecture used by CameraComponent and subsequent component migrations, reducing reliance on *ComponentData property bags and moving shape-recreation side effects into property setters.

Changes:

  • Migrates CollisionComponent state into private fields with explicit getters/setters and removes the old _setValue + set_* listener plumbing.
  • Updates CollisionComponentSystem and per-type implementations to operate directly on the component fields (and hoists removal/clone behavior into the system).
  • Adds a new collision component test suite and updates dependent code (Trigger, RigidBodyComponent) to use the new accessors.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
test/framework/components/collision/component.test.mjs Adds a comprehensive regression suite for defaults, conversions, cloning, offsets, lifecycle, and shape recreation behavior.
src/framework/components/rigid-body/component.js Switches offset reads from collision.data.* to collision.* accessors.
src/framework/components/collision/trigger.js Removes the redundant data parameter and reads component.shape directly.
src/framework/components/collision/system.js Refactors initialization/clone/removal and per-type implementations to operate on component fields; builds enabled accessor via schema.
src/framework/components/collision/data.js Reduces the data class to enabled only.
src/framework/components/collision/component.js Introduces private fields + real setters/getters and inlines side effects previously handled by set_* event handlers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/framework/components/collision/system.js
The old initializer defaulted falsy type inputs (null, empty string) to
the current data type; the migrated code applied any defined value,
letting null reach _createImplementation and crash on
impl.beforeInitialize. Resolve type solely up front with a truthiness
guard and drop it from _properties - leaving it in the generic loop
would push a falsy-but-defined value through the type setter and fire
changeType pre-init.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Comment thread src/framework/components/collision/system.js
@willeastcott willeastcott merged commit 52c3a6c into main Jun 11, 2026
10 checks passed
@willeastcott willeastcott deleted the refactor-collision-component-architecture branch June 11, 2026 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Request for a new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants