@combos-fun/engine 0.0.4 → 0.0.5
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/dist/engine.cjs.js +27 -29
- package/dist/engine.cjs.js.map +1 -1
- package/dist/engine.cjs.prod.js +1 -1
- package/dist/engine.d.ts +5 -20
- package/dist/engine.esm.js +28 -28
- package/dist/engine.esm.js.map +1 -1
- package/package.json +2 -2
package/dist/engine.cjs.js
CHANGED
|
@@ -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 =
|
|
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 ===
|
|
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 (
|
|
983
|
+
if ("systemName" in ctor) {
|
|
984
984
|
const sn = ctor.systemName;
|
|
985
|
-
if (typeof sn ===
|
|
985
|
+
if (typeof sn === "string")
|
|
986
986
|
return sn;
|
|
987
987
|
}
|
|
988
|
-
return
|
|
988
|
+
return "UnknownSystem";
|
|
989
989
|
}
|
|
990
990
|
function componentClassName(ctor) {
|
|
991
|
-
if (
|
|
991
|
+
if ("componentName" in ctor) {
|
|
992
992
|
const cn = ctor.componentName;
|
|
993
|
-
if (typeof cn ===
|
|
993
|
+
if (typeof cn === "string")
|
|
994
994
|
return cn;
|
|
995
995
|
}
|
|
996
|
-
return
|
|
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(
|
|
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(
|
|
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(
|
|
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 ===
|
|
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 ===
|
|
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(
|
|
1326
|
+
this.emit("sceneChanged", { scene, mode, params });
|
|
1327
1327
|
}
|
|
1328
1328
|
}
|
|
1329
1329
|
|
|
@@ -1697,7 +1697,6 @@ const decorators = {
|
|
|
1697
1697
|
const version = '__VERSION__';
|
|
1698
1698
|
console.log(`@combos-fun/engine version: ${version}`);
|
|
1699
1699
|
|
|
1700
|
-
exports.COMBOS_GAME_PLUGIN_INIT_SUCCESS = COMBOS_GAME_PLUGIN_INIT_SUCCESS;
|
|
1701
1700
|
exports.Component = Component;
|
|
1702
1701
|
exports.Game = Game;
|
|
1703
1702
|
exports.GameObject = GameObject;
|
|
@@ -1708,7 +1707,6 @@ exports.System = System;
|
|
|
1708
1707
|
exports.Transform = Transform;
|
|
1709
1708
|
exports.componentObserver = componentObserver;
|
|
1710
1709
|
exports.decorators = decorators;
|
|
1711
|
-
exports.postParentPluginInitSuccess = postParentPluginInitSuccess;
|
|
1712
1710
|
exports.resource = resource;
|
|
1713
1711
|
exports.resourceLoader = resourceLoader;
|
|
1714
1712
|
exports.version = version;
|