@combos-fun/plugin-matterjs 0.0.6 → 0.0.7

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,109 @@
1
+ # `@combos-fun/plugin-matterjs` — Agent notes
2
+
3
+ 2D physics for Combos Fun. Wraps `matter-js` ^0.20 and exposes a
4
+ `PhysicsSystem` plus a `Physics` Component that auto-syncs body
5
+ position / rotation to a sibling display object's `Transform` each frame.
6
+
7
+ ## When to read
8
+
9
+ Read for any 2D physics task: gravity, collisions, kinematic / static
10
+ bodies, mouse constraints, rigid-body alignment with sprites.
11
+
12
+ ## Public API
13
+
14
+ ```ts
15
+ import {
16
+ PhysicsSystem,
17
+ Physics,
18
+ PhysicsType,
19
+ type PhysicsSystemParams,
20
+ } from '@combos-fun/plugin-matterjs';
21
+ ```
22
+
23
+ ### `PhysicsType`
24
+
25
+ `RECTANGLE`, `CIRCLE`, `POLYGON`.
26
+
27
+ ### `Physics` Component params
28
+
29
+ | Field | Type | Notes |
30
+ |-------|------|-------|
31
+ | `type` | `PhysicsType?` | Body shape |
32
+ | `bodyOptions` | `object?` | Matter Body options: `isStatic`, `restitution`, `frictionAir`, `density`, `friction`, ... |
33
+ | `position` | `{x, y}?` | Initial offset |
34
+ | `sides` / `radius` | `number?` | Polygon / circle |
35
+ | `stopRotation` | `boolean?` | Lock rotation sync to render transform |
36
+
37
+ Runtime fields:
38
+
39
+ - `body: Matter.Body` — set by `PhysicsSystem` after the GameObject enters the scene.
40
+
41
+ Events on the `Physics` instance:
42
+
43
+ - `'collisionStart'` — `(otherGameObject, selfGameObject) => void`
44
+ - `'collisionActive'` — same signature
45
+ - `'collisionEnd'` — same signature
46
+
47
+ ### `PhysicsSystemParams`
48
+
49
+ | Field | Type | Notes |
50
+ |-------|------|-------|
51
+ | `world` | `DeepPartial<IWorldDefinition>` | **Required**. Must include `gravity: { x, y, scale }` (e.g. `{ x: 0, y: 1, scale: 0.001 }`) |
52
+ | `resolution` | `number?` | **Must match `RendererSystem.resolution`** to keep bodies aligned with sprites |
53
+ | `fps` | `number?` | Step rate |
54
+ | `isTest` | `boolean?` | Adds a Pixi debug overlay drawn from Matter renderer |
55
+ | `mouse` | `{ open, constraint? }?` | Optional Matter mouse constraint |
56
+ | `element` / `canvas` | optional | Debug renderer mount points |
57
+
58
+ ## Required setup
59
+
60
+ - Add `RendererSystem` (from `plugin-renderer`) **before** `PhysicsSystem`.
61
+ - Match `resolution` between renderer and physics.
62
+ - Use `Transform.origin: { x: 0.5, y: 0.5 }` so the body's center aligns
63
+ with the sprite center.
64
+ - Bodies are created lazily when the `GameObject` is added to a scene.
65
+
66
+ ## Runtime behaviour
67
+
68
+ - Each frame, `PhysicsSystem` steps the Matter `Engine` and then writes the
69
+ body's `position` / `rotation` back into the sibling `Transform`.
70
+ - Pause / resume: `PhysicsSystem` automatically stops / starts the Matter
71
+ runner when `Game.pause()` / `Game.resume()` is called.
72
+
73
+ ## Common pitfalls
74
+
75
+ | Symptom | Fix |
76
+ |---------|-----|
77
+ | `gravity` complaint at runtime | Provide `world: { gravity: { x: 0, y: 1, scale: 0.001 } }` (`scale` is required) |
78
+ | Bodies misaligned with sprites | `PhysicsSystem.resolution` must match `RendererSystem.resolution` |
79
+ | Rotation drift | Use `stopRotation: true` on `Physics` if the visual must stay axis-aligned |
80
+ | Bodies pile up at origin | Set `position: { x, y }` on `Physics` constructor params |
81
+ | Cannot tap through bodies | Disable mouse constraint or `pointer-events: none` on the canvas overlay |
82
+
83
+ ## Minimal example
84
+
85
+ ```ts
86
+ import { Game, GameObject, Transform } from '@combos-fun/engine';
87
+ import { RendererSystem } from '@combos-fun/plugin-renderer';
88
+ import { GraphicsSystem, Graphics } from '@combos-fun/plugin-renderer-graphics';
89
+ import { PhysicsSystem, Physics, PhysicsType } from '@combos-fun/plugin-matterjs';
90
+
91
+ const game = new Game({
92
+ systems: [
93
+ new RendererSystem({ canvas, width: 750, height: 1334 }),
94
+ new GraphicsSystem(),
95
+ new PhysicsSystem({ world: { gravity: { x: 0, y: 1, scale: 0.001 } } }),
96
+ ],
97
+ });
98
+
99
+ const ball = new GameObject('ball');
100
+ ball.addComponent(new Transform({ position: { x: 375, y: 100 }, origin: { x: 0.5, y: 0.5 } }));
101
+ ball.addComponent(new Graphics(/* draw a circle */));
102
+ ball.addComponent(new Physics({ type: PhysicsType.CIRCLE, radius: 25 }));
103
+ ```
104
+
105
+ ## Verification
106
+
107
+ - `pnpm --filter @combos-fun/plugin-matterjs run build`
108
+ - Run a 2D example with physics; bodies should fall under gravity, collide,
109
+ 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.7",
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.7"
25
39
  },
26
40
  "scripts": {
27
41
  "build": "node ../../scripts/build-package.mjs"