@combos-fun/engine 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 +25 -1
- package/agent-skill.md +205 -0
- package/combos-plugin.json +23 -0
- package/package.json +19 -3
- package/plugin-authoring.md +187 -0
package/README.md
CHANGED
|
@@ -1,3 +1,27 @@
|
|
|
1
1
|
# @combos-fun/engine
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
@combos-fun/engine — part of the Combos Fun engine monorepo.
|
|
4
|
+
|
|
5
|
+
Keywords: `engine`, `ecs`, `kernel`, `runtime`, `game`, `system`, `component`.
|
|
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/engine/plugin-manifest';
|
|
21
|
+
// or fetch the markdown directly:
|
|
22
|
+
// require.resolve('@combos-fun/engine/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,205 @@
|
|
|
1
|
+
# `@combos-fun/engine` — Agent notes
|
|
2
|
+
|
|
3
|
+
ECS microkernel for Combos Fun. This file is the canonical knowledge source for **using** the engine. For **authoring** a new `@combos-fun/plugin-*`, read `@combos-fun/engine/plugin-authoring` instead.
|
|
4
|
+
|
|
5
|
+
## When to read
|
|
6
|
+
|
|
7
|
+
Read this every time before working on a Combos Fun project. The entry skill loads this file as part of "Core" packages, regardless of 2D / 3D mode.
|
|
8
|
+
|
|
9
|
+
## Microkernel model
|
|
10
|
+
|
|
11
|
+
- **Kernel** `@combos-fun/engine`: `Game`, `Scene`, `GameObject`, `Component`, `System`, `Transform`, `resource`, `decorators`. **No** built-in rendering / physics / audio.
|
|
12
|
+
- **Extension**: `game.addSystem(new XxxSystem(...))` then `gameObject.addComponent(new Xxx(...))`.
|
|
13
|
+
- **Observer**: `@decorators.componentObserver({ Name: ['prop'] })` on a System; drain `this.componentObserver.clear()` in `update()` and switch on `OBSERVER_TYPE.ADD | CHANGE | REMOVE`.
|
|
14
|
+
- **Frame order**: `Component.update` → `Component.lateUpdate` → `System.update` → `System.lateUpdate`. `start()` fires inline on the first `update` tick.
|
|
15
|
+
|
|
16
|
+
## Public API
|
|
17
|
+
|
|
18
|
+
### Values
|
|
19
|
+
|
|
20
|
+
`Game`, `Scene`, `GameObject`, `Component`, `System`, `Transform`, `resource`, `resourceLoader`, `decorators`, `IDEProp`, `componentObserver`, `LOAD_EVENT`, `RESOURCE_TYPE`, `OBSERVER_TYPE`, `LOAD_SCENE_MODE`, `RESOURCE_TYPE_STRATEGY`, `version`, `COMBOS_GAME_PLUGIN_INIT_SUCCESS`, `postParentPluginInitSuccess`.
|
|
21
|
+
|
|
22
|
+
### Types
|
|
23
|
+
|
|
24
|
+
`GameParams`, `PluginStruct`, `TransformParams`, `ComponentChanged`, `UpdateParams`, `ComponentParams`, `ObserverInfo`, `PureObserverInfo`, `ResourceBase`, `SystemConstructor`, `CombosGamePluginInitSuccessMessage`.
|
|
25
|
+
|
|
26
|
+
### `GameParams`
|
|
27
|
+
|
|
28
|
+
| Field | Type | Default | Notes |
|
|
29
|
+
|-------|------|---------|-------|
|
|
30
|
+
| `systems` | `System[]` | `[]` | Bootstrapped async in registration order |
|
|
31
|
+
| `frameRate` | `number` | `60` | |
|
|
32
|
+
| `autoStart` | `boolean` | `true` | |
|
|
33
|
+
| `needScene` | `boolean` | `true` | Auto-creates `Scene('scene')` |
|
|
34
|
+
| `onSystemsBootstrapComplete` | `(game, error?) => void` | — | After all systems init |
|
|
35
|
+
| `pluginInitNotifyTargetOrigin` | `string` | `'*'` | postMessage target |
|
|
36
|
+
|
|
37
|
+
### `Game` methods
|
|
38
|
+
|
|
39
|
+
`addSystem(system)`, `removeSystem(system | class | string)` (calls `system.destroy()` internally), `getSystem(class | string)`, `loadScene({ scene, mode?, params? })` (`LOAD_SCENE_MODE.SINGLE | MULTI_CANVAS`), `start()`, `pause()`, `resume()`, `destroy()`.
|
|
40
|
+
|
|
41
|
+
### `resource` singleton
|
|
42
|
+
|
|
43
|
+
| Method | Notes |
|
|
44
|
+
|--------|-------|
|
|
45
|
+
| `addResource(resources[])` | Register (no load) |
|
|
46
|
+
| `preload()` | Load all `preload: true` |
|
|
47
|
+
| `loadConfig(resources[])` | `addResource` + `preload` |
|
|
48
|
+
| `loadSingle(resource): Promise` | Add + load one |
|
|
49
|
+
| `getResource(name): Promise` | Get loaded |
|
|
50
|
+
| `destroy(name): Promise` | Destroy one |
|
|
51
|
+
| `registerResourceType(type, value?)` | Custom type |
|
|
52
|
+
| `registerInstance(type, cb)` / `registerDestroy(type, cb)` | Factory / destructor |
|
|
53
|
+
|
|
54
|
+
Fields: `timeout` (6000ms), `resourcesMap`, `progress`.
|
|
55
|
+
|
|
56
|
+
## ECS hard rules (mandatory)
|
|
57
|
+
|
|
58
|
+
These rules apply to every code change. Violations must be fixed before the change is considered complete.
|
|
59
|
+
|
|
60
|
+
### Rule 1: All entity state lives in Components
|
|
61
|
+
|
|
62
|
+
Any data belonging to a game entity must be a field on a `Component` attached to a `GameObject`. No module-scope variables, closure captures, or shadow stores holding entity state. **Test:** if you `destroy()` a `GameObject`, does all its state disappear? If anything survives in a closure or module variable, violation.
|
|
63
|
+
|
|
64
|
+
### Rule 2: All behaviour logic lives in Component / System hooks
|
|
65
|
+
|
|
66
|
+
Code that runs per-frame, reacts to events, or mutates entity state must live in `Component` hooks (`init` / `awake` / `start` / `update` / `lateUpdate` / `onPause` / `onResume` / `onDestroy`) or `System` hooks (same set + `componentObserver` in `update`). No event callbacks in bootstrap, no `setInterval` outside Components, no `game.ticker.add` for game logic.
|
|
67
|
+
|
|
68
|
+
### Rule 3: Bootstrap code only wires, never implements
|
|
69
|
+
|
|
70
|
+
The entry file may: register resources, create `Game` with `systems`, create `GameObject`s + attach `Component`s, add to scene, call `game.start()`. The entry file must **not**: define event handlers, call component methods (`spriteAnim.play()`), hold component references for later use, or contain `if` / `switch` / loop game logic. When you need interaction logic, create a custom Component whose `start()` wires it and whose `onDestroy()` cleans it up.
|
|
71
|
+
|
|
72
|
+
### Rule 4: Single concern per Component, cross-entity logic in Systems
|
|
73
|
+
|
|
74
|
+
A Component holds data + self-contained behaviour for one concern on one entity. A System holds cross-entity logic reacting to component changes. Do not put multi-entity coordination inside a Component.
|
|
75
|
+
|
|
76
|
+
### Rule 5: No direct Pixi / Three.js / DOM manipulation outside Renderer pattern
|
|
77
|
+
|
|
78
|
+
2D display objects must come through `plugin-renderer-*` systems or a custom `Renderer` subclass registered via `rendererManager.register(this)`. 3D objects must come through `plugin-renderer-3d-*` systems or a custom `Renderer3D` subclass. No raw `new PIXI.Sprite(...)` / `new THREE.Mesh(...)` in bootstrap or plain Components.
|
|
79
|
+
|
|
80
|
+
### Rule 6: Component configuration via params, not imperative calls
|
|
81
|
+
|
|
82
|
+
Configure Components through constructor params (e.g. `autoPlay: true`). If behaviour must be triggered at runtime, do it from another Component's lifecycle hook, not from bootstrap code.
|
|
83
|
+
|
|
84
|
+
## Decision flowchart
|
|
85
|
+
|
|
86
|
+
```
|
|
87
|
+
Runs only once at startup to wire things?
|
|
88
|
+
├── YES: Only creates GameObjects/Components/Systems/resources?
|
|
89
|
+
│ ├── YES → bootstrap / entry file
|
|
90
|
+
│ └── NO (contains logic) → Component or System
|
|
91
|
+
└── NO: Runs per-frame or reacts to events?
|
|
92
|
+
├── Single-entity concern → Component
|
|
93
|
+
├── Cross-entity concern → System with @componentObserver
|
|
94
|
+
└── Rendering integration → Renderer (2D) / Renderer3D (3D) subclass
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## ECS compliance checklist
|
|
98
|
+
|
|
99
|
+
Run after every change:
|
|
100
|
+
|
|
101
|
+
- [ ] No game logic in entry file — only resource registration, `Game` / `System` creation, `GameObject` + `Component` wiring, scene setup
|
|
102
|
+
- [ ] No retained component references — entry file does not store `addComponent()` returns for later use
|
|
103
|
+
- [ ] No anonymous event handlers — all `.on(...)` / `addEventListener(...)` inside Component lifecycle hooks with cleanup in `onDestroy`
|
|
104
|
+
- [ ] No module-scope mutable state holding entity data
|
|
105
|
+
- [ ] All entity state accessible via `gameObject.getComponent(...)`
|
|
106
|
+
- [ ] All per-frame logic in Component / System `update` / `lateUpdate`
|
|
107
|
+
- [ ] Custom behaviour = named Component class with `static componentName`
|
|
108
|
+
- [ ] Every event subscription has cleanup in `onDestroy`
|
|
109
|
+
- [ ] Systems use `@decorators.componentObserver` and drain in `update()`
|
|
110
|
+
- [ ] No direct Pixi / Three.js manipulation outside `Renderer` / `Renderer3D` subclasses
|
|
111
|
+
|
|
112
|
+
## Inventory (mandatory after every task)
|
|
113
|
+
|
|
114
|
+
After every development task, write or update three inventory tables in the **project memory**:
|
|
115
|
+
|
|
116
|
+
**Component inventory** — for each custom Component:
|
|
117
|
+
|
|
118
|
+
| Field | Description |
|
|
119
|
+
|-------|-------------|
|
|
120
|
+
| `componentName` | Static name string |
|
|
121
|
+
| Purpose | One-sentence description |
|
|
122
|
+
| Key params | Constructor params that affect behaviour |
|
|
123
|
+
| Lifecycle hooks | Which of `init` / `awake` / `start` / `update` / `lateUpdate` / `onDestroy` it implements |
|
|
124
|
+
|
|
125
|
+
**GameObject inventory** — for each GameObject:
|
|
126
|
+
|
|
127
|
+
| Field | Description |
|
|
128
|
+
|-------|-------------|
|
|
129
|
+
| Name | Identifier or variable name |
|
|
130
|
+
| Parent | Parent GameObject or scene root |
|
|
131
|
+
| Components | Attached Components |
|
|
132
|
+
| Purpose | Role in the game |
|
|
133
|
+
|
|
134
|
+
**System inventory** — for each System:
|
|
135
|
+
|
|
136
|
+
| Field | Description |
|
|
137
|
+
|-------|-------------|
|
|
138
|
+
| Class name | System class |
|
|
139
|
+
| Order | Registration order in `systems` array |
|
|
140
|
+
| What it owns | Components observed / coordinated |
|
|
141
|
+
| Purpose | One-sentence description |
|
|
142
|
+
|
|
143
|
+
Skipping inventory is treated with the same weight as the ECS hard rules.
|
|
144
|
+
|
|
145
|
+
## Common pitfalls
|
|
146
|
+
|
|
147
|
+
| Symptom | Fix |
|
|
148
|
+
|---------|-----|
|
|
149
|
+
| Blank canvas | Add the right base renderer system (`RendererSystem` for 2D, `Renderer3DSystem` for 3D); ensure `autoStart: true` or call `game.start()` |
|
|
150
|
+
| Nothing draws | Add the matching sub-system (e.g. `ImgSystem`, `Graphics3DSystem`) before adding components |
|
|
151
|
+
| `getSystem` returns undefined | Use class reference, not string: `game.getSystem(RendererSystem)` |
|
|
152
|
+
| "Component already added" error | Use a new `Component` instance per `GameObject` |
|
|
153
|
+
| Destroyed `GameObject` causes errors | Retained reference in a closure — move logic into a Component |
|
|
154
|
+
| Cannot pause / resume behaviour | Logic in `setInterval` / `ticker.add` — move into `Component.update()` |
|
|
155
|
+
| Resource name not found | Match `resource.addResource` `name` to component `resource` field |
|
|
156
|
+
| TS: `onError` missing on `SoundSystem` | `SoundSystem` requires `onError` callback |
|
|
157
|
+
| Stale render after async load | 3D: use `increaseAsyncId` / `validateAsyncId` to drop stale work |
|
|
158
|
+
|
|
159
|
+
## Minimal 2D bootstrap
|
|
160
|
+
|
|
161
|
+
```ts
|
|
162
|
+
import { Game, resource } from '@combos-fun/engine';
|
|
163
|
+
import { RendererSystem } from '@combos-fun/plugin-renderer';
|
|
164
|
+
import { RenderSystem } from '@combos-fun/plugin-renderer-render';
|
|
165
|
+
import { ImgSystem } from '@combos-fun/plugin-renderer-img';
|
|
166
|
+
|
|
167
|
+
resource.addResource([{ name: 'logo', src: 'logo.png', preload: true }]);
|
|
168
|
+
|
|
169
|
+
new Game({
|
|
170
|
+
systems: [
|
|
171
|
+
new RendererSystem({ canvas: document.querySelector('#canvas')!, width: 750, height: 1334 }),
|
|
172
|
+
new RenderSystem(),
|
|
173
|
+
new ImgSystem(),
|
|
174
|
+
],
|
|
175
|
+
});
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
## Minimal 3D bootstrap
|
|
179
|
+
|
|
180
|
+
```ts
|
|
181
|
+
import { Game } from '@combos-fun/engine';
|
|
182
|
+
import { Renderer3DSystem } from '@combos-fun/plugin-renderer-3d';
|
|
183
|
+
import { Graphics3DSystem } from '@combos-fun/plugin-renderer-3d-graphics';
|
|
184
|
+
|
|
185
|
+
new Game({
|
|
186
|
+
systems: [
|
|
187
|
+
new Renderer3DSystem({ canvas: document.querySelector('#canvas')!, width: 750, height: 1000 }),
|
|
188
|
+
new Graphics3DSystem(),
|
|
189
|
+
],
|
|
190
|
+
});
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
## Verification
|
|
194
|
+
|
|
195
|
+
After modifying engine code:
|
|
196
|
+
|
|
197
|
+
1. `pnpm typecheck`
|
|
198
|
+
2. `pnpm run build` (rebuild all packages in dependency order)
|
|
199
|
+
3. `pnpm validate-plugin-manifests` (warn during migration, strict at GA)
|
|
200
|
+
4. `pnpm plugin-index:check`
|
|
201
|
+
5. Run an example app from `examples/` and verify no console errors
|
|
202
|
+
|
|
203
|
+
## See also
|
|
204
|
+
|
|
205
|
+
- `@combos-fun/engine/plugin-authoring` — full spec for writing a new `@combos-fun/plugin-*` package, including Component / System / Renderer / Renderer3D subclassing, manifest format, and publish requirements.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@combos-fun/engine",
|
|
3
|
+
"pluginId": "engine",
|
|
4
|
+
"category": "core",
|
|
5
|
+
"dimension": "shared",
|
|
6
|
+
"isCore": true,
|
|
7
|
+
"keywords": ["engine", "ecs", "kernel", "runtime", "game", "system", "component"],
|
|
8
|
+
"agentSkill": "./agent-skill.md",
|
|
9
|
+
"exports": [
|
|
10
|
+
"Game",
|
|
11
|
+
"Scene",
|
|
12
|
+
"GameObject",
|
|
13
|
+
"Component",
|
|
14
|
+
"System",
|
|
15
|
+
"Transform",
|
|
16
|
+
"resource",
|
|
17
|
+
"decorators",
|
|
18
|
+
"OBSERVER_TYPE",
|
|
19
|
+
"RESOURCE_TYPE",
|
|
20
|
+
"LOAD_EVENT",
|
|
21
|
+
"LOAD_SCENE_MODE"
|
|
22
|
+
]
|
|
23
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@combos-fun/engine",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"description": "@combos-fun/engine",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "dist/engine.esm.js",
|
|
@@ -8,8 +8,24 @@
|
|
|
8
8
|
"unpkg": "dist/CombosFun.min.js",
|
|
9
9
|
"files": [
|
|
10
10
|
"index.js",
|
|
11
|
-
"dist"
|
|
11
|
+
"dist",
|
|
12
|
+
"agent-skill.md",
|
|
13
|
+
"plugin-authoring.md",
|
|
14
|
+
"combos-plugin.json"
|
|
12
15
|
],
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"import": "./dist/engine.esm.js",
|
|
19
|
+
"require": "./index.js",
|
|
20
|
+
"types": "./dist/engine.d.ts"
|
|
21
|
+
},
|
|
22
|
+
"./plugin-manifest": "./combos-plugin.json",
|
|
23
|
+
"./agent-skill": "./agent-skill.md",
|
|
24
|
+
"./plugin-authoring": "./plugin-authoring.md"
|
|
25
|
+
},
|
|
26
|
+
"combos": {
|
|
27
|
+
"pluginManifest": "./combos-plugin.json"
|
|
28
|
+
},
|
|
13
29
|
"types": "dist/engine.d.ts",
|
|
14
30
|
"keywords": [
|
|
15
31
|
"combos-fun",
|
|
@@ -21,7 +37,7 @@
|
|
|
21
37
|
"lodash-es": "^4.17.21",
|
|
22
38
|
"resource-loader": "^4.0.0-rc4",
|
|
23
39
|
"sprite-timeline": "^1.10.2",
|
|
24
|
-
"@combos-fun/inspector-decorator": "0.0.
|
|
40
|
+
"@combos-fun/inspector-decorator": "0.0.8"
|
|
25
41
|
},
|
|
26
42
|
"scripts": {
|
|
27
43
|
"build": "node ../../scripts/build-package.mjs"
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
# `@combos-fun/engine` — Plugin authoring spec
|
|
2
|
+
|
|
3
|
+
This file is the standard for authoring any new `@combos-fun/plugin-*` package — npm-published or project-local. Read it only when you are **creating** a plugin. Day-to-day engine usage is covered in `@combos-fun/engine/agent-skill`.
|
|
4
|
+
|
|
5
|
+
A plugin is `Component(s)` + optional `System(s)` + optional `Renderer` / `Renderer3D` subclass, shipped under the `@combos-fun/` namespace as an npm package or as a folder inside a user project.
|
|
6
|
+
|
|
7
|
+
## When to read
|
|
8
|
+
|
|
9
|
+
- You are adding a new feature that does not match any existing `@combos-fun/plugin-*` keyword.
|
|
10
|
+
- You are publishing a new plugin to npm under `@combos-fun/*`.
|
|
11
|
+
- You are forking / extending an existing plugin's `Renderer` / `Renderer3D` subclass.
|
|
12
|
+
|
|
13
|
+
For pure consumption of existing plugins, this file is not required — read `@combos-fun/engine/agent-skill` plus each plugin's `agent-skill` instead.
|
|
14
|
+
|
|
15
|
+
## Required package layout
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
packages/<plugin-name>/
|
|
19
|
+
package.json
|
|
20
|
+
combos-plugin.json # machine-readable manifest (validated against schemas/combos-plugin.schema.json)
|
|
21
|
+
agent-skill.md # per-package agent notes
|
|
22
|
+
README.md # human-facing docs
|
|
23
|
+
index.js # CJS entry
|
|
24
|
+
lib/ # TypeScript sources
|
|
25
|
+
dist/ # built CJS / ESM / .d.ts (created by build-package.mjs)
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Project-local plugins (not published to npm) may skip `dist/`, the build step, and `combos-plugin.json` — but adopting both unlocks the same selection logic the entry skill uses for official plugins.
|
|
29
|
+
|
|
30
|
+
## Required `package.json` fields
|
|
31
|
+
|
|
32
|
+
```json
|
|
33
|
+
{
|
|
34
|
+
"name": "@combos-fun/plugin-xxx",
|
|
35
|
+
"files": ["dist", "index.js", "agent-skill.md", "combos-plugin.json"],
|
|
36
|
+
"exports": {
|
|
37
|
+
".": "./dist/plugin-xxx.esm.js",
|
|
38
|
+
"./plugin-manifest": "./combos-plugin.json",
|
|
39
|
+
"./agent-skill": "./agent-skill.md"
|
|
40
|
+
},
|
|
41
|
+
"combos": {
|
|
42
|
+
"pluginManifest": "./combos-plugin.json"
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
The `./plugin-manifest` and `./agent-skill` subpaths are part of the public contract. External Agents resolve documentation via these stable subpaths. Renaming the underlying files without updating `exports` is a breaking change.
|
|
48
|
+
|
|
49
|
+
## Component subclass
|
|
50
|
+
|
|
51
|
+
Subclass `Component` from `@combos-fun/engine`. Set `static componentName = 'MyFeature'`.
|
|
52
|
+
|
|
53
|
+
Lifecycle (all optional):
|
|
54
|
+
|
|
55
|
+
| Hook | When |
|
|
56
|
+
|------|------|
|
|
57
|
+
| `init(params?)` | During construction |
|
|
58
|
+
| `awake()` | When added to a GameObject |
|
|
59
|
+
| `start()` | Inline on first `update` tick (same frame as first `update`) |
|
|
60
|
+
| `update(frame)` | Every frame (`frame.deltaTime` in ms) |
|
|
61
|
+
| `lateUpdate(frame)` | After all components' `update`, before any `System.update` |
|
|
62
|
+
| `onPause()` / `onResume()` | Game pause / resume |
|
|
63
|
+
| `onDestroy()` | Component or GameObject destroyed |
|
|
64
|
+
|
|
65
|
+
`UpdateParams`: `deltaTime`, `frameCount`, `time`, `currentTime`, `fps`.
|
|
66
|
+
|
|
67
|
+
## System subclass
|
|
68
|
+
|
|
69
|
+
Subclass `System`. Set `static systemName = 'MyFeatureSystem'`.
|
|
70
|
+
|
|
71
|
+
Decorate with `@decorators.componentObserver({ MyFeature: ['power'] })`:
|
|
72
|
+
|
|
73
|
+
- `[]` (empty array) → ADD / REMOVE only
|
|
74
|
+
- `['prop']` → CHANGE on set
|
|
75
|
+
- `{ prop: ['a','b'], deep: true }` → deep change watching
|
|
76
|
+
|
|
77
|
+
In `update()`:
|
|
78
|
+
|
|
79
|
+
```ts
|
|
80
|
+
const changes = this.componentObserver.clear();
|
|
81
|
+
for (const c of changes) {
|
|
82
|
+
switch (c.type) {
|
|
83
|
+
case OBSERVER_TYPE.ADD: /* c.component, c.gameObject */ break;
|
|
84
|
+
case OBSERVER_TYPE.CHANGE: /* c.prop?: { deep, prop: string[] } */ break;
|
|
85
|
+
case OBSERVER_TYPE.REMOVE: break;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
System lifecycle is the same as Component (`init` can be async). `init` receives constructor params; `this.game` is available.
|
|
91
|
+
|
|
92
|
+
`System.destroy()` nulls internals and calls `onDestroy()` but **does not** remove the system from Game. Always call `game.removeSystem(system)`, which calls `destroy()` internally.
|
|
93
|
+
|
|
94
|
+
### `ComponentChanged` shape
|
|
95
|
+
|
|
96
|
+
`type: OBSERVER_TYPE`, `component`, `componentName`, `gameObject`, `prop?: { deep, prop: string[] }`.
|
|
97
|
+
|
|
98
|
+
## 2D Pixi `Renderer` subclass (`@combos-fun/plugin-renderer`)
|
|
99
|
+
|
|
100
|
+
Extend `Renderer` from `plugin-renderer` with `@decorators.componentObserver`.
|
|
101
|
+
|
|
102
|
+
```ts
|
|
103
|
+
class MyRenderer extends Renderer {
|
|
104
|
+
init() {
|
|
105
|
+
this.rendererSystem = this.game.getSystem(RendererSystem);
|
|
106
|
+
this.rendererSystem.rendererManager.register(this);
|
|
107
|
+
}
|
|
108
|
+
componentChanged(changed: ComponentChanged) {
|
|
109
|
+
const container = this.rendererSystem.containerManager.getContainer(
|
|
110
|
+
changed.gameObject.id,
|
|
111
|
+
);
|
|
112
|
+
switch (changed.type) {
|
|
113
|
+
case OBSERVER_TYPE.ADD: /* create pixi object, container.addChild(obj) */ break;
|
|
114
|
+
case OBSERVER_TYPE.CHANGE: /* mutate */ break;
|
|
115
|
+
case OBSERVER_TYPE.REMOVE: /* destroy + container.removeChild */ break;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
rendererUpdate(gameObject) {
|
|
119
|
+
/* per-frame sync */
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
`RendererSystem` must be added before any system calling `getSystem(RendererSystem)` in `init`.
|
|
125
|
+
|
|
126
|
+
## 3D Three.js `Renderer3D` subclass (`@combos-fun/plugin-renderer-3d`)
|
|
127
|
+
|
|
128
|
+
Extend `Renderer3D` with `@decorators.componentObserver`.
|
|
129
|
+
|
|
130
|
+
```ts
|
|
131
|
+
class MyRenderer3D extends Renderer3D {
|
|
132
|
+
init() {
|
|
133
|
+
this.rendererSystem = this.game.getSystem(Renderer3DSystem);
|
|
134
|
+
this.rendererSystem.rendererManager.register(this);
|
|
135
|
+
}
|
|
136
|
+
componentChanged(changed) {
|
|
137
|
+
const scene = this.threeContext.scene;
|
|
138
|
+
/* create / mutate / dispose THREE.Object3D */
|
|
139
|
+
}
|
|
140
|
+
rendererUpdate(gameObject) { /* per-frame */ }
|
|
141
|
+
}
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
`Renderer3DSystem` must be added before any system calling `getSystem(Renderer3DSystem)` in `init`.
|
|
145
|
+
|
|
146
|
+
**Async loading pattern** (3D only): use the inherited `increaseAsyncId(id)` before async work and `validateAsyncId(id, asyncId)` after each `await` to cancel stale operations when the component is removed mid-load.
|
|
147
|
+
|
|
148
|
+
## `combos-plugin.json` (manifest)
|
|
149
|
+
|
|
150
|
+
Validate against `schemas/combos-plugin.schema.json`. Required fields: `name`, `pluginId`, `category`, `dimension`, `agentSkill`. For non-core packages, `category` ∈ {`rendering`, `physics`, `audio`, `input`, `ui`, `a11y`, `animation`, `devtool`, `other`} and `dimension` ∈ {`2d`, `3d`, `shared`}.
|
|
151
|
+
|
|
152
|
+
## `agent-skill.md` template (per-plugin notes)
|
|
153
|
+
|
|
154
|
+
```md
|
|
155
|
+
# <plugin-name> — Agent notes
|
|
156
|
+
|
|
157
|
+
## When to read
|
|
158
|
+
<!-- which tasks should load this -->
|
|
159
|
+
|
|
160
|
+
## Public API
|
|
161
|
+
<!-- exported components / systems / params -->
|
|
162
|
+
|
|
163
|
+
## Required setup
|
|
164
|
+
<!-- system registration order, dependencies -->
|
|
165
|
+
|
|
166
|
+
## Runtime behaviour
|
|
167
|
+
<!-- lifecycle interactions, frame-order specifics -->
|
|
168
|
+
|
|
169
|
+
## Common pitfalls
|
|
170
|
+
<!-- blank canvas, missing systems, async stale, etc -->
|
|
171
|
+
|
|
172
|
+
## Minimal example
|
|
173
|
+
<!-- shortest copy-pasteable snippet -->
|
|
174
|
+
|
|
175
|
+
## Verification
|
|
176
|
+
<!-- how to run / test the plugin after changes -->
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
## Build & publish requirements (npm-published plugins only)
|
|
180
|
+
|
|
181
|
+
- Build: CJS / ESM + `.d.ts` to `dist/` via `node ../../scripts/build-package.mjs`.
|
|
182
|
+
- Peer / runtime deps: `@combos-fun/engine`, optionally `plugin-renderer` + `pixi.js` (for 2D renderer plugins) or `plugin-renderer-3d` + `three` (for 3D renderer plugins).
|
|
183
|
+
- `package.json`: include `agent-skill.md` and `combos-plugin.json` in `files`; expose `./plugin-manifest` and `./agent-skill` in `exports`.
|
|
184
|
+
- Run `pnpm validate-plugin-manifests --strict` and `pnpm plugin-index:check` before publishing. The publish script does this automatically.
|
|
185
|
+
- Duplicate registration of the same System class is warned and skipped.
|
|
186
|
+
|
|
187
|
+
Project-local plugins skip all of this: no build, no manifest, no schema validation, no exports, no publish. The Component / System / Renderer code itself is identical.
|