@combos-fun/engine 0.0.3 → 0.0.4

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.
@@ -954,6 +954,31 @@ class Scene extends GameObject {
954
954
  }
955
955
  }
956
956
 
957
+ /**
958
+ * Sent to `window.parent` after each `System.init` completes during `Game.addSystem`
959
+ * (when running inside an iframe and parent differs from self).
960
+ */
961
+ const COMBOS_GAME_PLUGIN_INIT_SUCCESS = 'combos-game:plugin-init-success';
962
+ /**
963
+ * Notifies the embedding page that a system (plugin) finished async/sync `init`.
964
+ */
965
+ function postParentPluginInitSuccess(systemName, targetOrigin = '*') {
966
+ if (typeof window === 'undefined')
967
+ return;
968
+ if (!window.parent || window.parent === window)
969
+ return;
970
+ const payload = {
971
+ type: COMBOS_GAME_PLUGIN_INIT_SUCCESS,
972
+ systemName,
973
+ };
974
+ try {
975
+ window.parent.postMessage(payload, targetOrigin);
976
+ }
977
+ catch {
978
+ /* ignore cross-origin or detached frame */
979
+ }
980
+ }
981
+
957
982
  function systemClassName(ctor) {
958
983
  if ('systemName' in ctor) {
959
984
  const sn = ctor.systemName;
@@ -1050,7 +1075,7 @@ const gameObjectPause = gameObjects => {
1050
1075
  }
1051
1076
  };
1052
1077
  class Game extends EventEmitter__default.default {
1053
- constructor({ systems, frameRate = 60, autoStart = true, needScene = true, onSystemsBootstrapComplete, } = {}) {
1078
+ constructor({ systems, frameRate = 60, autoStart = true, needScene = true, onSystemsBootstrapComplete, pluginInitNotifyTargetOrigin = '*', } = {}) {
1054
1079
  super();
1055
1080
  /**
1056
1081
  * State of game
@@ -1061,6 +1086,11 @@ class Game extends EventEmitter__default.default {
1061
1086
  this.multiScenes = [];
1062
1087
  /** Systems alled to this game */
1063
1088
  this.systems = [];
1089
+ /**
1090
+ * Passed to `postMessage` when reporting `COMBOS_GAME_PLUGIN_INIT_SUCCESS` to `window.parent`.
1091
+ */
1092
+ this.pluginInitNotifyTargetOrigin = '*';
1093
+ this.pluginInitNotifyTargetOrigin = pluginInitNotifyTargetOrigin;
1064
1094
  this.ticker = new Ticker({ autoStart: false, frameRate });
1065
1095
  this.initTicker();
1066
1096
  if (systems && systems.length) {
@@ -1134,6 +1164,7 @@ class Game extends EventEmitter__default.default {
1134
1164
  if (system.init) {
1135
1165
  await Promise.resolve(system.init(system.__systemDefaultParams));
1136
1166
  }
1167
+ postParentPluginInitSuccess(systemClassName(system.constructor), this.pluginInitNotifyTargetOrigin);
1137
1168
  setSystemObserver(system, system.constructor);
1138
1169
  initObserver(system.constructor);
1139
1170
  try {
@@ -1666,6 +1697,7 @@ const decorators = {
1666
1697
  const version = '__VERSION__';
1667
1698
  console.log(`@combos-fun/engine version: ${version}`);
1668
1699
 
1700
+ exports.COMBOS_GAME_PLUGIN_INIT_SUCCESS = COMBOS_GAME_PLUGIN_INIT_SUCCESS;
1669
1701
  exports.Component = Component;
1670
1702
  exports.Game = Game;
1671
1703
  exports.GameObject = GameObject;
@@ -1676,6 +1708,7 @@ exports.System = System;
1676
1708
  exports.Transform = Transform;
1677
1709
  exports.componentObserver = componentObserver;
1678
1710
  exports.decorators = decorators;
1711
+ exports.postParentPluginInitSuccess = postParentPluginInitSuccess;
1679
1712
  exports.resource = resource;
1680
1713
  exports.resourceLoader = resourceLoader;
1681
1714
  exports.version = version;