@combos-fun/plugin-matterjs 0.0.6 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,3 +1,27 @@
1
1
  # @combos-fun/plugin-matterjs
2
2
 
3
- Internal workspace package (Combos Fun monorepo).
3
+ @combos-fun/plugin-matterjs part of the Combos Fun engine monorepo.
4
+
5
+ Keywords: `matter-js`, `2d`, `physics`, `collision`, `rigid-body`, `gravity`.
6
+
7
+ ## Documentation
8
+
9
+ - Per-package agent / developer notes: [`agent-skill.md`](./agent-skill.md)
10
+ - Machine-readable manifest: [`combos-plugin.json`](./combos-plugin.json)
11
+ (validated against `schemas/combos-plugin.schema.json` in the repo
12
+ root)
13
+ - Entry skill (single source of truth for AI agents working with this
14
+ monorepo): `skills/combos-engine-development/SKILL.md`
15
+
16
+ When consumed from npm, the manifest and agent notes are exposed as
17
+ stable subpaths:
18
+
19
+ ```ts
20
+ import manifest from '@combos-fun/plugin-matterjs/plugin-manifest';
21
+ // or fetch the markdown directly:
22
+ // require.resolve('@combos-fun/plugin-matterjs/agent-skill')
23
+ ```
24
+
25
+ ## License
26
+
27
+ Internal workspace package, part of the Combos Fun engine monorepo.
package/agent-skill.md ADDED
@@ -0,0 +1,106 @@
1
+ # `@combos-fun/plugin-matterjs` — Agent notes
2
+
3
+ 2D physics for Combos Fun. Wraps `matter-js` ^0.20 and exposes a `PhysicsSystem` plus a `Physics` Component that auto-syncs body position / rotation to a sibling display object's `Transform` each frame.
4
+
5
+ ## When to read
6
+
7
+ Read for any 2D physics task: gravity, collisions, kinematic / static bodies, mouse constraints, rigid-body alignment with sprites.
8
+
9
+ ## Public API
10
+
11
+ ```ts
12
+ import {
13
+ PhysicsSystem,
14
+ Physics,
15
+ PhysicsType,
16
+ type PhysicsSystemParams,
17
+ } from '@combos-fun/plugin-matterjs';
18
+ ```
19
+
20
+ ### `PhysicsType`
21
+
22
+ `RECTANGLE`, `CIRCLE`, `POLYGON`.
23
+
24
+ ### `Physics` Component params
25
+
26
+ | Field | Type | Notes |
27
+ |-------|------|-------|
28
+ | `type` | `PhysicsType?` | Body shape |
29
+ | `bodyOptions` | `object?` | Matter Body options: `isStatic`, `restitution`, `frictionAir`, `density`, `friction`, ... |
30
+ | `position` | `{x, y}?` | Initial offset |
31
+ | `sides` / `radius` | `number?` | Polygon / circle |
32
+ | `stopRotation` | `boolean?` | Lock rotation sync to render transform |
33
+
34
+ Runtime fields:
35
+
36
+ - `body: Matter.Body` — set by `PhysicsSystem` after the GameObject enters the scene.
37
+
38
+ Events on the `Physics` instance:
39
+
40
+ - `'collisionStart'` — `(otherGameObject, selfGameObject) => void`
41
+ - `'collisionActive'` — same signature
42
+ - `'collisionEnd'` — same signature
43
+
44
+ ### `PhysicsSystemParams`
45
+
46
+ | Field | Type | Notes |
47
+ |-------|------|-------|
48
+ | `world` | `DeepPartial<IWorldDefinition>` | **Required**. Must include `gravity: { x, y, scale }` (e.g. `{ x: 0, y: 1, scale: 0.001 }`) |
49
+ | `resolution` | `number?` | **Must match `RendererSystem.resolution`** to keep bodies aligned with sprites |
50
+ | `fps` | `number?` | Step rate |
51
+ | `isTest` | `boolean?` | Adds a Pixi debug overlay drawn from Matter renderer |
52
+ | `mouse` | `{ open, constraint? }?` | Optional Matter mouse constraint |
53
+ | `element` / `canvas` | optional | Debug renderer mount points |
54
+
55
+ ## Required setup
56
+
57
+ - Add `RendererSystem` (from `plugin-renderer`) **before** `PhysicsSystem`.
58
+ - Match `resolution` between renderer and physics.
59
+ - Use `Transform.origin: { x: 0.5, y: 0.5 }` so the body's center aligns
60
+ with the sprite center.
61
+ - Bodies are created lazily when the `GameObject` is added to a scene.
62
+
63
+ ## Runtime behaviour
64
+
65
+ - Each frame, `PhysicsSystem` steps the Matter `Engine` and then writes the
66
+ body's `position` / `rotation` back into the sibling `Transform`.
67
+ - Pause / resume: `PhysicsSystem` automatically stops / starts the Matter
68
+ runner when `Game.pause()` / `Game.resume()` is called.
69
+
70
+ ## Common pitfalls
71
+
72
+ | Symptom | Fix |
73
+ |---------|-----|
74
+ | `gravity` complaint at runtime | Provide `world: { gravity: { x: 0, y: 1, scale: 0.001 } }` (`scale` is required) |
75
+ | Bodies misaligned with sprites | `PhysicsSystem.resolution` must match `RendererSystem.resolution` |
76
+ | Rotation drift | Use `stopRotation: true` on `Physics` if the visual must stay axis-aligned |
77
+ | Bodies pile up at origin | Set `position: { x, y }` on `Physics` constructor params |
78
+ | Cannot tap through bodies | Disable mouse constraint or `pointer-events: none` on the canvas overlay |
79
+
80
+ ## Minimal example
81
+
82
+ ```ts
83
+ import { Game, GameObject, Transform } from '@combos-fun/engine';
84
+ import { RendererSystem } from '@combos-fun/plugin-renderer';
85
+ import { GraphicsSystem, Graphics } from '@combos-fun/plugin-renderer-graphics';
86
+ import { PhysicsSystem, Physics, PhysicsType } from '@combos-fun/plugin-matterjs';
87
+
88
+ const game = new Game({
89
+ systems: [
90
+ new RendererSystem({ canvas, width: 750, height: 1334 }),
91
+ new GraphicsSystem(),
92
+ new PhysicsSystem({ world: { gravity: { x: 0, y: 1, scale: 0.001 } } }),
93
+ ],
94
+ });
95
+
96
+ const ball = new GameObject('ball');
97
+ ball.addComponent(new Transform({ position: { x: 375, y: 100 }, origin: { x: 0.5, y: 0.5 } }));
98
+ ball.addComponent(new Graphics(/* draw a circle */));
99
+ ball.addComponent(new Physics({ type: PhysicsType.CIRCLE, radius: 25 }));
100
+ ```
101
+
102
+ ## Verification
103
+
104
+ - `pnpm --filter @combos-fun/plugin-matterjs run build`
105
+ - Run a 2D example with physics; bodies should fall under gravity, collide,
106
+ and stay aligned with sprites.
@@ -0,0 +1,11 @@
1
+ {
2
+ "name": "@combos-fun/plugin-matterjs",
3
+ "pluginId": "matterjs",
4
+ "category": "physics",
5
+ "dimension": "2d",
6
+ "isCore": false,
7
+ "keywords": ["matter-js", "2d", "physics", "collision", "rigid-body", "gravity"],
8
+ "agentSkill": "./agent-skill.md",
9
+ "requires": ["@combos-fun/engine", "@combos-fun/plugin-renderer"],
10
+ "exports": ["PhysicsSystem", "Physics", "PhysicsType"]
11
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@combos-fun/plugin-matterjs",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "description": "@combos-fun/plugin-matterjs",
5
5
  "main": "index.js",
6
6
  "module": "dist/plugin-matterjs.esm.js",
@@ -8,8 +8,22 @@
8
8
  "unpkg": "dist/CombosFun.plugin.renderer.matterjs.min.js",
9
9
  "files": [
10
10
  "index.js",
11
- "dist"
11
+ "dist",
12
+ "agent-skill.md",
13
+ "combos-plugin.json"
12
14
  ],
15
+ "exports": {
16
+ ".": {
17
+ "import": "./dist/plugin-matterjs.esm.js",
18
+ "require": "./index.js",
19
+ "types": "./dist/plugin-matterjs.d.ts"
20
+ },
21
+ "./plugin-manifest": "./combos-plugin.json",
22
+ "./agent-skill": "./agent-skill.md"
23
+ },
24
+ "combos": {
25
+ "pluginManifest": "./combos-plugin.json"
26
+ },
13
27
  "types": "dist/plugin-matterjs.d.ts",
14
28
  "keywords": [
15
29
  "combos-fun",
@@ -21,7 +35,7 @@
21
35
  "matter-js": "^0.20.0",
22
36
  "pixi.js": "^8.18.1",
23
37
  "poly-decomp": "^0.3.0",
24
- "@combos-fun/engine": "0.0.6"
38
+ "@combos-fun/engine": "0.0.8"
25
39
  },
26
40
  "scripts": {
27
41
  "build": "node ../../scripts/build-package.mjs"