@combos-fun/engine 0.0.4 → 0.0.6

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.
@@ -958,12 +958,12 @@ class Scene extends GameObject {
958
958
  * Sent to `window.parent` after each `System.init` completes during `Game.addSystem`
959
959
  * (when running inside an iframe and parent differs from self).
960
960
  */
961
- const COMBOS_GAME_PLUGIN_INIT_SUCCESS = 'combos-game:plugin-init-success';
961
+ const COMBOS_GAME_PLUGIN_INIT_SUCCESS = "combos-game:plugin-init-success";
962
962
  /**
963
963
  * Notifies the embedding page that a system (plugin) finished async/sync `init`.
964
964
  */
965
- function postParentPluginInitSuccess(systemName, targetOrigin = '*') {
966
- if (typeof window === 'undefined')
965
+ function postParentPluginInitSuccess(systemName, targetOrigin = "*") {
966
+ if (typeof window === "undefined")
967
967
  return;
968
968
  if (!window.parent || window.parent === window)
969
969
  return;
@@ -980,20 +980,20 @@ function postParentPluginInitSuccess(systemName, targetOrigin = '*') {
980
980
  }
981
981
 
982
982
  function systemClassName(ctor) {
983
- if ('systemName' in ctor) {
983
+ if ("systemName" in ctor) {
984
984
  const sn = ctor.systemName;
985
- if (typeof sn === 'string')
985
+ if (typeof sn === "string")
986
986
  return sn;
987
987
  }
988
- return 'UnknownSystem';
988
+ return "UnknownSystem";
989
989
  }
990
990
  function componentClassName(ctor) {
991
- if ('componentName' in ctor) {
991
+ if ("componentName" in ctor) {
992
992
  const cn = ctor.componentName;
993
- if (typeof cn === 'string')
993
+ if (typeof cn === "string")
994
994
  return cn;
995
995
  }
996
- return 'UnknownComponent';
996
+ return "UnknownComponent";
997
997
  }
998
998
  exports.LOAD_SCENE_MODE = void 0;
999
999
  (function (LOAD_SCENE_MODE) {
@@ -1018,7 +1018,7 @@ const triggerStart = (obj) => {
1018
1018
  }
1019
1019
  }
1020
1020
  };
1021
- const getAllGameObjects = game => {
1021
+ const getAllGameObjects = (game) => {
1022
1022
  const mainSceneGameObjects = game?.scene?.gameObjects || [];
1023
1023
  const gameObjectsArray = game?.multiScenes.map(({ gameObjects }) => gameObjects);
1024
1024
  let otherSceneGameObjects = [];
@@ -1050,7 +1050,7 @@ const gameObjectLoop = (e, gameObjects = []) => {
1050
1050
  }
1051
1051
  }
1052
1052
  };
1053
- const gameObjectResume = gameObjects => {
1053
+ const gameObjectResume = (gameObjects) => {
1054
1054
  for (const gameObject of gameObjects) {
1055
1055
  for (const component of gameObject.components) {
1056
1056
  try {
@@ -1062,7 +1062,7 @@ const gameObjectResume = gameObjects => {
1062
1062
  }
1063
1063
  }
1064
1064
  };
1065
- const gameObjectPause = gameObjects => {
1065
+ const gameObjectPause = (gameObjects) => {
1066
1066
  for (const gameObject of gameObjects) {
1067
1067
  for (const component of gameObject.components) {
1068
1068
  try {
@@ -1075,7 +1075,7 @@ const gameObjectPause = gameObjects => {
1075
1075
  }
1076
1076
  };
1077
1077
  class Game extends EventEmitter__default.default {
1078
- constructor({ systems, frameRate = 60, autoStart = true, needScene = true, onSystemsBootstrapComplete, pluginInitNotifyTargetOrigin = '*', } = {}) {
1078
+ constructor({ systems, frameRate = 60, autoStart = true, needScene = true, onSystemsBootstrapComplete, pluginInitNotifyTargetOrigin = "*", } = {}) {
1079
1079
  super();
1080
1080
  /**
1081
1081
  * State of game
@@ -1089,7 +1089,7 @@ class Game extends EventEmitter__default.default {
1089
1089
  /**
1090
1090
  * Passed to `postMessage` when reporting `COMBOS_GAME_PLUGIN_INIT_SUCCESS` to `window.parent`.
1091
1091
  */
1092
- this.pluginInitNotifyTargetOrigin = '*';
1092
+ this.pluginInitNotifyTargetOrigin = "*";
1093
1093
  this.pluginInitNotifyTargetOrigin = pluginInitNotifyTargetOrigin;
1094
1094
  this.ticker = new Ticker({ autoStart: false, frameRate });
1095
1095
  this.initTicker();
@@ -1109,7 +1109,7 @@ class Game extends EventEmitter__default.default {
1109
1109
  await this.addSystem(system);
1110
1110
  }
1111
1111
  if (needScene) {
1112
- this.loadScene(new Scene('scene'));
1112
+ this.loadScene(new Scene("scene"));
1113
1113
  }
1114
1114
  if (autoStart) {
1115
1115
  this.start();
@@ -1117,7 +1117,7 @@ class Game extends EventEmitter__default.default {
1117
1117
  }
1118
1118
  catch (e) {
1119
1119
  error = e;
1120
- console.error('Game bootstrap failed', e);
1120
+ console.error("Game bootstrap failed", e);
1121
1121
  }
1122
1122
  finally {
1123
1123
  onComplete?.(this, error);
@@ -1150,10 +1150,10 @@ class Game extends EventEmitter__default.default {
1150
1150
  system = S;
1151
1151
  }
1152
1152
  else {
1153
- console.warn('can only add System');
1153
+ console.warn("can only add System");
1154
1154
  return;
1155
1155
  }
1156
- const hasTheSystem = this.systems.find(item => {
1156
+ const hasTheSystem = this.systems.find((item) => {
1157
1157
  return item.constructor === system.constructor;
1158
1158
  });
1159
1159
  if (hasTheSystem) {
@@ -1184,14 +1184,14 @@ class Game extends EventEmitter__default.default {
1184
1184
  if (!system)
1185
1185
  return;
1186
1186
  let index = -1;
1187
- if (typeof system === 'string') {
1188
- index = this.systems.findIndex(s => s.name === system);
1187
+ if (typeof system === "string") {
1188
+ index = this.systems.findIndex((s) => s.name === system);
1189
1189
  }
1190
1190
  else if (system instanceof Function) {
1191
- index = this.systems.findIndex(s => s.constructor === system);
1191
+ index = this.systems.findIndex((s) => s.constructor === system);
1192
1192
  }
1193
1193
  else if (system instanceof System) {
1194
- index = this.systems.findIndex(s => s === system);
1194
+ index = this.systems.findIndex((s) => s === system);
1195
1195
  }
1196
1196
  if (index > -1) {
1197
1197
  this.systems[index].destroy && this.systems[index].destroy();
@@ -1204,8 +1204,8 @@ class Game extends EventEmitter__default.default {
1204
1204
  * @returns system instance
1205
1205
  */
1206
1206
  getSystem(S) {
1207
- return this.systems.find(system => {
1208
- if (typeof S === 'string') {
1207
+ return this.systems.find((system) => {
1208
+ if (typeof S === "string") {
1209
1209
  return system.name === S;
1210
1210
  }
1211
1211
  else {
@@ -1247,7 +1247,7 @@ class Game extends EventEmitter__default.default {
1247
1247
  * 4. call lastUpdate method on all system
1248
1248
  */
1249
1249
  initTicker() {
1250
- this.ticker.add(e => {
1250
+ this.ticker.add((e) => {
1251
1251
  this.scene && gameObjectLoop(e, this.gameObjects);
1252
1252
  for (const system of this.systems) {
1253
1253
  try {
@@ -1311,7 +1311,7 @@ class Game extends EventEmitter__default.default {
1311
1311
  this.canvas = null;
1312
1312
  this.multiScenes = null;
1313
1313
  }
1314
- loadScene({ scene, mode = exports.LOAD_SCENE_MODE.SINGLE, params = {} }) {
1314
+ loadScene({ scene, mode = exports.LOAD_SCENE_MODE.SINGLE, params = {}, }) {
1315
1315
  if (!scene) {
1316
1316
  return;
1317
1317
  }
@@ -1323,7 +1323,7 @@ class Game extends EventEmitter__default.default {
1323
1323
  this.multiScenes.push(scene);
1324
1324
  break;
1325
1325
  }
1326
- this.emit('sceneChanged', { scene, mode, params });
1326
+ this.emit("sceneChanged", { scene, mode, params });
1327
1327
  }
1328
1328
  }
1329
1329
 
@@ -1433,6 +1433,7 @@ exports.RESOURCE_TYPE = void 0;
1433
1433
  RESOURCE_TYPE["SPRITE_ANIMATION"] = "SPRITE_ANIMATION";
1434
1434
  RESOURCE_TYPE["AUDIO"] = "AUDIO";
1435
1435
  RESOURCE_TYPE["VIDEO"] = "VIDEO";
1436
+ RESOURCE_TYPE["GLB"] = "GLB";
1436
1437
  })(exports.RESOURCE_TYPE || (exports.RESOURCE_TYPE = {}));
1437
1438
  resourceLoader$1.XhrLoadStrategy.setExtensionXhrType('json', resourceLoader$1.XhrResponseType.Json);
1438
1439
  resourceLoader$1.XhrLoadStrategy.setExtensionXhrType('tex', resourceLoader$1.XhrResponseType.Json);
@@ -1441,6 +1442,8 @@ resourceLoader$1.XhrLoadStrategy.setExtensionXhrType('mp3', resourceLoader$1.Xhr
1441
1442
  resourceLoader$1.XhrLoadStrategy.setExtensionXhrType('wav', resourceLoader$1.XhrResponseType.Buffer);
1442
1443
  resourceLoader$1.XhrLoadStrategy.setExtensionXhrType('aac', resourceLoader$1.XhrResponseType.Buffer);
1443
1444
  resourceLoader$1.XhrLoadStrategy.setExtensionXhrType('ogg', resourceLoader$1.XhrResponseType.Buffer);
1445
+ resourceLoader$1.XhrLoadStrategy.setExtensionXhrType('glb', resourceLoader$1.XhrResponseType.Buffer);
1446
+ resourceLoader$1.XhrLoadStrategy.setExtensionXhrType('gltf', resourceLoader$1.XhrResponseType.Json);
1444
1447
  const RESOURCE_TYPE_STRATEGY = {
1445
1448
  png: resourceLoader$1.ImageLoadStrategy,
1446
1449
  jpg: resourceLoader$1.ImageLoadStrategy,
@@ -1451,6 +1454,8 @@ const RESOURCE_TYPE_STRATEGY = {
1451
1454
  ske: resourceLoader$1.XhrLoadStrategy,
1452
1455
  audio: resourceLoader$1.XhrLoadStrategy,
1453
1456
  video: resourceLoader$1.VideoLoadStrategy,
1457
+ glb: resourceLoader$1.XhrLoadStrategy,
1458
+ gltf: resourceLoader$1.XhrLoadStrategy,
1454
1459
  };
1455
1460
  /**
1456
1461
  * Resource manager