@combos-fun/engine 0.1.19 → 0.1.21

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
@@ -9,10 +9,10 @@ ECS microkernel. New plugins: `plugin-authoring.md`.
9
9
  - Per-entity state on Components, so destroying a GameObject removes it. Cross-entity work in Systems. Remove listeners in `onDestroy`.
10
10
  - Bootstrap only wires resources, Systems, GameObjects, and Components. Configure in the constructor; act from lifecycle or events.
11
11
  - Custom Components set `static componentName`. Do not scan the scene for them.
12
- - Use renderer plugins or a registered `Renderer` / `Renderer3D`. Host-owned plugins may touch raw Pixi, Three, or DOM. Host messages: `combos-game:*` only here; plugins use `combos-development-tool:*`.
12
+ - Use renderer plugins or a registered `Renderer` / `Renderer3D`.
13
13
  - `game.getSystem(SystemClass)`. String form is `static systemName`, not the class name.
14
14
  - Scene: `game.scene`.
15
15
  - Component `game` is a getter (`gameObject?.scene?.game`), after the GameObject is in the scene. System `game` is set in `addSystem`.
16
16
  - `componentObserver.clear()` events may omit `gameObject`.
17
- - `resource.addResource`. Each `src` slot is a url string or `{ type, url }`. `preload` only removes first-use delay.
17
+ - `resource.addResource`. Each `src` slot is a url string or `{ type, url }`. `preload: true` loads during startup. Lazy `getResource` loads on first use.
18
18
  - Inspector fields: `@Field` from `@combos-fun/inspector-decorator`. Engine `IDEProp` is legacy.
@@ -891,7 +891,7 @@ class Scene extends GameObject {
891
891
  }
892
892
 
893
893
  /** Generated at build from package.json */
894
- const version = "0.1.19";
894
+ const version = "0.1.21";
895
895
 
896
896
  /**
897
897
  * Sent to `window.parent` after each `System.init` completes during `Game.addSystem`
@@ -901,7 +901,8 @@ const COMBOS_GAME_PLUGIN_INIT_SUCCESS = "combos-game:plugin-init-success";
901
901
  /**
902
902
  * iframe → parent: game bootstrap finished (all systems `init`/`awake`, optional
903
903
  * scene load and `start`). Sent once, even when `autoStart` is `false`, so the host
904
- * knows assets + scene graph are ready and it may pause / hold before play.
904
+ * knows the scene graph is ready and it may pause / hold before play.
905
+ * Asset preload is a separate batch: {@link COMBOS_GAME_RESOURCES_READY}.
905
906
  */
906
907
  const COMBOS_GAME_READY = "combos-game:ready";
907
908
  /**
@@ -913,6 +914,23 @@ const COMBOS_GAME_SET_PLAYING = "combos-game:set-playing";
913
914
  * iframe → parent: current run state after a `start` / `pause` / `resume`.
914
915
  */
915
916
  const COMBOS_GAME_STATE_CHANGED = "combos-game:state-changed";
917
+ /**
918
+ * iframe → parent: one preload-batch resource settled (success or failure).
919
+ * Lazy `getResource` loads do not emit this.
920
+ */
921
+ const COMBOS_GAME_RESOURCE_PROGRESS = "combos-game:resource-progress";
922
+ /**
923
+ * iframe → parent: the current `preload()` batch reached `loaded === total`.
924
+ * Sent once per batch. `failed.length === 0` means every item succeeded.
925
+ * `total: 0` means that call had no `preload: true` resources.
926
+ */
927
+ const COMBOS_GAME_RESOURCES_READY = "combos-game:resources-ready";
928
+ /** Shared with `Game.pluginInitNotifyTargetOrigin` so preload can post before or after `new Game`. */
929
+ let parentNotifyTargetOrigin = "*";
930
+ /** Called from `Game` so later preload batches use the same `targetOrigin` as lifecycle posts. */
931
+ function setParentNotifyTargetOrigin(targetOrigin) {
932
+ parentNotifyTargetOrigin = targetOrigin || "*";
933
+ }
916
934
  function postToParent(payload, targetOrigin) {
917
935
  if (typeof window === "undefined")
918
936
  return;
@@ -949,6 +967,28 @@ function postParentGameReady(error, targetOrigin = "*") {
949
967
  };
950
968
  postToParent(payload, targetOrigin);
951
969
  }
970
+ /** Notifies the embedding page that one preload-batch resource settled. */
971
+ function postParentResourceProgress(input, targetOrigin = parentNotifyTargetOrigin) {
972
+ const payload = {
973
+ type: COMBOS_GAME_RESOURCE_PROGRESS,
974
+ name: input.name,
975
+ loaded: input.loaded,
976
+ total: input.total,
977
+ progress: input.progress,
978
+ success: input.success,
979
+ ...(input.success ? {} : { error: input.error ?? "load failed" }),
980
+ };
981
+ postToParent(payload, targetOrigin);
982
+ }
983
+ /** Notifies the embedding page that the current preload batch finished. */
984
+ function postParentResourcesReady(input, targetOrigin = parentNotifyTargetOrigin) {
985
+ const payload = {
986
+ type: COMBOS_GAME_RESOURCES_READY,
987
+ total: input.total,
988
+ failed: input.failed,
989
+ };
990
+ postToParent(payload, targetOrigin);
991
+ }
952
992
  /** Notifies the embedding page of the current play/pause state. */
953
993
  function postParentGameState(state, targetOrigin = "*") {
954
994
  const payload = {
@@ -1157,7 +1197,7 @@ class Game extends EventEmitter__default.default {
1157
1197
  this.systems = [];
1158
1198
  /**
1159
1199
  * Passed to `postMessage` when reporting lifecycle events to `window.parent`
1160
- * (`plugin-init-success`, `ready`, `state-changed`).
1200
+ * (`plugin-init-success`, `ready`, `state-changed`, `resource-progress`, `resources-ready`).
1161
1201
  */
1162
1202
  this.pluginInitNotifyTargetOrigin = "*";
1163
1203
  /** Inbound `postMessage` origins allowed to send host commands. */
@@ -1172,6 +1212,7 @@ class Game extends EventEmitter__default.default {
1172
1212
  this.setPlaying(playing);
1173
1213
  };
1174
1214
  this.pluginInitNotifyTargetOrigin = pluginInitNotifyTargetOrigin;
1215
+ setParentNotifyTargetOrigin(pluginInitNotifyTargetOrigin);
1175
1216
  this.allowedMessageOrigins = mergeAllowedMessageOrigins(allowedMessageOrigins);
1176
1217
  this.ticker = new Ticker({ autoStart: false, frameRate });
1177
1218
  this.initTicker();
@@ -1534,10 +1575,12 @@ class Progress extends EventEmitter__default.default {
1534
1575
  this.progress = 0;
1535
1576
  this.resourceTotal = 0;
1536
1577
  this.resourceLoadedCount = 0;
1578
+ this.failed = [];
1537
1579
  this.resource = resource;
1538
1580
  this.resourceTotal = resourceTotal;
1539
1581
  if (resourceTotal === 0) {
1540
1582
  this.resource.emit(exports.LOAD_EVENT.COMPLETE, this);
1583
+ this.notifyResourcesReady();
1541
1584
  }
1542
1585
  }
1543
1586
  onStart() {
@@ -1550,13 +1593,30 @@ class Progress extends EventEmitter__default.default {
1550
1593
  this.resource.emit(exports.LOAD_EVENT.LOADED, this, param);
1551
1594
  }
1552
1595
  else {
1596
+ const error = param.errMsg || 'load failed';
1597
+ this.failed.push({ name: param.name, error });
1553
1598
  this.resource.emit(exports.LOAD_EVENT.ERROR, this, param);
1554
1599
  }
1555
1600
  this.resource.emit(exports.LOAD_EVENT.PROGRESS, this, param);
1601
+ postParentResourceProgress({
1602
+ name: param.name,
1603
+ loaded: this.resourceLoadedCount,
1604
+ total: this.resourceTotal,
1605
+ progress: this.progress,
1606
+ success: param.success,
1607
+ ...(param.success ? {} : { error: param.errMsg || 'load failed' }),
1608
+ });
1556
1609
  if (this.resourceLoadedCount === this.resourceTotal) {
1557
1610
  this.resource.emit(exports.LOAD_EVENT.COMPLETE, this);
1611
+ this.notifyResourcesReady();
1558
1612
  }
1559
1613
  }
1614
+ notifyResourcesReady() {
1615
+ postParentResourcesReady({
1616
+ total: this.resourceTotal,
1617
+ failed: this.failed.slice(),
1618
+ });
1619
+ }
1560
1620
  }
1561
1621
 
1562
1622
  const SLOT_DEFAULT_TYPE = {
@@ -2485,6 +2545,8 @@ console.log(`@combos-fun/engine version: ${version}`);
2485
2545
  exports.AdaptivePixelRatio = AdaptivePixelRatio;
2486
2546
  exports.COMBOS_GAME_PLUGIN_INIT_SUCCESS = COMBOS_GAME_PLUGIN_INIT_SUCCESS;
2487
2547
  exports.COMBOS_GAME_READY = COMBOS_GAME_READY;
2548
+ exports.COMBOS_GAME_RESOURCES_READY = COMBOS_GAME_RESOURCES_READY;
2549
+ exports.COMBOS_GAME_RESOURCE_PROGRESS = COMBOS_GAME_RESOURCE_PROGRESS;
2488
2550
  exports.COMBOS_GAME_SET_PLAYING = COMBOS_GAME_SET_PLAYING;
2489
2551
  exports.COMBOS_GAME_STATE_CHANGED = COMBOS_GAME_STATE_CHANGED;
2490
2552
  exports.Component = Component;
@@ -2509,6 +2571,8 @@ exports.parseSetPlayingMessage = parseSetPlayingMessage;
2509
2571
  exports.postParentGameReady = postParentGameReady;
2510
2572
  exports.postParentGameState = postParentGameState;
2511
2573
  exports.postParentPluginInitSuccess = postParentPluginInitSuccess;
2574
+ exports.postParentResourceProgress = postParentResourceProgress;
2575
+ exports.postParentResourcesReady = postParentResourcesReady;
2512
2576
  exports.readSpriteClipSheet = readSpriteClipSheet;
2513
2577
  exports.resolveRenderQuality = resolveRenderQuality;
2514
2578
  exports.resolveSpriteClip = resolveSpriteClip;