Skip to content

feat(examples): Tiled+physics examples + ObjectLayer→collider bridge (B3)#160

Merged
Exoridus merged 1 commit into
mainfrom
feat/v0.14-b3-examples
Jun 22, 2026
Merged

feat(examples): Tiled+physics examples + ObjectLayer→collider bridge (B3)#160
Exoridus merged 1 commit into
mainfrom
feat/v0.14-b3-examples

Conversation

@Exoridus

Copy link
Copy Markdown
Owner

What

Adds the v0.14 Phase 4 B3 deliverable: two runnable combined Tiled + physics examples plus a reusable ObjectLayer → collider bridge recipe, exercising the freshly-merged B1 (free body construction + world.add/world.attach, #156) and B2 (typed ObjectLayer schema, #157) APIs.

New examples (examples/physics/)

  • sprite-follows-body — the minimal binding: world.attach(sprite, { … }) builds a body + collider and binds it; the sprite tracks the body each world.step, falling onto a static floor (Kenney platformer character).
  • tiled-map-physics-actor — a hand-built TileMap rendered via TileMapNode (tilemap extension), an ObjectLayer of solid regions, the bridge turning that layer into static PhysicsBodys, and a dynamic actor that falls/bounces. The physics /debug overlay outlines every generated collider.

The bridge — examples/shared/physics-tilemap.ts

buildCollidersFromObjectLayer(world, layer, options) walks an ObjectLayer and adds one static body per closed-area object: Rectangle→BoxShape, Polygon→PolygonShape (convex; concave skipped with a warning), Ellipse→CircleShape (larger semi-axis). Point/polyline/tile are skipped. Forwards friction/restitution/filter and supports a custom accept predicate.

Placement rationale: the bridge lives in example/app land, not in either package. @codexo/exojs-tilemap must never depend on @codexo/exojs-physics and vice-versa (the B4/D4 ADR, #158, keeps geometry shared but collision detection separate). The recipe is the only place that legitimately depends on both, so app-land is the correct, coupling-free home — and it stays a copy-paste recipe rather than engine API.

Tests

test/site/physics-tilemap-bridge.test.ts (8 cases) drives the recipe end-to-end against the real (aliased-to-source) packages: rectangle/ellipse/polygon mapping + centring, skip rules, non-convex warn-and-skip, option forwarding, the accept predicate, and an integration test where a dynamic box comes to rest on a bridge-built floor.

Wiring

  • tsconfig.examples.json: @codexo/exojs-physics + /debug path mappings.
  • vitest.config.ts: @codexo/exojs-physics source alias (so the bridge test resolves).
  • eslint.config.ts: example .js import-sort collapsed to a single group — the examples:sync transpile strips blank lines between import groups, so an example mixing a package import with a relative recipe import could otherwise never lint clean.
  • examples/examples.json + site/src/lib/chapters.ts: new Physics category (catalog↔chapters parity is asserted in examples-catalog.test.ts).
  • site/public/preview.html + site/scripts/sync-exo-vendor.ts: physics (+ /debug) and tilemap (+ /register) added to the playground import map and vendor sync so the examples actually run in the playground.

Verification (all green locally; CI builds no dist)

  • pnpm typecheck:examples
  • pnpm lint (examples) + pnpm lint:packages
  • pnpm format:check
  • pnpm --filter @codexo/exojs-examples examples:sync (generated .js + catalog committed) ✓
  • Bridge test ✓; full exojs project (2377) + exojs-physics/exojs-tilemap (352) ✓

Not merged.

@chatgpt-codex-connector

Copy link
Copy Markdown

To use Codex here, create an environment for this repo.

@Exoridus Exoridus merged commit e58f52c into main Jun 22, 2026
12 checks passed
@Exoridus Exoridus deleted the feat/v0.14-b3-examples branch June 22, 2026 17:07
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