@combos-fun/engine 0.0.10 → 0.0.12

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.
@@ -35,6 +35,12 @@ function getComponentName(component) {
35
35
  * @public
36
36
  */
37
37
  class Component extends EventEmitter__default.default {
38
+ /**
39
+ * Get the game instance this component belongs to
40
+ */
41
+ get game() {
42
+ return this.gameObject?.scene?.game;
43
+ }
38
44
  constructor(params) {
39
45
  super();
40
46
  /**
@@ -80,8 +86,10 @@ function getObjectCache(component, keys) {
80
86
  }
81
87
  const keyIndex = keys.length - 1;
82
88
  let property = component;
83
- // FIXME: Bug is here, property[keys[i]] maybe undefined
84
89
  for (let i = 0; i < keyIndex; i++) {
90
+ if (property[keys[i]] === undefined || property[keys[i]] === null) {
91
+ return { property: undefined, key: undefined };
92
+ }
85
93
  property = property[keys[i]];
86
94
  }
87
95
  cache[key] = { property, key: keys[keyIndex] };
@@ -321,7 +329,7 @@ class Transform extends Component {
321
329
  for (const key of props) {
322
330
  Object.assign(this[key], params[key]);
323
331
  }
324
- this.rotation = params.rotation || this.rotation;
332
+ this.rotation = params.rotation ?? this.rotation;
325
333
  }
326
334
  set parent(val) {
327
335
  if (val) {
@@ -584,7 +592,7 @@ class GameObject {
584
592
  if (this.parent)
585
593
  return this.parent.removeChild(this);
586
594
  }
587
- /** Destory this gameObject */
595
+ /** Destroy this gameObject */
588
596
  destroy() {
589
597
  if (!this.transform) {
590
598
  console.error('Cannot destroy gameObject that have already been destroyed.');
@@ -678,7 +686,7 @@ class System {
678
686
  const Ctor = this.constructor;
679
687
  this.name = Ctor.systemName;
680
688
  }
681
- /** Default destory method */
689
+ /** Default destroy method */
682
690
  destroy() {
683
691
  this.componentObserver = null;
684
692
  this.__systemDefaultParams = null;
@@ -873,6 +881,7 @@ class Ticker {
873
881
  this._lastFrameTime = frameTime;
874
882
  const options = {
875
883
  deltaTime,
884
+ delta: deltaTime,
876
885
  time: frameTime,
877
886
  currentTime: frameTime,
878
887
  frameCount: ++this._frameCount,
@@ -1069,7 +1078,7 @@ const gameObjectPause = (gameObjects) => {
1069
1078
  component.onPause && component.onPause();
1070
1079
  }
1071
1080
  catch (e) {
1072
- console.error(`gameObject: ${gameObject.name}, ${component.name}, onResume error`, e);
1081
+ console.error(`gameObject: ${gameObject.name}, ${component.name}, onPause error`, e);
1073
1082
  }
1074
1083
  }
1075
1084
  }
@@ -1109,7 +1118,7 @@ class Game extends EventEmitter__default.default {
1109
1118
  await this.addSystem(system);
1110
1119
  }
1111
1120
  if (needScene) {
1112
- this.loadScene(new Scene("scene"));
1121
+ this.loadScene({ scene: new Scene("scene") });
1113
1122
  }
1114
1123
  if (autoStart) {
1115
1124
  this.start();
@@ -1315,6 +1324,7 @@ class Game extends EventEmitter__default.default {
1315
1324
  if (!scene) {
1316
1325
  return;
1317
1326
  }
1327
+ scene.game = this;
1318
1328
  switch (mode) {
1319
1329
  case exports.LOAD_SCENE_MODE.SINGLE:
1320
1330
  this.scene = scene;
@@ -1538,7 +1548,7 @@ class Resource extends EventEmitter__default.default {
1538
1548
  const res = this.resourcesMap[name];
1539
1549
  return this.makeInstanceFunctions[res.type] && (await this.makeInstanceFunctions[res.type](res));
1540
1550
  }
1541
- /** destory this resource manager */
1551
+ /** Destroy resource by name */
1542
1552
  async destroy(name) {
1543
1553
  await this._destroy(name);
1544
1554
  }