@combos-fun/engine 0.0.12 → 0.0.13

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.
Files changed (2) hide show
  1. package/agent-skill.md +144 -82
  2. package/package.json +2 -2
package/agent-skill.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # `@combos-fun/engine` — Agent notes
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. 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
4
 
5
5
  ## When to read
6
6
 
@@ -25,14 +25,16 @@ Read this every time before working on a Combos Fun project. The entry skill loa
25
25
 
26
26
  ### `GameParams`
27
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 |
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` | `'*'` | postMessage target |
37
+
36
38
 
37
39
  ### `Game` methods
38
40
 
@@ -40,19 +42,23 @@ Read this every time before working on a Combos Fun project. The entry skill loa
40
42
 
41
43
  ### `resource` singleton
42
44
 
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 |
45
+
46
+ | Method | Notes |
47
+ | ---------------------------------------------------------- | ------------------------- |
48
+ | `addResource(resources[])` | Register (no load) |
49
+ | `preload()` | Load all `preload: true` |
50
+ | `loadConfig(resources[])` | `addResource` + `preload` |
51
+ | `loadSingle(resource): Promise` | Add + load one |
52
+ | `getResource(name): Promise` | Get loaded |
53
+ | `destroy(name): Promise` | Destroy one |
54
+ | `registerResourceType(type, value?)` | Custom type |
55
+ | `registerInstance(type, cb)` / `registerDestroy(type, cb)` | Factory / destructor |
56
+
53
57
 
54
58
  Fields: `timeout` (6000ms), `resourcesMap`, `progress`.
55
59
 
60
+ > ⚠️ `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.
61
+
56
62
  ## ECS hard rules (mandatory)
57
63
 
58
64
  These rules apply to every code change. Violations must be fixed before the change is considered complete.
@@ -63,7 +69,7 @@ Any data belonging to a game entity must be a field on a `Component` attached to
63
69
 
64
70
  ### Rule 2: All behaviour logic lives in Component / System hooks
65
71
 
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.
72
+ 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`.
67
73
 
68
74
  ### Rule 3: Bootstrap code only wires, never implements
69
75
 
@@ -71,11 +77,11 @@ The entry file may: register resources, create `Game` with `systems`, create `Ga
71
77
 
72
78
  ### Rule 4: Single concern per Component, cross-entity logic in Systems
73
79
 
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.
80
+ 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.
75
81
 
76
82
  ### Rule 5: No direct Pixi / Three.js / DOM manipulation outside Renderer pattern
77
83
 
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.
84
+ 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
85
 
80
86
  ### Rule 6: Component configuration via params, not imperative calls
81
87
 
@@ -94,99 +100,154 @@ Runs only once at startup to wire things?
94
100
  └── Rendering integration → Renderer (2D) / Renderer3D (3D) subclass
95
101
  ```
96
102
 
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
103
  ## Inventory (mandatory after every task)
113
104
 
114
105
  After every development task, write or update three inventory tables in the **project memory**:
115
106
 
116
107
  **Component inventory** — for each custom Component:
117
108
 
118
- | Field | Description |
119
- |-------|-------------|
120
- | `componentName` | Static name string |
121
- | Purpose | One-sentence description |
122
- | Key params | Constructor params that affect behaviour |
109
+
110
+ | Field | Description |
111
+ | --------------- | ----------------------------------------------------------------------------------------- |
112
+ | `componentName` | Static name string |
113
+ | Purpose | One-sentence description |
114
+ | Key params | Constructor params that affect behaviour |
123
115
  | Lifecycle hooks | Which of `init` / `awake` / `start` / `update` / `lateUpdate` / `onDestroy` it implements |
124
116
 
117
+
125
118
  **GameObject inventory** — for each GameObject:
126
119
 
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 |
120
+
121
+ | Field | Description |
122
+ | ---------- | ------------------------------- |
123
+ | Name | Identifier or variable name |
124
+ | Parent | Parent GameObject or scene root |
125
+ | Components | Attached Components |
126
+ | Purpose | Role in the game |
127
+
133
128
 
134
129
  **System inventory** — for each System:
135
130
 
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 |
131
+
132
+ | Field | Description |
133
+ | ------------ | ------------------------------------- |
134
+ | Class name | System class |
135
+ | Order | Registration order in `systems` array |
136
+ | What it owns | Components observed / coordinated |
137
+ | Purpose | One-sentence description |
138
+
142
139
 
143
140
  Skipping inventory is treated with the same weight as the ECS hard rules.
144
141
 
145
142
  ## Common pitfalls
146
143
 
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
144
 
159
- ## Minimal 2D bootstrap
145
+ | Symptom | Fix |
146
+ | -------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
147
+ | Blank canvas | Add the right base renderer system (`RendererSystem` for 2D, `Renderer3DSystem` for 3D); ensure `autoStart: true` or call `game.start()` |
148
+ | Nothing draws | Add the matching sub-system (e.g. `ImgSystem`, `Graphics3DSystem`) before adding components |
149
+ | `getSystem` returns undefined | Use class reference, not string: `game.getSystem(RendererSystem)` |
150
+ | "Component already added" error | Use a new `Component` instance per `GameObject` |
151
+ | Resource name not found | Match `resource.addResource` `name` to component `resource` field |
152
+ | TS: `onError` missing on `SoundSystem` | `SoundSystem` requires `onError` callback |
153
+ | Stale render after async load | 3D: use `increaseAsyncId` / `validateAsyncId` to drop stale work |
160
154
 
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
155
 
167
- resource.addResource([{ name: 'logo', src: 'logo.png', preload: true }]);
156
+ ## Minimal 2D bootstrap
168
157
 
169
- new Game({
170
- systems: [
171
- new RendererSystem({ canvas: document.querySelector('#canvas')!, width: 750, height: 1334 }),
172
- new RenderSystem(),
173
- new ImgSystem(),
174
- ],
158
+ ```ts
159
+ import {
160
+ Game,
161
+ GameObject,
162
+ resource,
163
+ RESOURCE_TYPE,
164
+ LOAD_EVENT,
165
+ } from "@combos-fun/engine";
166
+ import { RendererSystem } from "@combos-fun/plugin-renderer";
167
+ import { Render, RenderSystem } from "@combos-fun/plugin-renderer-render";
168
+ import { Img, ImgSystem } from "@combos-fun/plugin-renderer-img";
169
+
170
+ resource.once(LOAD_EVENT.COMPLETE, () => {
171
+ new Game({
172
+ systems: [
173
+ new RendererSystem({
174
+ canvas: document.querySelector("#canvas")!,
175
+ width: 750,
176
+ height: 1334,
177
+ }),
178
+ new RenderSystem(),
179
+ new ImgSystem(),
180
+ ],
181
+ // Safe place to wire the scene graph: every system has finished init.
182
+ onSystemsBootstrapComplete: (g) => {
183
+ // Transform values go through constructor params — never set them imperatively.
184
+ const logo = new GameObject("logo", {
185
+ position: { x: 100, y: 100 },
186
+ size: { width: 200, height: 200 },
187
+ origin: { x: 0.5, y: 0.5 },
188
+ });
189
+ logo.addComponent(new Img({ resource: "logo" }));
190
+ // Render is only needed when you want to hide / fade / reorder; without it the
191
+ // object is still drawn at alpha 1, zIndex 0. Requires RenderSystem registered.
192
+ logo.addComponent(new Render({ zIndex: 5 }));
193
+ // Use addChild — not addGameObject — so transform parent + scene are both wired.
194
+ g.scene.addChild(logo);
195
+ },
196
+ });
175
197
  });
198
+
199
+ resource.loadConfig([
200
+ {
201
+ name: "logo",
202
+ type: RESOURCE_TYPE.IMAGE,
203
+ src: { image: { type: "png", url: "logo.png" } },
204
+ preload: true,
205
+ },
206
+ ]);
176
207
  ```
177
208
 
209
+ `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.
210
+
178
211
  ## Minimal 3D bootstrap
179
212
 
180
213
  ```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';
214
+ import { Game, GameObject } from "@combos-fun/engine";
215
+ import { Renderer3DSystem } from "@combos-fun/plugin-renderer-3d";
216
+ import {
217
+ Graphics3D,
218
+ Graphics3DSystem,
219
+ } from "@combos-fun/plugin-renderer-3d-graphics";
184
220
 
185
221
  new Game({
186
222
  systems: [
187
- new Renderer3DSystem({ canvas: document.querySelector('#canvas')!, width: 750, height: 1000 }),
223
+ new Renderer3DSystem({
224
+ canvas: document.querySelector("#canvas")!,
225
+ width: 750,
226
+ height: 1000,
227
+ }),
188
228
  new Graphics3DSystem(),
189
229
  ],
230
+ // Safe place to wire the scene graph: every system has finished init.
231
+ onSystemsBootstrapComplete: (g) => {
232
+ // 3D position / rotation / scale go through the component's own params
233
+ // (positionX/Y/Z, rotationX/Y/Z, scaleX/Y/Z) — GameObject's TransformParams
234
+ // is 2D-only (Vector2 + Size2) and is not read by 3D renderers.
235
+ const box = new GameObject("box");
236
+ box.addComponent(
237
+ new Graphics3D({
238
+ shape: "box",
239
+ width: 1,
240
+ height: 1,
241
+ depth: 1,
242
+ color: 0xff0000,
243
+ positionX: 0,
244
+ positionY: 1,
245
+ positionZ: 0,
246
+ }),
247
+ );
248
+ // Use addChild — not addGameObject — so transform parent + scene are both wired.
249
+ g.scene.addChild(box);
250
+ },
190
251
  });
191
252
  ```
192
253
 
@@ -202,3 +263,4 @@ After modifying engine code:
202
263
  ## See also
203
264
 
204
265
  - `@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.
266
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@combos-fun/engine",
3
- "version": "0.0.12",
3
+ "version": "0.0.13",
4
4
  "description": "ECS microkernel",
5
5
  "main": "index.js",
6
6
  "module": "dist/engine.esm.js",
@@ -43,7 +43,7 @@
43
43
  "lodash-es": "^4.17.21",
44
44
  "resource-loader": "^4.0.0-rc4",
45
45
  "sprite-timeline": "^1.10.2",
46
- "@combos-fun/inspector-decorator": "0.0.12"
46
+ "@combos-fun/inspector-decorator": "0.0.13"
47
47
  },
48
48
  "scripts": {
49
49
  "build": "node ../../scripts/build-package.mjs"