@combos-fun/engine 0.0.34 → 0.0.36

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/agent-skill.md CHANGED
@@ -1,10 +1,12 @@
1
- # `@combos-fun/engine` — Agent notes
1
+ # `@combos-fun/engine` — Agent short card
2
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.
3
+ ECS microkernel for Combos Fun. **Short card only** do not re-cat after the first read. For authoring a new `@combos-fun/plugin-*`, read `@combos-fun/engine/plugin-authoring`.
4
4
 
5
5
  ## When to read
6
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.
7
+ Open this card **only when** an existing-project hard gate allows a plugin skill read (unfamiliar compile symbol / new plugin / real API conflict), or when starting from zero after mode detection. **Do not** load it every turn, and **do not** bulk-read sibling plugin skills with it.
8
+
9
+ Public API tables, host `postMessage` protocol, and long bootstrap samples: [`references/public-api.md`](references/public-api.md), [`references/bootstrap-examples.md`](references/bootstrap-examples.md).
8
10
 
9
11
  ## Microkernel model
10
12
 
@@ -13,116 +15,14 @@ Read this every time before working on a Combos Fun project. The entry skill loa
13
15
  - **Observer**: `@decorators.componentObserver({ Name: ['prop'] })` on a System; drain `this.componentObserver.clear()` in `update()` and switch on `OBSERVER_TYPE.ADD | CHANGE | REMOVE`.
14
16
  - **Frame order**: `Component.update` → `Component.lateUpdate` → `System.update` → `System.lateUpdate`. `start()` fires inline on the first `update` tick.
15
17
 
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`, `COMBOS_GAME_READY`, `COMBOS_GAME_SET_PLAYING`, `COMBOS_GAME_STATE_CHANGED`, `postParentPluginInitSuccess`, `postParentGameReady`, `postParentGameState`, `parseSetPlayingMessage`, `DEFAULT_ALLOWED_MESSAGE_HOST_SUFFIXES`, `isAllowedMessageOrigin`, `mergeAllowedMessageOrigins`.
21
-
22
- ### Types
23
-
24
- `GameParams`, `PluginStruct`, `TransformParams`, `ComponentChanged`, `UpdateParams`, `ComponentParams`, `ObserverInfo`, `PureObserverInfo`, `ResourceBase`, `SystemConstructor`, `CombosGamePluginInitSuccessMessage`, `CombosGameReadyMessage`, `CombosGameStateChangedMessage`, `CombosGameSetPlayingMessage`.
25
-
26
- ### `GameParams`
27
-
28
-
29
- | Field | Type | Default | Notes |
30
- | ------------------------------ | ------------------------ | ------- | ---------------------------------------- |
31
- | `systems` | `System[]` | `[]` | Bootstrapped async in registration order |
32
- | `frameRate` | `number` | `60` | |
33
- | `autoStart` | `boolean` | `true` | |
34
- | `needScene` | `boolean` | `true` | Auto-creates `Scene('scene')` |
35
- | `onSystemsBootstrapComplete` | `(game, error?) => void` | — | After all systems init |
36
- | `pluginInitNotifyTargetOrigin` | `string` | `'*'` | Outbound postMessage target (init / ready / state) |
37
- | `allowedMessageOrigins` | `string[]` | defaults | Inbound origins allowed to send `set-playing` (merged with defaults; `['*']` = any) |
38
-
39
-
40
- When the game runs inside an iframe (`window.parent !== window`), each `Game.addSystem` call posts to the parent after that system's `init` completes:
41
-
42
- ```typescript
43
- {
44
- type: 'combos-game:plugin-init-success',
45
- systemName: string, // System.systemName
46
- engineVersion: string, // @combos-fun/engine build version
47
- packageName?: string, // npm name, injected at plugin build
48
- packageVersion?: string, // semver from plugin package.json, injected at plugin build
49
- }
50
- ```
51
-
52
- Official `@combos-fun/plugin-*` packages get `packageName` / `packageVersion` automatically via `scripts/build-package.mjs` (no hand-written static fields). Host pages can gate tooling on specific systems or versions using this payload. Types: `CombosGamePluginInitSuccessMessage`, helper `postParentPluginInitSuccess` in `bootstrapMessages.ts`.
53
-
54
- ### Host lifecycle protocol (preload → hold → play)
55
-
56
- Core `Game` speaks a `postMessage` protocol with the embedding page so a host APP can preload, hold, then start the game on user intent. All outbound messages go to `pluginInitNotifyTargetOrigin`; the inbound command is origin-checked against `allowedMessageOrigins`.
57
-
58
- **Outbound (iframe → parent):**
59
-
60
- | Type | When | Payload |
61
- | ---- | ---- | ------- |
62
- | `combos-game:ready` | Bootstrap finished (systems `init`/`awake`, optional scene load & start). Sent once even with `autoStart:false`. | `{ engineVersion, error? }` |
63
- | `combos-game:state-changed` | After `start` / `pause` / `resume` | `{ playing, started }` |
64
-
65
- **Inbound (parent → iframe):**
66
-
67
- | Type | Effect | Payload |
68
- | ---- | ------ | ------- |
69
- | `combos-game:set-playing` | `true` → cold `start()` on first play, else `resume()`; `false` → `pause()` | `{ playing: boolean }` |
70
-
71
- Recommended flow: create the game with `autoStart:false`, wait for `combos-game:ready`, keep the game held at frame 0 (host shows a cover/loading overlay), then post `{ type: 'combos-game:set-playing', playing: true }` when the user taps play. `game.setPlaying(playing)` is the programmatic equivalent. Helpers: `postParentGameReady`, `postParentGameState`, `parseSetPlayingMessage`.
72
-
73
- > Note: play/pause is owned by the engine core here, **not** by `plugin-development-tool` (which now only handles pick mode + mute).
74
-
75
-
76
- ### `Game` methods
77
-
78
- `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()`, `setPlaying(playing)` (host bridge: cold-start-or-resume / pause), `destroy()`.
79
-
80
- ### `resource` singleton
81
-
82
-
83
- | Method | Notes |
84
- | ---------------------------------------------------------- | ------------------------- |
85
- | `addResource(resources[])` | Register (no load) |
86
- | `preload()` | Load all `preload: true` |
87
- | `loadConfig(resources[])` | `addResource` + `preload` |
88
- | `loadSingle(resource): Promise` | Add + load one |
89
- | `getResource(name): Promise` | Get loaded |
90
- | `destroy(name): Promise` | Destroy one |
91
- | `registerResourceType(type, value?)` | Custom type |
92
- | `registerInstance(type, cb)` / `registerDestroy(type, cb)` | Factory / destructor |
93
-
94
-
95
- Fields: `timeout` (6000ms), `resourcesMap`, `progress`.
96
-
97
- > ⚠️ `addResource` only registers; it does **not** kick off network load. Components that reference an unloaded `resource` (e.g. `Img({ resource: 'logo' })`) silently render nothing — the canvas stays blank with no console error. Always pair it with `preload()` (and gate `new Game(...)` behind `resource.once(LOAD_EVENT.COMPLETE, ...)`), or skip the pair entirely and use `loadConfig(resources[])` which does both in one call.
98
-
99
18
  ## ECS hard rules (mandatory)
100
19
 
101
- These rules apply to every code change. Violations must be fixed before the change is considered complete.
102
-
103
- ### Rule 1: All entity state lives in Components
104
-
105
- 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.
106
-
107
- ### Rule 2: All behaviour logic lives in Component / System hooks
108
-
109
- 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. Every `.on(...)` / `addEventListener(...)` subscription set up in `start` / `awake` must be torn down in `onDestroy`.
110
-
111
- ### Rule 3: Bootstrap code only wires, never implements
112
-
113
- 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.
114
-
115
- ### Rule 4: Single concern per Component, cross-entity logic in Systems
116
-
117
- 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. Every custom Component subclass must set `static componentName`; every custom System reacts via `@decorators.componentObserver({ Name: ['prop'] })` and drains observations in `update()` — never via ad-hoc scans of the scene graph.
118
-
119
- ### Rule 5: No direct Pixi / Three.js / DOM manipulation outside Renderer pattern
120
-
121
- 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.
122
-
123
- ### Rule 6: Component configuration via params, not imperative calls
124
-
125
- 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.
20
+ 1. **Entity state in Components** no module-scope / closure entity stores. Destroying a `GameObject` must drop its state.
21
+ 2. **Behaviour in Component / System hooks** — no bootstrap event handlers, no `setInterval` / `game.ticker.add` for game logic; tear down listeners in `onDestroy`.
22
+ 3. **Bootstrap only wires** create Game / Systems / GameObjects / Components; no game `if` / loops in entry files.
23
+ 4. **One concern per Component; cross-entity logic in Systems** — custom types need `static componentName` / observer drain, not ad-hoc scene scans.
24
+ 5. **No raw Pixi / Three / DOM outside Renderer pattern** use `plugin-renderer-*` / `plugin-renderer-3d-*` or registered `Renderer` / `Renderer3D`.
25
+ 6. **Configure via constructor params** — runtime triggers from other Component hooks, not bootstrap.
126
26
 
127
27
  ## Decision flowchart
128
28
 
@@ -137,167 +37,18 @@ Runs only once at startup to wire things?
137
37
  └── Rendering integration → Renderer (2D) / Renderer3D (3D) subclass
138
38
  ```
139
39
 
140
- ## Inventory (mandatory after every task)
141
-
142
- After every development task, write or update three inventory tables in the **project memory**:
143
-
144
- **Component inventory** — for each custom Component:
145
-
146
-
147
- | Field | Description |
148
- | --------------- | ----------------------------------------------------------------------------------------- |
149
- | `componentName` | Static name string |
150
- | Purpose | One-sentence description |
151
- | Key params | Constructor params that affect behaviour |
152
- | Lifecycle hooks | Which of `init` / `awake` / `start` / `update` / `lateUpdate` / `onDestroy` it implements |
153
-
154
-
155
- **GameObject inventory** — for each GameObject:
156
-
157
-
158
- | Field | Description |
159
- | ---------- | ------------------------------- |
160
- | Name | Identifier or variable name |
161
- | Parent | Parent GameObject or scene root |
162
- | Components | Attached Components |
163
- | Purpose | Role in the game |
164
-
165
-
166
- **System inventory** — for each System:
167
-
168
-
169
- | Field | Description |
170
- | ------------ | ------------------------------------- |
171
- | Class name | System class |
172
- | Order | Registration order in `systems` array |
173
- | What it owns | Components observed / coordinated |
174
- | Purpose | One-sentence description |
175
-
176
-
177
- Skipping inventory is treated with the same weight as the ECS hard rules.
178
-
179
40
  ## Common pitfalls
180
41
 
181
-
182
- | Symptom | Fix |
183
- | -------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
184
- | Blank canvas | Add the right base renderer system (`RendererSystem` for 2D, `Renderer3DSystem` for 3D); ensure `autoStart: true` or call `game.start()` |
185
- | Nothing draws | Add the matching sub-system (e.g. `ImgSystem`, `Graphics3DSystem`) before adding components |
186
- | `getSystem` returns undefined | Use class reference, not string: `game.getSystem(RendererSystem)` |
187
- | "Component already added" error | Use a new `Component` instance per `GameObject` |
188
- | Resource name not found | Match `resource.addResource` `name` to component `resource` field |
189
- | TS: `onError` missing on `SoundSystem` | `SoundSystem` requires `onError` callback |
190
- | Stale render after async load | 3D: use `increaseAsyncId` / `validateAsyncId` to drop stale work |
191
-
192
-
193
- ## Minimal 2D bootstrap
194
-
195
- ```ts
196
- import {
197
- Game,
198
- GameObject,
199
- resource,
200
- RESOURCE_TYPE,
201
- LOAD_EVENT,
202
- } from "@combos-fun/engine";
203
- import { RendererSystem } from "@combos-fun/plugin-renderer";
204
- import { Render, RenderSystem } from "@combos-fun/plugin-renderer-render";
205
- import { Img, ImgSystem } from "@combos-fun/plugin-renderer-img";
206
-
207
- resource.once(LOAD_EVENT.COMPLETE, () => {
208
- new Game({
209
- systems: [
210
- new RendererSystem({
211
- canvas: document.querySelector("#canvas")!,
212
- width: 750,
213
- height: 1334,
214
- }),
215
- new RenderSystem(),
216
- new ImgSystem(),
217
- ],
218
- // Safe place to wire the scene graph: every system has finished init.
219
- onSystemsBootstrapComplete: (g) => {
220
- // Transform values go through constructor params — never set them imperatively.
221
- const logo = new GameObject("logo", {
222
- position: { x: 100, y: 100 },
223
- size: { width: 200, height: 200 },
224
- origin: { x: 0.5, y: 0.5 },
225
- });
226
- logo.addComponent(new Img({ resource: "logo" }));
227
- // Render is only needed when you want to hide / fade / reorder; without it the
228
- // object is still drawn at alpha 1, zIndex 0. Requires RenderSystem registered.
229
- logo.addComponent(new Render({ zIndex: 5 }));
230
- // Use addChild — not addGameObject — so transform parent + scene are both wired.
231
- g.scene.addChild(logo);
232
- },
233
- });
234
- });
235
-
236
- resource.loadConfig([
237
- {
238
- name: "logo",
239
- type: RESOURCE_TYPE.IMAGE,
240
- src: { image: { type: "png", url: "logo.png" } },
241
- preload: true,
242
- },
243
- ]);
244
- ```
245
-
246
- `ResourceBase` requires both `type: RESOURCE_TYPE` and a nested `src` object keyed by media slot (`image` / `json` / `audio` / `video` / `tex` / `ske` / …) where each slot is `{ type, url }`. A flat `src: 'logo.png'` is invalid.
247
-
248
- ## Minimal 3D bootstrap
249
-
250
- ```ts
251
- import { Game, GameObject } from "@combos-fun/engine";
252
- import { Renderer3DSystem } from "@combos-fun/plugin-renderer-3d";
253
- import {
254
- Graphics3D,
255
- Graphics3DSystem,
256
- } from "@combos-fun/plugin-renderer-3d-graphics";
257
-
258
- new Game({
259
- systems: [
260
- new Renderer3DSystem({
261
- canvas: document.querySelector("#canvas")!,
262
- width: 750,
263
- height: 1000,
264
- }),
265
- new Graphics3DSystem(),
266
- ],
267
- // Safe place to wire the scene graph: every system has finished init.
268
- onSystemsBootstrapComplete: (g) => {
269
- // 3D position / rotation / scale go through the component's own params
270
- // (positionX/Y/Z, rotationX/Y/Z, scaleX/Y/Z) — GameObject's TransformParams
271
- // is 2D-only (Vector2 + Size2) and is not read by 3D renderers.
272
- const box = new GameObject("box");
273
- box.addComponent(
274
- new Graphics3D({
275
- shape: "box",
276
- width: 1,
277
- height: 1,
278
- depth: 1,
279
- color: 0xff0000,
280
- positionX: 0,
281
- positionY: 1,
282
- positionZ: 0,
283
- }),
284
- );
285
- // Use addChild — not addGameObject — so transform parent + scene are both wired.
286
- g.scene.addChild(box);
287
- },
288
- });
289
- ```
290
-
291
- ## Verification
292
-
293
- After modifying engine code:
294
-
295
- 1. `pnpm typecheck`
296
- 2. `pnpm run build` (rebuild all packages in dependency order)
297
- 3. `pnpm validate-plugin-manifests:strict`
298
- 4. Run an example app from `examples/` and verify no console errors
42
+ | Symptom | Fix |
43
+ | --- | --- |
44
+ | Blank canvas | Base renderer system registered; `autoStart` or `game.start()` |
45
+ | Nothing draws | Matching sub-system (e.g. `ImgSystem`) before components |
46
+ | `getSystem` undefined | Pass class, not string |
47
+ | Resource missing / blank sprite | `loadConfig` or `addResource` + `preload` + `LOAD_EVENT.COMPLETE` before use |
48
+ | TS / runtime API guess wrong | Prefer `$combos-engine-development` `references/api-guessing-cases.md`, not `node_modules` digs |
299
49
 
300
50
  ## See also
301
51
 
302
- - `@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.
303
-
52
+ - [`references/public-api.md`](references/public-api.md)exports, `GameParams`, host lifecycle, `resource` API
53
+ - [`references/bootstrap-examples.md`](references/bootstrap-examples.md) — minimal 2D / 3D samples
54
+ - `@combos-fun/engine/plugin-authoring` — new plugin package spec
@@ -1001,7 +1001,7 @@ class Scene extends GameObject {
1001
1001
  }
1002
1002
 
1003
1003
  /** Generated at build from package.json */
1004
- const version = "0.0.34";
1004
+ const version = "0.0.36";
1005
1005
 
1006
1006
  /**
1007
1007
  * Sent to `window.parent` after each `System.init` completes during `Game.addSystem`