feat(examples): Tiled+physics examples + ObjectLayer→collider bridge (B3)#160
Merged
Conversation
|
To use Codex here, create an environment for this repo. |
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.
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 (typedObjectLayerschema, #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 eachworld.step, falling onto a static floor (Kenney platformer character).tiled-map-physics-actor— a hand-builtTileMaprendered viaTileMapNode(tilemap extension), anObjectLayerof solid regions, the bridge turning that layer into staticPhysicsBodys, and a dynamic actor that falls/bounces. The physics/debugoverlay outlines every generated collider.The bridge —
examples/shared/physics-tilemap.tsbuildCollidersFromObjectLayer(world, layer, options)walks anObjectLayerand 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 customacceptpredicate.Placement rationale: the bridge lives in example/app land, not in either package.
@codexo/exojs-tilemapmust never depend on@codexo/exojs-physicsand 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, theacceptpredicate, and an integration test where a dynamic box comes to rest on a bridge-built floor.Wiring
tsconfig.examples.json:@codexo/exojs-physics+/debugpath mappings.vitest.config.ts:@codexo/exojs-physicssource alias (so the bridge test resolves).eslint.config.ts: example.jsimport-sort collapsed to a single group — theexamples:synctranspile 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 inexamples-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) ✓exojsproject (2377) +exojs-physics/exojs-tilemap(352) ✓Not merged.