@eva/eva.js 2.0.0-beta.1 → 2.0.0-beta.2

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.
@@ -12,113 +12,6 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
12
12
 
13
13
  var EventEmitter__default = /*#__PURE__*/_interopDefaultLegacy(EventEmitter);
14
14
 
15
- /*! *****************************************************************************
16
- Copyright (c) Microsoft Corporation. All rights reserved.
17
- Licensed under the Apache License, Version 2.0 (the "License"); you may not use
18
- this file except in compliance with the License. You may obtain a copy of the
19
- License at http://www.apache.org/licenses/LICENSE-2.0
20
-
21
- THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
22
- KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
23
- WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
24
- MERCHANTABLITY OR NON-INFRINGEMENT.
25
-
26
- See the Apache Version 2.0 License for specific language governing permissions
27
- and limitations under the License.
28
- ***************************************************************************** */
29
- /* global Reflect, Promise */
30
-
31
- var extendStatics = function(d, b) {
32
- extendStatics = Object.setPrototypeOf ||
33
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
34
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
35
- return extendStatics(d, b);
36
- };
37
-
38
- function __extends(d, b) {
39
- extendStatics(d, b);
40
- function __() { this.constructor = d; }
41
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
42
- }
43
-
44
- function __decorate(decorators, target, key, desc) {
45
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
46
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
47
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
48
- return c > 3 && r && Object.defineProperty(target, key, r), r;
49
- }
50
-
51
- function __awaiter(thisArg, _arguments, P, generator) {
52
- return new (P || (P = Promise))(function (resolve, reject) {
53
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
54
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
55
- function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
56
- step((generator = generator.apply(thisArg, _arguments || [])).next());
57
- });
58
- }
59
-
60
- function __generator(thisArg, body) {
61
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
62
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
63
- function verb(n) { return function (v) { return step([n, v]); }; }
64
- function step(op) {
65
- if (f) throw new TypeError("Generator is already executing.");
66
- while (_) try {
67
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
68
- if (y = 0, t) op = [op[0] & 2, t.value];
69
- switch (op[0]) {
70
- case 0: case 1: t = op; break;
71
- case 4: _.label++; return { value: op[1], done: false };
72
- case 5: _.label++; y = op[1]; op = [0]; continue;
73
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
74
- default:
75
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
76
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
77
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
78
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
79
- if (t[2]) _.ops.pop();
80
- _.trys.pop(); continue;
81
- }
82
- op = body.call(thisArg, _);
83
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
84
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
85
- }
86
- }
87
-
88
- function __values(o) {
89
- var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
90
- if (m) return m.call(o);
91
- return {
92
- next: function () {
93
- if (o && i >= o.length) o = void 0;
94
- return { value: o && o[i++], done: !o };
95
- }
96
- };
97
- }
98
-
99
- function __read(o, n) {
100
- var m = typeof Symbol === "function" && o[Symbol.iterator];
101
- if (!m) return o;
102
- var i = m.call(o), r, ar = [], e;
103
- try {
104
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
105
- }
106
- catch (error) { e = { error: error }; }
107
- finally {
108
- try {
109
- if (r && !r.done && (m = i["return"])) m.call(i);
110
- }
111
- finally { if (e) throw e.error; }
112
- }
113
- return ar;
114
- }
115
-
116
- function __spread() {
117
- for (var ar = [], i = 0; i < arguments.length; i++)
118
- ar = ar.concat(__read(arguments[i]));
119
- return ar;
120
- }
121
-
122
15
  function getComponentName(component) {
123
16
  if (component instanceof Component) {
124
17
  return component.name;
@@ -127,17 +20,14 @@ function getComponentName(component) {
127
20
  return component.componentName;
128
21
  }
129
22
  }
130
- var Component = (function (_super) {
131
- __extends(Component, _super);
132
- function Component(params) {
133
- var _this = _super.call(this) || this;
134
- _this.started = false;
135
- _this.name = _this.constructor.componentName;
136
- _this.__componentDefaultParams = params;
137
- return _this;
138
- }
139
- return Component;
140
- }(EventEmitter__default));
23
+ class Component extends EventEmitter__default {
24
+ constructor(params) {
25
+ super();
26
+ this.started = false;
27
+ this.name = this.constructor.componentName;
28
+ this.__componentDefaultParams = params;
29
+ }
30
+ }
141
31
  var Component$1 = Component;
142
32
 
143
33
  exports.OBSERVER_TYPE = void 0;
@@ -146,25 +36,25 @@ exports.OBSERVER_TYPE = void 0;
146
36
  ObserverType["REMOVE"] = "REMOVE";
147
37
  ObserverType["CHANGE"] = "CHANGE";
148
38
  })(exports.OBSERVER_TYPE || (exports.OBSERVER_TYPE = {}));
149
- var objectCache = {};
150
- var systemInstance = {};
151
- var observerInfos = {};
152
- var componentProps = {};
39
+ const objectCache = {};
40
+ const systemInstance = {};
41
+ const observerInfos = {};
42
+ const componentProps = {};
153
43
  function getObjectCache(component, keys) {
154
44
  if (!objectCache[component.gameObject.id]) {
155
45
  objectCache[component.gameObject.id] = {};
156
46
  }
157
- var cache = objectCache[component.gameObject.id];
158
- var key = component.name + '_' + keys.join(',');
47
+ const cache = objectCache[component.gameObject.id];
48
+ const key = component.name + '_' + keys.join(',');
159
49
  if (cache[key]) {
160
50
  return cache[key];
161
51
  }
162
- var keyIndex = keys.length - 1;
163
- var property = component;
164
- for (var i = 0; i < keyIndex; i++) {
52
+ const keyIndex = keys.length - 1;
53
+ let property = component;
54
+ for (let i = 0; i < keyIndex; i++) {
165
55
  property = property[keys[i]];
166
56
  }
167
- cache[key] = { property: property, key: keys[keyIndex] };
57
+ cache[key] = { property, key: keys[keyIndex] };
168
58
  return cache[key];
169
59
  }
170
60
  function removeObjectCache(component) {
@@ -172,83 +62,69 @@ function removeObjectCache(component) {
172
62
  delete objectCache[component.gameObject.id];
173
63
  }
174
64
  }
175
- function addObserver(_a) {
176
- var _b, _c;
177
- var systemName = _a.systemName, componentName = _a.componentName, component = _a.component, prop = _a.prop, type = _a.type;
178
- (_c = (_b = systemInstance[systemName]) === null || _b === void 0 ? void 0 : _b.componentObserver) === null || _c === void 0 ? void 0 : _c.add({
179
- component: component,
180
- prop: prop,
181
- type: type,
182
- componentName: componentName,
65
+ function addObserver({ systemName, componentName, component, prop, type }) {
66
+ var _a, _b;
67
+ (_b = (_a = systemInstance[systemName]) === null || _a === void 0 ? void 0 : _a.componentObserver) === null || _b === void 0 ? void 0 : _b.add({
68
+ component,
69
+ prop,
70
+ type,
71
+ componentName,
183
72
  });
184
73
  }
185
- function pushToQueue(_a) {
186
- var prop = _a.prop, component = _a.component, componentName = _a.componentName;
187
- for (var systemName in observerInfos) {
188
- var observerInfo = observerInfos[systemName] || {};
189
- var info = observerInfo[componentName];
74
+ function pushToQueue({ prop, component, componentName, }) {
75
+ for (const systemName in observerInfos) {
76
+ const observerInfo = observerInfos[systemName] || {};
77
+ const info = observerInfo[componentName];
190
78
  if (!info)
191
79
  continue;
192
- var index = info.findIndex(function (p) {
80
+ const index = info.findIndex(p => {
193
81
  return lodashEs.isEqual(p, prop);
194
82
  });
195
83
  if (index > -1) {
196
84
  addObserver({
197
- systemName: systemName,
198
- componentName: componentName,
199
- component: component,
200
- prop: prop,
85
+ systemName,
86
+ componentName,
87
+ component,
88
+ prop,
201
89
  type: exports.OBSERVER_TYPE.CHANGE,
202
90
  });
203
91
  }
204
92
  }
205
93
  }
206
- function defineProperty(_a) {
207
- var e_1, _b;
208
- var obj = _a.obj, key = _a.key, prop = _a.prop, component = _a.component, componentName = _a.componentName;
94
+ function defineProperty({ obj, key, prop, component, componentName, }) {
209
95
  if (obj === undefined) {
210
96
  return;
211
97
  }
212
98
  if (!(key in obj)) {
213
- console.error("prop " + key + " not in component: " + componentName + ", Can not observer");
99
+ console.error(`prop ${key} not in component: ${componentName}, Can not observer`);
214
100
  return;
215
101
  }
216
- Object.defineProperty(obj, "_" + key, {
102
+ Object.defineProperty(obj, `_${key}`, {
217
103
  enumerable: false,
218
104
  writable: true,
219
105
  value: obj[key],
220
106
  });
221
107
  if (prop.deep && lodashEs.isObject(obj[key])) {
222
- try {
223
- for (var _c = __values(Object.keys(obj[key])), _d = _c.next(); !_d.done; _d = _c.next()) {
224
- var childKey = _d.value;
225
- defineProperty({
226
- obj: obj[key],
227
- key: childKey,
228
- prop: prop,
229
- component: component,
230
- componentName: componentName,
231
- });
232
- }
233
- }
234
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
235
- finally {
236
- try {
237
- if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
238
- }
239
- finally { if (e_1) throw e_1.error; }
108
+ for (const childKey of Object.keys(obj[key])) {
109
+ defineProperty({
110
+ obj: obj[key],
111
+ key: childKey,
112
+ prop,
113
+ component,
114
+ componentName,
115
+ });
240
116
  }
241
117
  }
242
118
  Object.defineProperty(obj, key, {
243
119
  enumerable: true,
244
- set: function (val) {
245
- if (obj["_" + key] === val)
120
+ set(val) {
121
+ if (obj[`_${key}`] === val)
246
122
  return;
247
- obj["_" + key] = val;
248
- pushToQueue({ prop: prop, component: component, componentName: componentName });
123
+ obj[`_${key}`] = val;
124
+ pushToQueue({ prop, component, componentName });
249
125
  },
250
- get: function () {
251
- return obj["_" + key];
126
+ get() {
127
+ return obj[`_${key}`];
252
128
  },
253
129
  });
254
130
  }
@@ -256,55 +132,29 @@ function isComponent(comp) {
256
132
  return comp && comp.constructor && 'componentName' in comp.constructor;
257
133
  }
258
134
  function initObserver(Systems) {
259
- var e_2, _a, e_3, _b;
260
- var Ss = [];
135
+ const Ss = [];
261
136
  if (Systems instanceof Array) {
262
- Ss.push.apply(Ss, __spread(Systems));
137
+ Ss.push(...Systems);
263
138
  }
264
139
  else {
265
140
  Ss.push(Systems);
266
141
  }
267
- try {
268
- for (var Ss_1 = __values(Ss), Ss_1_1 = Ss_1.next(); !Ss_1_1.done; Ss_1_1 = Ss_1.next()) {
269
- var S = Ss_1_1.value;
270
- for (var componentName in S.observerInfo) {
271
- componentProps[componentName] = componentProps[componentName] || [];
272
- var props = componentProps[componentName];
273
- var _loop_1 = function (prop) {
274
- var index = props.findIndex(function (p) {
275
- return lodashEs.isEqual(p, prop);
276
- });
277
- if (index === -1) {
278
- componentProps[componentName].push(prop);
279
- }
280
- };
281
- try {
282
- for (var _c = (e_3 = void 0, __values(S.observerInfo[componentName])), _d = _c.next(); !_d.done; _d = _c.next()) {
283
- var prop = _d.value;
284
- _loop_1(prop);
285
- }
286
- }
287
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
288
- finally {
289
- try {
290
- if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
291
- }
292
- finally { if (e_3) throw e_3.error; }
142
+ for (const S of Ss) {
143
+ for (const componentName in S.observerInfo) {
144
+ componentProps[componentName] = componentProps[componentName] || [];
145
+ const props = componentProps[componentName];
146
+ for (const prop of S.observerInfo[componentName]) {
147
+ const index = props.findIndex(p => {
148
+ return lodashEs.isEqual(p, prop);
149
+ });
150
+ if (index === -1) {
151
+ componentProps[componentName].push(prop);
293
152
  }
294
153
  }
295
154
  }
296
155
  }
297
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
298
- finally {
299
- try {
300
- if (Ss_1_1 && !Ss_1_1.done && (_a = Ss_1.return)) _a.call(Ss_1);
301
- }
302
- finally { if (e_2) throw e_2.error; }
303
- }
304
156
  }
305
- function observer(component, componentName) {
306
- var e_4, _a;
307
- if (componentName === void 0) { componentName = component.name; }
157
+ function observer(component, componentName = component.name) {
308
158
  if (!componentName || !componentProps[componentName]) {
309
159
  return;
310
160
  }
@@ -314,53 +164,41 @@ function observer(component, componentName) {
314
164
  if (!component.gameObject || !component.gameObject.id) {
315
165
  throw new Error('component should be add to a gameObject');
316
166
  }
317
- try {
318
- for (var _b = __values(componentProps[componentName]), _c = _b.next(); !_c.done; _c = _b.next()) {
319
- var item = _c.value;
320
- var _d = getObjectCache(component, item.prop), property = _d.property, key = _d.key;
321
- defineProperty({
322
- obj: property,
323
- key: key,
324
- prop: item,
325
- component: component,
326
- componentName: componentName,
327
- });
328
- }
329
- }
330
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
331
- finally {
332
- try {
333
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
334
- }
335
- finally { if (e_4) throw e_4.error; }
167
+ for (const item of componentProps[componentName]) {
168
+ const { property, key } = getObjectCache(component, item.prop);
169
+ defineProperty({
170
+ obj: property,
171
+ key,
172
+ prop: item,
173
+ component,
174
+ componentName,
175
+ });
336
176
  }
337
177
  }
338
- function observerAdded(component, componentName) {
178
+ function observerAdded(component, componentName = component.name) {
339
179
  var _a, _b;
340
- if (componentName === void 0) { componentName = component.name; }
341
- for (var systemName in observerInfos) {
342
- var observerInfo = observerInfos[systemName] || {};
343
- var info = observerInfo[componentName];
180
+ for (const systemName in observerInfos) {
181
+ const observerInfo = observerInfos[systemName] || {};
182
+ const info = observerInfo[componentName];
344
183
  if (info) {
345
184
  (_b = (_a = systemInstance[systemName]) === null || _a === void 0 ? void 0 : _a.componentObserver) === null || _b === void 0 ? void 0 : _b.add({
346
- component: component,
185
+ component,
347
186
  type: exports.OBSERVER_TYPE.ADD,
348
- componentName: componentName,
187
+ componentName,
349
188
  });
350
189
  }
351
190
  }
352
191
  }
353
- function observerRemoved(component, componentName) {
192
+ function observerRemoved(component, componentName = component.name) {
354
193
  var _a, _b;
355
- if (componentName === void 0) { componentName = component.name; }
356
- for (var systemName in observerInfos) {
357
- var observerInfo = observerInfos[systemName] || {};
358
- var info = observerInfo[componentName];
194
+ for (const systemName in observerInfos) {
195
+ const observerInfo = observerInfos[systemName] || {};
196
+ const info = observerInfo[componentName];
359
197
  if (info) {
360
198
  (_b = (_a = systemInstance[systemName]) === null || _a === void 0 ? void 0 : _a.componentObserver) === null || _b === void 0 ? void 0 : _b.add({
361
- component: component,
199
+ component,
362
200
  type: exports.OBSERVER_TYPE.REMOVE,
363
- componentName: componentName,
201
+ componentName,
364
202
  });
365
203
  }
366
204
  }
@@ -371,60 +209,73 @@ function setSystemObserver(system, S) {
371
209
  systemInstance[S.systemName] = system;
372
210
  }
373
211
 
374
- var Transform = (function (_super) {
375
- __extends(Transform, _super);
376
- function Transform() {
377
- var _this = _super !== null && _super.apply(this, arguments) || this;
378
- _this.name = 'Transform';
379
- _this._parent = null;
380
- _this.inScene = false;
381
- _this.children = [];
382
- _this.position = { x: 0, y: 0 };
383
- _this.size = { width: 0, height: 0 };
384
- _this.origin = { x: 0, y: 0 };
385
- _this.anchor = { x: 0, y: 0 };
386
- _this.scale = { x: 1, y: 1 };
387
- _this.skew = { x: 0, y: 0 };
388
- _this.rotation = 0;
389
- return _this;
390
- }
391
- Transform.prototype.init = function (params) {
392
- var e_1, _a;
393
- if (params === void 0) { params = {}; }
394
- var props = ['position', 'size', 'origin', 'anchor', 'scale', 'skew'];
395
- try {
396
- for (var props_1 = __values(props), props_1_1 = props_1.next(); !props_1_1.done; props_1_1 = props_1.next()) {
397
- var key = props_1_1.value;
398
- Object.assign(this[key], params[key]);
399
- }
400
- }
401
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
402
- finally {
403
- try {
404
- if (props_1_1 && !props_1_1.done && (_a = props_1.return)) _a.call(props_1);
405
- }
406
- finally { if (e_1) throw e_1.error; }
212
+ /*! *****************************************************************************
213
+ Copyright (c) Microsoft Corporation. All rights reserved.
214
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
215
+ this file except in compliance with the License. You may obtain a copy of the
216
+ License at http://www.apache.org/licenses/LICENSE-2.0
217
+
218
+ THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
219
+ KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
220
+ WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
221
+ MERCHANTABLITY OR NON-INFRINGEMENT.
222
+
223
+ See the Apache Version 2.0 License for specific language governing permissions
224
+ and limitations under the License.
225
+ ***************************************************************************** */
226
+
227
+ function __decorate(decorators, target, key, desc) {
228
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
229
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
230
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
231
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
232
+ }
233
+
234
+ function __awaiter(thisArg, _arguments, P, generator) {
235
+ return new (P || (P = Promise))(function (resolve, reject) {
236
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
237
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
238
+ function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
239
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
240
+ });
241
+ }
242
+
243
+ class Transform extends Component$1 {
244
+ constructor() {
245
+ super(...arguments);
246
+ this.name = 'Transform';
247
+ this._parent = null;
248
+ this.inScene = false;
249
+ this.children = [];
250
+ this.position = { x: 0, y: 0 };
251
+ this.size = { width: 0, height: 0 };
252
+ this.origin = { x: 0, y: 0 };
253
+ this.anchor = { x: 0, y: 0 };
254
+ this.scale = { x: 1, y: 1 };
255
+ this.skew = { x: 0, y: 0 };
256
+ this.rotation = 0;
257
+ }
258
+ init(params = {}) {
259
+ const props = ['position', 'size', 'origin', 'anchor', 'scale', 'skew'];
260
+ for (const key of props) {
261
+ Object.assign(this[key], params[key]);
407
262
  }
408
263
  this.rotation = params.rotation || this.rotation;
409
- };
410
- Object.defineProperty(Transform.prototype, "parent", {
411
- get: function () {
412
- return this._parent;
413
- },
414
- set: function (val) {
415
- if (val) {
416
- val.addChild(this);
417
- }
418
- else if (this.parent) {
419
- this.parent.removeChild(this);
420
- }
421
- },
422
- enumerable: false,
423
- configurable: true
424
- });
425
- Transform.prototype.addChild = function (child) {
264
+ }
265
+ set parent(val) {
266
+ if (val) {
267
+ val.addChild(this);
268
+ }
269
+ else if (this.parent) {
270
+ this.parent.removeChild(this);
271
+ }
272
+ }
273
+ get parent() {
274
+ return this._parent;
275
+ }
276
+ addChild(child) {
426
277
  if (child.parent === this) {
427
- var index = this.children.findIndex(function (item) { return item === child; });
278
+ const index = this.children.findIndex(item => item === child);
428
279
  this.children.splice(index, 1);
429
280
  }
430
281
  else if (child.parent) {
@@ -432,56 +283,55 @@ var Transform = (function (_super) {
432
283
  }
433
284
  child._parent = this;
434
285
  this.children.push(child);
435
- };
436
- Transform.prototype.removeChild = function (child) {
437
- var index = this.children.findIndex(function (item) { return item === child; });
286
+ }
287
+ removeChild(child) {
288
+ const index = this.children.findIndex(item => item === child);
438
289
  if (index > -1) {
439
290
  this.children.splice(index, 1);
440
291
  child._parent = null;
441
292
  }
442
- };
443
- Transform.prototype.clearChildren = function () {
293
+ }
294
+ clearChildren() {
444
295
  this.children.length = 0;
445
- };
446
- Transform.componentName = 'Transform';
447
- __decorate([
448
- inspectorDecorator.type('vector2'),
449
- inspectorDecorator.step(1)
450
- ], Transform.prototype, "position", void 0);
451
- __decorate([
452
- inspectorDecorator.type('size'),
453
- inspectorDecorator.step(1)
454
- ], Transform.prototype, "size", void 0);
455
- __decorate([
456
- inspectorDecorator.type('vector2'),
457
- inspectorDecorator.step(0.1)
458
- ], Transform.prototype, "origin", void 0);
459
- __decorate([
460
- inspectorDecorator.type('vector2'),
461
- inspectorDecorator.step(0.1)
462
- ], Transform.prototype, "anchor", void 0);
463
- __decorate([
464
- inspectorDecorator.type('vector2'),
465
- inspectorDecorator.step(0.1)
466
- ], Transform.prototype, "scale", void 0);
467
- __decorate([
468
- inspectorDecorator.type('vector2'),
469
- inspectorDecorator.step(0.1)
470
- ], Transform.prototype, "skew", void 0);
471
- __decorate([
472
- inspectorDecorator.type('number'),
473
- inspectorDecorator.step(0.1)
474
- ], Transform.prototype, "rotation", void 0);
475
- return Transform;
476
- }(Component$1));
296
+ }
297
+ }
298
+ Transform.componentName = 'Transform';
299
+ __decorate([
300
+ inspectorDecorator.type('vector2'),
301
+ inspectorDecorator.step(1)
302
+ ], Transform.prototype, "position", void 0);
303
+ __decorate([
304
+ inspectorDecorator.type('size'),
305
+ inspectorDecorator.step(1)
306
+ ], Transform.prototype, "size", void 0);
307
+ __decorate([
308
+ inspectorDecorator.type('vector2'),
309
+ inspectorDecorator.step(0.1)
310
+ ], Transform.prototype, "origin", void 0);
311
+ __decorate([
312
+ inspectorDecorator.type('vector2'),
313
+ inspectorDecorator.step(0.1)
314
+ ], Transform.prototype, "anchor", void 0);
315
+ __decorate([
316
+ inspectorDecorator.type('vector2'),
317
+ inspectorDecorator.step(0.1)
318
+ ], Transform.prototype, "scale", void 0);
319
+ __decorate([
320
+ inspectorDecorator.type('vector2'),
321
+ inspectorDecorator.step(0.1)
322
+ ], Transform.prototype, "skew", void 0);
323
+ __decorate([
324
+ inspectorDecorator.type('number'),
325
+ inspectorDecorator.step(0.1)
326
+ ], Transform.prototype, "rotation", void 0);
477
327
  var Transform$1 = Transform;
478
328
 
479
- var _id = 0;
329
+ let _id = 0;
480
330
  function getId() {
481
331
  return ++_id;
482
332
  }
483
- var GameObject = (function () {
484
- function GameObject(name, obj) {
333
+ class GameObject {
334
+ constructor(name, obj) {
485
335
  this._componentCache = {};
486
336
  this.components = [];
487
337
  this.destroyed = false;
@@ -489,89 +339,62 @@ var GameObject = (function () {
489
339
  this.id = getId();
490
340
  this.addComponent(Transform$1, obj);
491
341
  }
492
- Object.defineProperty(GameObject.prototype, "transform", {
493
- get: function () {
494
- return this.getComponent(Transform$1);
495
- },
496
- enumerable: false,
497
- configurable: true
498
- });
499
- Object.defineProperty(GameObject.prototype, "parent", {
500
- get: function () {
501
- return this.transform && this.transform.parent && this.transform.parent.gameObject;
502
- },
503
- enumerable: false,
504
- configurable: true
505
- });
506
- Object.defineProperty(GameObject.prototype, "name", {
507
- get: function () {
508
- return this._name;
509
- },
510
- enumerable: false,
511
- configurable: true
512
- });
513
- Object.defineProperty(GameObject.prototype, "scene", {
514
- get: function () {
515
- return this._scene;
516
- },
517
- set: function (val) {
518
- var e_1, _a;
519
- if (this._scene === val)
520
- return;
521
- var scene = this._scene;
522
- this._scene = val;
523
- if (this.transform && this.transform.children) {
524
- try {
525
- for (var _b = __values(this.transform.children), _c = _b.next(); !_c.done; _c = _b.next()) {
526
- var child = _c.value;
527
- child.gameObject.scene = val;
528
- }
529
- }
530
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
531
- finally {
532
- try {
533
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
534
- }
535
- finally { if (e_1) throw e_1.error; }
536
- }
537
- }
538
- if (val) {
539
- val.addGameObject(this);
540
- }
541
- else {
542
- scene && scene.removeGameObject(this);
342
+ get transform() {
343
+ return this.getComponent(Transform$1);
344
+ }
345
+ get parent() {
346
+ return this.transform && this.transform.parent && this.transform.parent.gameObject;
347
+ }
348
+ get name() {
349
+ return this._name;
350
+ }
351
+ set scene(val) {
352
+ if (this._scene === val)
353
+ return;
354
+ const scene = this._scene;
355
+ this._scene = val;
356
+ if (this.transform && this.transform.children) {
357
+ for (const child of this.transform.children) {
358
+ child.gameObject.scene = val;
543
359
  }
544
- },
545
- enumerable: false,
546
- configurable: true
547
- });
548
- GameObject.prototype.addChild = function (gameObject) {
360
+ }
361
+ if (val) {
362
+ val.addGameObject(this);
363
+ }
364
+ else {
365
+ scene && scene.removeGameObject(this);
366
+ }
367
+ }
368
+ get scene() {
369
+ return this._scene;
370
+ }
371
+ addChild(gameObject) {
549
372
  if (!gameObject || !gameObject.transform || gameObject === this)
550
373
  return;
551
374
  if (!(gameObject instanceof GameObject)) {
552
375
  throw new Error('addChild only receive GameObject');
553
376
  }
554
377
  if (!this.transform) {
555
- throw new Error("gameObject '" + this.name + "' has been destroy");
378
+ throw new Error(`gameObject '${this.name}' has been destroy`);
556
379
  }
557
380
  gameObject.transform.parent = this.transform;
558
381
  gameObject.scene = this.scene;
559
- };
560
- GameObject.prototype.removeChild = function (gameObject) {
382
+ }
383
+ removeChild(gameObject) {
561
384
  if (!(gameObject instanceof GameObject) || !gameObject.parent || gameObject.parent !== this) {
562
385
  return gameObject;
563
386
  }
564
387
  gameObject.transform.parent = null;
565
388
  gameObject.scene = null;
566
389
  return gameObject;
567
- };
568
- GameObject.prototype.addComponent = function (C, obj) {
390
+ }
391
+ addComponent(C, obj) {
569
392
  if (this.destroyed)
570
393
  return;
571
- var componentName = getComponentName(C);
394
+ const componentName = getComponentName(C);
572
395
  if (this._componentCache[componentName])
573
396
  return;
574
- var component;
397
+ let component;
575
398
  if (C instanceof Function) {
576
399
  component = new C(obj);
577
400
  }
@@ -582,7 +405,7 @@ var GameObject = (function () {
582
405
  throw new Error('addComponent recieve Component and Component Constructor');
583
406
  }
584
407
  if (component.gameObject) {
585
- throw new Error("component has been added on gameObject " + component.gameObject.name);
408
+ throw new Error(`component has been added on gameObject ${component.gameObject.name}`);
586
409
  }
587
410
  component.gameObject = this;
588
411
  component.init && component.init(component.__componentDefaultParams);
@@ -592,9 +415,9 @@ var GameObject = (function () {
592
415
  this._componentCache[componentName] = component;
593
416
  component.awake && component.awake();
594
417
  return component;
595
- };
596
- GameObject.prototype.removeComponent = function (c) {
597
- var componentName;
418
+ }
419
+ removeComponent(c) {
420
+ let componentName;
598
421
  if (typeof c === 'string') {
599
422
  componentName = c;
600
423
  }
@@ -608,24 +431,21 @@ var GameObject = (function () {
608
431
  throw new Error("Transform can't be removed");
609
432
  }
610
433
  return this._removeComponent(componentName);
611
- };
612
- GameObject.prototype._removeComponent = function (componentName) {
613
- var index = this.components.findIndex(function (_a) {
614
- var name = _a.name;
615
- return name === componentName;
616
- });
434
+ }
435
+ _removeComponent(componentName) {
436
+ const index = this.components.findIndex(({ name }) => name === componentName);
617
437
  if (index === -1)
618
438
  return;
619
- var component = this.components.splice(index, 1)[0];
439
+ const component = this.components.splice(index, 1)[0];
620
440
  delete this._componentCache[componentName];
621
441
  delete component.__componentDefaultParams;
622
442
  component.onDestroy && component.onDestroy();
623
443
  observerRemoved(component, componentName);
624
444
  component.gameObject = undefined;
625
445
  return component;
626
- };
627
- GameObject.prototype.getComponent = function (c) {
628
- var componentName;
446
+ }
447
+ getComponent(c) {
448
+ let componentName;
629
449
  if (typeof c === 'string') {
630
450
  componentName = c;
631
451
  }
@@ -641,111 +461,102 @@ var GameObject = (function () {
641
461
  else {
642
462
  return;
643
463
  }
644
- };
645
- GameObject.prototype.remove = function () {
464
+ }
465
+ remove() {
646
466
  if (this.parent)
647
467
  return this.parent.removeChild(this);
648
- };
649
- GameObject.prototype.destroy = function () {
468
+ }
469
+ destroy() {
650
470
  if (!this.transform) {
651
471
  console.error('Cannot destroy gameObject that have already been destroyed.');
652
472
  return;
653
473
  }
654
- Array.from(this.transform.children).forEach(function (_a) {
655
- var gameObject = _a.gameObject;
474
+ Array.from(this.transform.children).forEach(({ gameObject }) => {
656
475
  gameObject.destroy();
657
476
  });
658
477
  this.remove();
659
478
  this.transform.clearChildren();
660
- for (var key in this._componentCache) {
479
+ for (const key in this._componentCache) {
661
480
  this._removeComponent(key);
662
481
  }
663
482
  this.components.length = 0;
664
483
  this.destroyed = true;
665
- };
666
- return GameObject;
667
- }());
484
+ }
485
+ }
668
486
  var GameObject$1 = GameObject;
669
487
 
670
- var ComponentObserver = (function () {
671
- function ComponentObserver() {
488
+ class ComponentObserver {
489
+ constructor() {
672
490
  this.events = [];
673
491
  }
674
- ComponentObserver.prototype.add = function (_a) {
675
- var component = _a.component, prop = _a.prop, type = _a.type, componentName = _a.componentName;
492
+ add({ component, prop, type, componentName }) {
676
493
  if (type === exports.OBSERVER_TYPE.REMOVE) {
677
- if (this.events.find(function (changed) { return changed.component === component && changed.type === exports.OBSERVER_TYPE.ADD; })) {
678
- this.events = this.events.filter(function (changed) { return changed.component !== component; });
494
+ if (this.events.find((changed) => changed.component === component && changed.type === exports.OBSERVER_TYPE.ADD)) {
495
+ this.events = this.events.filter(changed => changed.component !== component);
679
496
  return;
680
497
  }
681
- this.events = this.events.filter(function (changed) { return changed.component !== component; });
498
+ this.events = this.events.filter(changed => changed.component !== component);
682
499
  }
683
- var index = this.events.findIndex(function (changed) { return changed.component === component && lodashEs.isEqual(changed.prop, prop) && changed.type === type; });
500
+ const index = this.events.findIndex(changed => changed.component === component && lodashEs.isEqual(changed.prop, prop) && changed.type === type);
684
501
  if (index > -1) {
685
502
  this.events.splice(index, 1);
686
503
  }
687
504
  this.events.push({
688
505
  gameObject: component.gameObject,
689
- component: component,
506
+ component,
690
507
  prop: prop,
691
- type: type,
692
- componentName: componentName,
508
+ type,
509
+ componentName,
693
510
  });
694
- };
695
- ComponentObserver.prototype.getChanged = function () {
511
+ }
512
+ getChanged() {
696
513
  return this.events;
697
- };
698
- Object.defineProperty(ComponentObserver.prototype, "changed", {
699
- get: function () {
700
- return this.events;
701
- },
702
- enumerable: false,
703
- configurable: true
704
- });
705
- ComponentObserver.prototype.clear = function () {
706
- var events = this.events;
514
+ }
515
+ get changed() {
516
+ return this.events;
517
+ }
518
+ clear() {
519
+ const events = this.events;
707
520
  this.events = [];
708
521
  return events;
709
- };
710
- return ComponentObserver;
711
- }());
522
+ }
523
+ }
712
524
  var ComponentObserver$1 = ComponentObserver;
713
525
 
714
- var System = (function () {
715
- function System(params) {
526
+ class System {
527
+ constructor(params) {
716
528
  this.started = false;
717
529
  this.componentObserver = new ComponentObserver$1();
718
530
  this.__systemDefaultParams = params;
719
531
  this.name = this.constructor.systemName;
720
532
  }
721
- System.prototype.destroy = function () {
533
+ destroy() {
722
534
  var _a;
723
535
  this.componentObserver = null;
724
536
  this.__systemDefaultParams = null;
725
537
  (_a = this.onDestroy) === null || _a === void 0 ? void 0 : _a.call(this);
726
- };
727
- return System;
728
- }());
538
+ }
539
+ }
729
540
  var System$1 = System;
730
541
 
731
542
  function createNowTime() {
732
- var nowtime = null;
543
+ let nowtime = null;
733
544
  if (Date.now) {
734
545
  nowtime = Date.now;
735
546
  }
736
547
  else {
737
- nowtime = function () { return new Date().getTime(); };
548
+ nowtime = () => new Date().getTime();
738
549
  }
739
550
  return nowtime;
740
551
  }
741
552
 
742
- var _nowtime = createNowTime();
743
- var defaultOptions$1 = {
553
+ const _nowtime = createNowTime();
554
+ const defaultOptions$1 = {
744
555
  originTime: 0,
745
556
  playbackRate: 1.0,
746
557
  };
747
- var Timeline = (function () {
748
- function Timeline(options, parent) {
558
+ class Timeline {
559
+ constructor(options, parent) {
749
560
  if (options instanceof Timeline) {
750
561
  parent = options;
751
562
  options = {};
@@ -769,97 +580,72 @@ var Timeline = (function () {
769
580
  }
770
581
  this._playbackRate = options.playbackRate;
771
582
  }
772
- Object.defineProperty(Timeline.prototype, "globalTime", {
773
- get: function () {
774
- return this.parent ? this.parent.currentTime : _nowtime() - this._createTime;
775
- },
776
- enumerable: false,
777
- configurable: true
778
- });
779
- Object.defineProperty(Timeline.prototype, "parent", {
780
- get: function () {
781
- return this._parent;
782
- },
783
- enumerable: false,
784
- configurable: true
785
- });
786
- Object.defineProperty(Timeline.prototype, "lastTimeMark", {
787
- get: function () {
788
- return this._timeMark[this._timeMark.length - 1];
789
- },
790
- enumerable: false,
791
- configurable: true
792
- });
793
- Timeline.prototype.markTime = function (_a) {
794
- var _b = _a === void 0 ? {} : _a, _c = _b.time, time = _c === void 0 ? this.currentTime : _c, _d = _b.entropy, entropy = _d === void 0 ? this.entropy : _d, _e = _b.playbackRate, playbackRate = _e === void 0 ? this.playbackRate : _e;
795
- var timeMark = {
583
+ get globalTime() {
584
+ return this.parent ? this.parent.currentTime : _nowtime() - this._createTime;
585
+ }
586
+ get parent() {
587
+ return this._parent;
588
+ }
589
+ get lastTimeMark() {
590
+ return this._timeMark[this._timeMark.length - 1];
591
+ }
592
+ markTime({ time = this.currentTime, entropy = this.entropy, playbackRate = this.playbackRate } = {}) {
593
+ const timeMark = {
796
594
  globalTime: this.globalTime,
797
595
  localTime: time,
798
- entropy: entropy,
799
- playbackRate: playbackRate,
596
+ entropy,
597
+ playbackRate,
800
598
  globalEntropy: this.globalEntropy,
801
599
  };
802
600
  this._timeMark.push(timeMark);
803
- };
804
- Object.defineProperty(Timeline.prototype, "currentTime", {
805
- get: function () {
806
- var _a = this.lastTimeMark, localTime = _a.localTime, globalTime = _a.globalTime;
807
- return localTime + (this.globalTime - globalTime) * this.playbackRate;
808
- },
809
- set: function (time) {
810
- this.markTime({ time: time });
811
- },
812
- enumerable: false,
813
- configurable: true
814
- });
815
- Object.defineProperty(Timeline.prototype, "globalEntropy", {
816
- get: function () {
817
- return this._parent ? this._parent.entropy : this.globalTime;
818
- },
819
- enumerable: false,
820
- configurable: true
821
- });
822
- Object.defineProperty(Timeline.prototype, "entropy", {
823
- get: function () {
824
- var _a = this.lastTimeMark, entropy = _a.entropy, globalEntropy = _a.globalEntropy;
825
- return entropy + Math.abs((this.globalEntropy - globalEntropy) * this.playbackRate);
826
- },
827
- set: function (entropy) {
828
- if (this.entropy > entropy) {
829
- var idx = this.seekTimeMark(entropy);
830
- this._timeMark.length = idx + 1;
831
- }
832
- this.markTime({ entropy: entropy });
833
- },
834
- enumerable: false,
835
- configurable: true
836
- });
837
- Timeline.prototype.fork = function (options) {
601
+ }
602
+ get currentTime() {
603
+ const { localTime, globalTime } = this.lastTimeMark;
604
+ return localTime + (this.globalTime - globalTime) * this.playbackRate;
605
+ }
606
+ set currentTime(time) {
607
+ this.markTime({ time });
608
+ }
609
+ get globalEntropy() {
610
+ return this._parent ? this._parent.entropy : this.globalTime;
611
+ }
612
+ get entropy() {
613
+ const { entropy, globalEntropy } = this.lastTimeMark;
614
+ return entropy + Math.abs((this.globalEntropy - globalEntropy) * this.playbackRate);
615
+ }
616
+ set entropy(entropy) {
617
+ if (this.entropy > entropy) {
618
+ const idx = this.seekTimeMark(entropy);
619
+ this._timeMark.length = idx + 1;
620
+ }
621
+ this.markTime({ entropy });
622
+ }
623
+ fork(options) {
838
624
  return new Timeline(options, this);
839
- };
840
- Timeline.prototype.seekGlobalTime = function (seekEntropy) {
841
- var idx = this.seekTimeMark(seekEntropy), timeMark = this._timeMark[idx];
842
- var entropy = timeMark.entropy, playbackRate = timeMark.playbackRate, globalTime = timeMark.globalTime;
625
+ }
626
+ seekGlobalTime(seekEntropy) {
627
+ const idx = this.seekTimeMark(seekEntropy), timeMark = this._timeMark[idx];
628
+ const { entropy, playbackRate, globalTime } = timeMark;
843
629
  return globalTime + (seekEntropy - entropy) / Math.abs(playbackRate);
844
- };
845
- Timeline.prototype.seekLocalTime = function (seekEntropy) {
846
- var idx = this.seekTimeMark(seekEntropy), timeMark = this._timeMark[idx];
847
- var localTime = timeMark.localTime, entropy = timeMark.entropy, playbackRate = timeMark.playbackRate;
630
+ }
631
+ seekLocalTime(seekEntropy) {
632
+ const idx = this.seekTimeMark(seekEntropy), timeMark = this._timeMark[idx];
633
+ const { localTime, entropy, playbackRate } = timeMark;
848
634
  if (playbackRate > 0) {
849
635
  return localTime + (seekEntropy - entropy);
850
636
  }
851
637
  return localTime - (seekEntropy - entropy);
852
- };
853
- Timeline.prototype.seekTimeMark = function (entropy) {
854
- var timeMark = this._timeMark;
855
- var l = 0, r = timeMark.length - 1;
638
+ }
639
+ seekTimeMark(entropy) {
640
+ const timeMark = this._timeMark;
641
+ let l = 0, r = timeMark.length - 1;
856
642
  if (entropy <= timeMark[l].entropy) {
857
643
  return l;
858
644
  }
859
645
  if (entropy >= timeMark[r].entropy) {
860
646
  return r;
861
647
  }
862
- var m = Math.floor((l + r) / 2);
648
+ let m = Math.floor((l + r) / 2);
863
649
  while (m > l && m < r) {
864
650
  if (entropy === timeMark[m].entropy) {
865
651
  return m;
@@ -873,46 +659,36 @@ var Timeline = (function () {
873
659
  m = Math.floor((l + r) / 2);
874
660
  }
875
661
  return l;
876
- };
877
- Object.defineProperty(Timeline.prototype, "playbackRate", {
878
- get: function () {
879
- return this._playbackRate;
880
- },
881
- set: function (rate) {
882
- if (rate !== this.playbackRate) {
883
- this.markTime({ playbackRate: rate });
884
- this._playbackRate = rate;
885
- }
886
- },
887
- enumerable: false,
888
- configurable: true
889
- });
890
- Object.defineProperty(Timeline.prototype, "paused", {
891
- get: function () {
892
- if (this.playbackRate === 0)
662
+ }
663
+ get playbackRate() {
664
+ return this._playbackRate;
665
+ }
666
+ set playbackRate(rate) {
667
+ if (rate !== this.playbackRate) {
668
+ this.markTime({ playbackRate: rate });
669
+ this._playbackRate = rate;
670
+ }
671
+ }
672
+ get paused() {
673
+ if (this.playbackRate === 0)
674
+ return true;
675
+ let parent = this.parent;
676
+ while (parent) {
677
+ if (parent.playbackRate === 0)
893
678
  return true;
894
- var parent = this.parent;
895
- while (parent) {
896
- if (parent.playbackRate === 0)
897
- return true;
898
- parent = parent.parent;
899
- }
900
- return false;
901
- },
902
- enumerable: false,
903
- configurable: true
904
- });
905
- return Timeline;
906
- }());
679
+ parent = parent.parent;
680
+ }
681
+ return false;
682
+ }
683
+ }
907
684
  var Timeline$1 = Timeline;
908
685
 
909
- var defaultOptions = {
686
+ const defaultOptions = {
910
687
  autoStart: true,
911
688
  frameRate: 60,
912
689
  };
913
- var Ticker = (function () {
914
- function Ticker(options) {
915
- var _this = this;
690
+ class Ticker {
691
+ constructor(options) {
916
692
  options = Object.assign({}, defaultOptions, options);
917
693
  this._frameCount = 0;
918
694
  this._frameDuration = 1000 / options.frameRate;
@@ -922,103 +698,88 @@ var Ticker = (function () {
922
698
  this._lastFrameTime = this.timeline.currentTime;
923
699
  this._tickers = new Set();
924
700
  this._requestId = null;
925
- this._ticker = function () {
926
- if (_this._started) {
927
- _this._requestId = requestAnimationFrame(_this._ticker);
928
- _this.update();
701
+ this._ticker = () => {
702
+ if (this._started) {
703
+ this._requestId = requestAnimationFrame(this._ticker);
704
+ this.update();
929
705
  }
930
706
  };
931
707
  if (this.autoStart) {
932
708
  this.start();
933
709
  }
934
710
  }
935
- Ticker.prototype.update = function () {
936
- var e_1, _a;
937
- var currentTime = this.timeline.currentTime;
938
- var durationTime = currentTime - this._lastFrameTime;
711
+ update() {
712
+ const currentTime = this.timeline.currentTime;
713
+ const durationTime = currentTime - this._lastFrameTime;
939
714
  if (durationTime >= this._frameDuration) {
940
- var frameTime = currentTime - (durationTime % this._frameDuration);
941
- var deltaTime = frameTime - this._lastFrameTime;
715
+ const frameTime = currentTime - (durationTime % this._frameDuration);
716
+ const deltaTime = frameTime - this._lastFrameTime;
942
717
  this._lastFrameTime = frameTime;
943
- var options = {
944
- deltaTime: deltaTime,
718
+ const options = {
719
+ deltaTime,
945
720
  time: frameTime,
946
721
  currentTime: frameTime,
947
722
  frameCount: ++this._frameCount,
948
723
  fps: Math.round(1000 / deltaTime),
949
724
  };
950
- try {
951
- for (var _b = __values(this._tickers), _c = _b.next(); !_c.done; _c = _b.next()) {
952
- var func = _c.value;
953
- if (typeof func === 'function') {
954
- func(options);
955
- }
725
+ for (const func of this._tickers) {
726
+ if (typeof func === 'function') {
727
+ func(options);
956
728
  }
957
729
  }
958
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
959
- finally {
960
- try {
961
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
962
- }
963
- finally { if (e_1) throw e_1.error; }
964
- }
965
730
  }
966
- };
967
- Ticker.prototype.add = function (fn) {
731
+ }
732
+ add(fn) {
968
733
  this._tickers.add(fn);
969
- };
970
- Ticker.prototype.remove = function (fn) {
734
+ }
735
+ remove(fn) {
971
736
  this._tickers.delete(fn);
972
- };
973
- Ticker.prototype.start = function () {
737
+ }
738
+ start() {
974
739
  if (this._started)
975
740
  return;
976
741
  this._started = true;
977
742
  this.timeline.playbackRate = 1.0;
978
743
  this._requestId = requestAnimationFrame(this._ticker);
979
- };
980
- Ticker.prototype.pause = function () {
744
+ }
745
+ pause() {
981
746
  this._started = false;
982
747
  this.timeline.playbackRate = 0;
983
- };
984
- Ticker.prototype.setPlaybackRate = function (rate) {
748
+ }
749
+ setPlaybackRate(rate) {
985
750
  this.timeline.playbackRate = rate;
986
- };
987
- return Ticker;
988
- }());
751
+ }
752
+ }
989
753
  var Ticker$1 = Ticker;
990
754
 
991
- var Scene = (function (_super) {
992
- __extends(Scene, _super);
993
- function Scene(name, obj) {
994
- var _this = _super.call(this, name, obj) || this;
995
- _this.gameObjects = [];
996
- _this.scene = _this;
997
- return _this;
998
- }
999
- Scene.prototype.addGameObject = function (gameObject) {
755
+ class Scene extends GameObject$1 {
756
+ constructor(name, obj) {
757
+ super(name, obj);
758
+ this.gameObjects = [];
759
+ this.scene = this;
760
+ }
761
+ addGameObject(gameObject) {
1000
762
  this.gameObjects.push(gameObject);
1001
763
  if (gameObject.transform) {
1002
764
  gameObject.transform.inScene = true;
1003
765
  }
1004
- };
1005
- Scene.prototype.removeGameObject = function (gameObject) {
1006
- var index = this.gameObjects.indexOf(gameObject);
766
+ }
767
+ removeGameObject(gameObject) {
768
+ const index = this.gameObjects.indexOf(gameObject);
1007
769
  if (index === -1)
1008
770
  return;
1009
771
  if (gameObject.transform) {
1010
772
  gameObject.transform.inScene = false;
1011
773
  }
1012
774
  this.gameObjects.splice(index, 1);
1013
- };
1014
- Scene.prototype.destroy = function () {
775
+ }
776
+ destroy() {
1015
777
  this.scene = null;
1016
- _super.prototype.destroy.call(this);
778
+ super.destroy();
1017
779
  this.gameObjects = null;
1018
780
  this.canvas = null;
1019
- };
1020
- return Scene;
1021
- }(GameObject$1));
781
+ }
782
+ }
1022
783
  var Scene$1 = Scene;
1023
784
 
1024
785
  exports.LOAD_SCENE_MODE = void 0;
@@ -1026,7 +787,7 @@ exports.LOAD_SCENE_MODE = void 0;
1026
787
  LOAD_SCENE_MODE["SINGLE"] = "SINGLE";
1027
788
  LOAD_SCENE_MODE["MULTI_CANVAS"] = "MULTI_CANVAS";
1028
789
  })(exports.LOAD_SCENE_MODE || (exports.LOAD_SCENE_MODE = {}));
1029
- var triggerStart = function (obj) {
790
+ const triggerStart = (obj) => {
1030
791
  if (!(obj instanceof System$1) && !(obj instanceof Component$1))
1031
792
  return;
1032
793
  if (obj.started)
@@ -1037,312 +798,161 @@ var triggerStart = function (obj) {
1037
798
  }
1038
799
  catch (e) {
1039
800
  if (obj instanceof Component$1) {
1040
- console.error(obj.constructor.componentName + " start error", e);
801
+ console.error(`${obj.constructor.componentName} start error`, e);
1041
802
  }
1042
803
  else {
1043
- console.error(obj.constructor.systemName + " start error", e);
804
+ console.error(`${obj.constructor.systemName} start error`, e);
1044
805
  }
1045
806
  }
1046
807
  };
1047
- var getAllGameObjects = function (game) {
1048
- var e_1, _a;
1049
- var _b;
1050
- var mainSceneGameObjects = ((_b = game === null || game === void 0 ? void 0 : game.scene) === null || _b === void 0 ? void 0 : _b.gameObjects) || [];
1051
- var gameObjectsArray = game === null || game === void 0 ? void 0 : game.multiScenes.map(function (_a) {
1052
- var gameObjects = _a.gameObjects;
1053
- return gameObjects;
1054
- });
1055
- var otherSceneGameObjects = [];
1056
- try {
1057
- for (var gameObjectsArray_1 = __values(gameObjectsArray), gameObjectsArray_1_1 = gameObjectsArray_1.next(); !gameObjectsArray_1_1.done; gameObjectsArray_1_1 = gameObjectsArray_1.next()) {
1058
- var gameObjects = gameObjectsArray_1_1.value;
1059
- otherSceneGameObjects = __spread(otherSceneGameObjects, gameObjects);
1060
- }
808
+ const getAllGameObjects = game => {
809
+ var _a;
810
+ const mainSceneGameObjects = ((_a = game === null || game === void 0 ? void 0 : game.scene) === null || _a === void 0 ? void 0 : _a.gameObjects) || [];
811
+ const gameObjectsArray = game === null || game === void 0 ? void 0 : game.multiScenes.map(({ gameObjects }) => gameObjects);
812
+ let otherSceneGameObjects = [];
813
+ for (const gameObjects of gameObjectsArray) {
814
+ otherSceneGameObjects = [...otherSceneGameObjects, ...gameObjects];
1061
815
  }
1062
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
1063
- finally {
1064
- try {
1065
- if (gameObjectsArray_1_1 && !gameObjectsArray_1_1.done && (_a = gameObjectsArray_1.return)) _a.call(gameObjectsArray_1);
1066
- }
1067
- finally { if (e_1) throw e_1.error; }
1068
- }
1069
- return __spread(mainSceneGameObjects, otherSceneGameObjects);
816
+ return [...mainSceneGameObjects, ...otherSceneGameObjects];
1070
817
  };
1071
- var gameObjectLoop = function (e, gameObjects) {
1072
- var e_2, _a, e_3, _b, e_4, _c, e_5, _d;
1073
- if (gameObjects === void 0) { gameObjects = []; }
1074
- try {
1075
- for (var gameObjects_1 = __values(gameObjects), gameObjects_1_1 = gameObjects_1.next(); !gameObjects_1_1.done; gameObjects_1_1 = gameObjects_1.next()) {
1076
- var gameObject = gameObjects_1_1.value;
818
+ const gameObjectLoop = (e, gameObjects = []) => {
819
+ for (const gameObject of gameObjects) {
820
+ for (const component of gameObject.components) {
1077
821
  try {
1078
- for (var _e = (e_3 = void 0, __values(gameObject.components)), _f = _e.next(); !_f.done; _f = _e.next()) {
1079
- var component = _f.value;
1080
- try {
1081
- triggerStart(component);
1082
- component.update && component.update(e);
1083
- }
1084
- catch (e) {
1085
- console.error("gameObject: " + gameObject.name + " " + component.name + " update error", e);
1086
- }
1087
- }
822
+ triggerStart(component);
823
+ component.update && component.update(e);
1088
824
  }
1089
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
1090
- finally {
1091
- try {
1092
- if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
1093
- }
1094
- finally { if (e_3) throw e_3.error; }
825
+ catch (e) {
826
+ console.error(`gameObject: ${gameObject.name} ${component.name} update error`, e);
1095
827
  }
1096
828
  }
1097
829
  }
1098
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
1099
- finally {
1100
- try {
1101
- if (gameObjects_1_1 && !gameObjects_1_1.done && (_a = gameObjects_1.return)) _a.call(gameObjects_1);
1102
- }
1103
- finally { if (e_2) throw e_2.error; }
1104
- }
1105
- try {
1106
- for (var gameObjects_2 = __values(gameObjects), gameObjects_2_1 = gameObjects_2.next(); !gameObjects_2_1.done; gameObjects_2_1 = gameObjects_2.next()) {
1107
- var gameObject = gameObjects_2_1.value;
830
+ for (const gameObject of gameObjects) {
831
+ for (const component of gameObject.components) {
1108
832
  try {
1109
- for (var _g = (e_5 = void 0, __values(gameObject.components)), _h = _g.next(); !_h.done; _h = _g.next()) {
1110
- var component = _h.value;
1111
- try {
1112
- component.lateUpdate && component.lateUpdate(e);
1113
- }
1114
- catch (e) {
1115
- console.error("gameObject: " + gameObject.name + " " + component.name + " lateUpdate error", e);
1116
- }
1117
- }
833
+ component.lateUpdate && component.lateUpdate(e);
1118
834
  }
1119
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
1120
- finally {
1121
- try {
1122
- if (_h && !_h.done && (_d = _g.return)) _d.call(_g);
1123
- }
1124
- finally { if (e_5) throw e_5.error; }
835
+ catch (e) {
836
+ console.error(`gameObject: ${gameObject.name} ${component.name} lateUpdate error`, e);
1125
837
  }
1126
838
  }
1127
839
  }
1128
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
1129
- finally {
1130
- try {
1131
- if (gameObjects_2_1 && !gameObjects_2_1.done && (_c = gameObjects_2.return)) _c.call(gameObjects_2);
1132
- }
1133
- finally { if (e_4) throw e_4.error; }
1134
- }
1135
840
  };
1136
- var gameObjectResume = function (gameObjects) {
1137
- var e_6, _a, e_7, _b;
1138
- try {
1139
- for (var gameObjects_3 = __values(gameObjects), gameObjects_3_1 = gameObjects_3.next(); !gameObjects_3_1.done; gameObjects_3_1 = gameObjects_3.next()) {
1140
- var gameObject = gameObjects_3_1.value;
841
+ const gameObjectResume = gameObjects => {
842
+ for (const gameObject of gameObjects) {
843
+ for (const component of gameObject.components) {
1141
844
  try {
1142
- for (var _c = (e_7 = void 0, __values(gameObject.components)), _d = _c.next(); !_d.done; _d = _c.next()) {
1143
- var component = _d.value;
1144
- try {
1145
- component.onResume && component.onResume();
1146
- }
1147
- catch (e) {
1148
- console.error("gameObject: " + gameObject.name + ", " + component.name + ", onResume error", e);
1149
- }
1150
- }
845
+ component.onResume && component.onResume();
1151
846
  }
1152
- catch (e_7_1) { e_7 = { error: e_7_1 }; }
1153
- finally {
1154
- try {
1155
- if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
1156
- }
1157
- finally { if (e_7) throw e_7.error; }
847
+ catch (e) {
848
+ console.error(`gameObject: ${gameObject.name}, ${component.name}, onResume error`, e);
1158
849
  }
1159
850
  }
1160
851
  }
1161
- catch (e_6_1) { e_6 = { error: e_6_1 }; }
1162
- finally {
1163
- try {
1164
- if (gameObjects_3_1 && !gameObjects_3_1.done && (_a = gameObjects_3.return)) _a.call(gameObjects_3);
1165
- }
1166
- finally { if (e_6) throw e_6.error; }
1167
- }
1168
852
  };
1169
- var gameObjectPause = function (gameObjects) {
1170
- var e_8, _a, e_9, _b;
1171
- try {
1172
- for (var gameObjects_4 = __values(gameObjects), gameObjects_4_1 = gameObjects_4.next(); !gameObjects_4_1.done; gameObjects_4_1 = gameObjects_4.next()) {
1173
- var gameObject = gameObjects_4_1.value;
853
+ const gameObjectPause = gameObjects => {
854
+ for (const gameObject of gameObjects) {
855
+ for (const component of gameObject.components) {
1174
856
  try {
1175
- for (var _c = (e_9 = void 0, __values(gameObject.components)), _d = _c.next(); !_d.done; _d = _c.next()) {
1176
- var component = _d.value;
1177
- try {
1178
- component.onPause && component.onPause();
1179
- }
1180
- catch (e) {
1181
- console.error("gameObject: " + gameObject.name + ", " + component.name + ", onResume error", e);
1182
- }
1183
- }
857
+ component.onPause && component.onPause();
1184
858
  }
1185
- catch (e_9_1) { e_9 = { error: e_9_1 }; }
1186
- finally {
1187
- try {
1188
- if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
1189
- }
1190
- finally { if (e_9) throw e_9.error; }
859
+ catch (e) {
860
+ console.error(`gameObject: ${gameObject.name}, ${component.name}, onResume error`, e);
1191
861
  }
1192
862
  }
1193
863
  }
1194
- catch (e_8_1) { e_8 = { error: e_8_1 }; }
1195
- finally {
1196
- try {
1197
- if (gameObjects_4_1 && !gameObjects_4_1.done && (_a = gameObjects_4.return)) _a.call(gameObjects_4);
1198
- }
1199
- finally { if (e_8) throw e_8.error; }
1200
- }
1201
864
  };
1202
- var Game = (function (_super) {
1203
- __extends(Game, _super);
1204
- function Game() {
1205
- var _this = _super !== null && _super.apply(this, arguments) || this;
1206
- _this.playing = false;
1207
- _this.started = false;
1208
- _this.multiScenes = [];
1209
- _this.systems = [];
1210
- return _this;
1211
- }
1212
- Game.prototype.init = function (_a) {
1213
- var _b = _a === void 0 ? {} : _a, systems = _b.systems, _c = _b.frameRate, frameRate = _c === void 0 ? 60 : _c, _d = _b.autoStart, autoStart = _d === void 0 ? true : _d, _e = _b.needScene, needScene = _e === void 0 ? true : _e;
1214
- return __awaiter(this, void 0, void 0, function () {
1215
- var systems_1, systems_1_1, system, e_10_1;
1216
- var e_10, _f;
1217
- return __generator(this, function (_g) {
1218
- switch (_g.label) {
1219
- case 0:
1220
- if (window.__EVA_INSPECTOR_ENV__) {
1221
- window.__EVA_GAME_INSTANCE__ = this;
1222
- }
1223
- this.ticker = new Ticker$1({ autoStart: false, frameRate: frameRate });
1224
- this.initTicker();
1225
- if (!(systems && systems.length)) return [3, 8];
1226
- _g.label = 1;
1227
- case 1:
1228
- _g.trys.push([1, 6, 7, 8]);
1229
- systems_1 = __values(systems), systems_1_1 = systems_1.next();
1230
- _g.label = 2;
1231
- case 2:
1232
- if (!!systems_1_1.done) return [3, 5];
1233
- system = systems_1_1.value;
1234
- return [4, this.addSystem(system)];
1235
- case 3:
1236
- _g.sent();
1237
- _g.label = 4;
1238
- case 4:
1239
- systems_1_1 = systems_1.next();
1240
- return [3, 2];
1241
- case 5: return [3, 8];
1242
- case 6:
1243
- e_10_1 = _g.sent();
1244
- e_10 = { error: e_10_1 };
1245
- return [3, 8];
1246
- case 7:
1247
- try {
1248
- if (systems_1_1 && !systems_1_1.done && (_f = systems_1.return)) _f.call(systems_1);
1249
- }
1250
- finally { if (e_10) throw e_10.error; }
1251
- return [7];
1252
- case 8:
1253
- if (needScene) {
1254
- this.loadScene(new Scene$1('scene'));
1255
- }
1256
- if (autoStart) {
1257
- this.start();
1258
- }
1259
- return [2];
865
+ class Game extends EventEmitter__default {
866
+ constructor() {
867
+ super(...arguments);
868
+ this.playing = false;
869
+ this.started = false;
870
+ this.multiScenes = [];
871
+ this.systems = [];
872
+ }
873
+ init({ systems, frameRate = 60, autoStart = true, needScene = true } = {}) {
874
+ return __awaiter(this, void 0, void 0, function* () {
875
+ if (window.__EVA_INSPECTOR_ENV__) {
876
+ window.__EVA_GAME_INSTANCE__ = this;
877
+ }
878
+ this.ticker = new Ticker$1({ autoStart: false, frameRate });
879
+ this.initTicker();
880
+ if (systems && systems.length) {
881
+ for (const system of systems) {
882
+ yield this.addSystem(system);
1260
883
  }
1261
- });
884
+ }
885
+ if (needScene) {
886
+ this.loadScene(new Scene$1('scene'));
887
+ }
888
+ if (autoStart) {
889
+ this.start();
890
+ }
1262
891
  });
1263
- };
1264
- Object.defineProperty(Game.prototype, "scene", {
1265
- get: function () {
1266
- return this._scene;
1267
- },
1268
- set: function (scene) {
1269
- this._scene = scene;
1270
- },
1271
- enumerable: false,
1272
- configurable: true
1273
- });
1274
- Object.defineProperty(Game.prototype, "gameObjects", {
1275
- get: function () {
1276
- return getAllGameObjects(this);
1277
- },
1278
- enumerable: false,
1279
- configurable: true
1280
- });
1281
- Game.prototype.addSystem = function (S, obj) {
1282
- return __awaiter(this, void 0, void 0, function () {
1283
- var system, hasTheSystem, _a;
1284
- return __generator(this, function (_b) {
1285
- switch (_b.label) {
1286
- case 0:
1287
- if (S instanceof Function) {
1288
- system = new S(obj);
1289
- }
1290
- else if (S instanceof System$1) {
1291
- system = S;
1292
- }
1293
- else {
1294
- console.warn('can only add System');
1295
- return [2];
1296
- }
1297
- hasTheSystem = this.systems.find(function (item) {
1298
- return item.constructor === system.constructor;
1299
- });
1300
- if (hasTheSystem) {
1301
- console.warn(system.constructor.systemName + " System has been added");
1302
- return [2];
1303
- }
1304
- system.game = this;
1305
- _a = system.init;
1306
- if (!_a) return [3, 2];
1307
- return [4, system.init(system.__systemDefaultParams)];
1308
- case 1:
1309
- _a = (_b.sent());
1310
- _b.label = 2;
1311
- case 2:
1312
- setSystemObserver(system, system.constructor);
1313
- initObserver(system.constructor);
1314
- try {
1315
- system.awake && system.awake();
1316
- }
1317
- catch (e) {
1318
- console.error(system.constructor.systemName + " awake error", e);
1319
- }
1320
- this.systems.push(system);
1321
- return [2, system];
1322
- }
892
+ }
893
+ get scene() {
894
+ return this._scene;
895
+ }
896
+ set scene(scene) {
897
+ this._scene = scene;
898
+ }
899
+ get gameObjects() {
900
+ return getAllGameObjects(this);
901
+ }
902
+ addSystem(S, obj) {
903
+ return __awaiter(this, void 0, void 0, function* () {
904
+ let system;
905
+ if (S instanceof Function) {
906
+ system = new S(obj);
907
+ }
908
+ else if (S instanceof System$1) {
909
+ system = S;
910
+ }
911
+ else {
912
+ console.warn('can only add System');
913
+ return;
914
+ }
915
+ const hasTheSystem = this.systems.find(item => {
916
+ return item.constructor === system.constructor;
1323
917
  });
918
+ if (hasTheSystem) {
919
+ console.warn(`${system.constructor.systemName} System has been added`);
920
+ return;
921
+ }
922
+ system.game = this;
923
+ system.init && (yield system.init(system.__systemDefaultParams));
924
+ setSystemObserver(system, system.constructor);
925
+ initObserver(system.constructor);
926
+ try {
927
+ system.awake && system.awake();
928
+ }
929
+ catch (e) {
930
+ console.error(`${system.constructor.systemName} awake error`, e);
931
+ }
932
+ this.systems.push(system);
933
+ return system;
1324
934
  });
1325
- };
1326
- Game.prototype.removeSystem = function (system) {
935
+ }
936
+ removeSystem(system) {
1327
937
  if (!system)
1328
938
  return;
1329
- var index = -1;
939
+ let index = -1;
1330
940
  if (typeof system === 'string') {
1331
- index = this.systems.findIndex(function (s) { return s.name === system; });
941
+ index = this.systems.findIndex(s => s.name === system);
1332
942
  }
1333
943
  else if (system instanceof Function) {
1334
- index = this.systems.findIndex(function (s) { return s.constructor === system; });
944
+ index = this.systems.findIndex(s => s.constructor === system);
1335
945
  }
1336
946
  else if (system instanceof System$1) {
1337
- index = this.systems.findIndex(function (s) { return s === system; });
947
+ index = this.systems.findIndex(s => s === system);
1338
948
  }
1339
949
  if (index > -1) {
1340
950
  this.systems[index].destroy && this.systems[index].destroy();
1341
951
  this.systems.splice(index, 1);
1342
952
  }
1343
- };
1344
- Game.prototype.getSystem = function (S) {
1345
- return this.systems.find(function (system) {
953
+ }
954
+ getSystem(S) {
955
+ return this.systems.find(system => {
1346
956
  if (typeof S === 'string') {
1347
957
  return system.name === S;
1348
958
  }
@@ -1350,134 +960,79 @@ var Game = (function (_super) {
1350
960
  return system instanceof S;
1351
961
  }
1352
962
  });
1353
- };
1354
- Game.prototype.pause = function () {
963
+ }
964
+ pause() {
1355
965
  if (!this.playing)
1356
966
  return;
1357
967
  this.playing = false;
1358
968
  this.ticker.pause();
1359
969
  this.triggerPause();
1360
- };
1361
- Game.prototype.start = function () {
970
+ }
971
+ start() {
1362
972
  if (this.playing)
1363
973
  return;
1364
974
  this.playing = true;
1365
975
  this.started = true;
1366
976
  this.ticker.start();
1367
- };
1368
- Game.prototype.resume = function () {
977
+ }
978
+ resume() {
1369
979
  if (this.playing)
1370
980
  return;
1371
981
  this.playing = true;
1372
982
  this.ticker.start();
1373
983
  this.triggerResume();
1374
- };
1375
- Game.prototype.initTicker = function () {
1376
- var _this = this;
1377
- this.ticker.add(function (e) {
1378
- var e_11, _a, e_12, _b;
1379
- _this.scene && gameObjectLoop(e, _this.gameObjects);
1380
- try {
1381
- for (var _c = __values(_this.systems), _d = _c.next(); !_d.done; _d = _c.next()) {
1382
- var system = _d.value;
1383
- try {
1384
- triggerStart(system);
1385
- system.update && system.update(e);
1386
- }
1387
- catch (e) {
1388
- console.error(system.constructor.systemName + " update error", e);
1389
- }
1390
- }
1391
- }
1392
- catch (e_11_1) { e_11 = { error: e_11_1 }; }
1393
- finally {
984
+ }
985
+ initTicker() {
986
+ this.ticker.add(e => {
987
+ this.scene && gameObjectLoop(e, this.gameObjects);
988
+ for (const system of this.systems) {
1394
989
  try {
1395
- if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
990
+ triggerStart(system);
991
+ system.update && system.update(e);
1396
992
  }
1397
- finally { if (e_11) throw e_11.error; }
1398
- }
1399
- try {
1400
- for (var _e = __values(_this.systems), _f = _e.next(); !_f.done; _f = _e.next()) {
1401
- var system = _f.value;
1402
- try {
1403
- system.lateUpdate && system.lateUpdate(e);
1404
- }
1405
- catch (e) {
1406
- console.error(system.constructor.systemName + " lateUpdate error", e);
1407
- }
1408
- }
1409
- }
1410
- catch (e_12_1) { e_12 = { error: e_12_1 }; }
1411
- finally {
1412
- try {
1413
- if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
993
+ catch (e) {
994
+ console.error(`${system.constructor.systemName} update error`, e);
1414
995
  }
1415
- finally { if (e_12) throw e_12.error; }
1416
996
  }
1417
- });
1418
- };
1419
- Game.prototype.triggerResume = function () {
1420
- var e_13, _a;
1421
- gameObjectResume(this.gameObjects);
1422
- try {
1423
- for (var _b = __values(this.systems), _c = _b.next(); !_c.done; _c = _b.next()) {
1424
- var system = _c.value;
997
+ for (const system of this.systems) {
1425
998
  try {
1426
- system.onResume && system.onResume();
999
+ system.lateUpdate && system.lateUpdate(e);
1427
1000
  }
1428
1001
  catch (e) {
1429
- console.error(system.constructor.systemName + ", onResume error", e);
1002
+ console.error(`${system.constructor.systemName} lateUpdate error`, e);
1430
1003
  }
1431
1004
  }
1432
- }
1433
- catch (e_13_1) { e_13 = { error: e_13_1 }; }
1434
- finally {
1005
+ });
1006
+ }
1007
+ triggerResume() {
1008
+ gameObjectResume(this.gameObjects);
1009
+ for (const system of this.systems) {
1435
1010
  try {
1436
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1011
+ system.onResume && system.onResume();
1437
1012
  }
1438
- finally { if (e_13) throw e_13.error; }
1439
- }
1440
- };
1441
- Game.prototype.triggerPause = function () {
1442
- var e_14, _a;
1443
- gameObjectPause(this.gameObjects);
1444
- try {
1445
- for (var _b = __values(this.systems), _c = _b.next(); !_c.done; _c = _b.next()) {
1446
- var system = _c.value;
1447
- try {
1448
- system.onPause && system.onPause();
1449
- }
1450
- catch (e) {
1451
- console.error(system.constructor.systemName + ", onPause error", e);
1452
- }
1013
+ catch (e) {
1014
+ console.error(`${system.constructor.systemName}, onResume error`, e);
1453
1015
  }
1454
1016
  }
1455
- catch (e_14_1) { e_14 = { error: e_14_1 }; }
1456
- finally {
1017
+ }
1018
+ triggerPause() {
1019
+ gameObjectPause(this.gameObjects);
1020
+ for (const system of this.systems) {
1457
1021
  try {
1458
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1022
+ system.onPause && system.onPause();
1459
1023
  }
1460
- finally { if (e_14) throw e_14.error; }
1461
- }
1462
- };
1463
- Game.prototype.destroySystems = function () {
1464
- var e_15, _a;
1465
- try {
1466
- for (var _b = __values(__spread(this.systems)), _c = _b.next(); !_c.done; _c = _b.next()) {
1467
- var system = _c.value;
1468
- this.removeSystem(system);
1024
+ catch (e) {
1025
+ console.error(`${system.constructor.systemName}, onPause error`, e);
1469
1026
  }
1470
1027
  }
1471
- catch (e_15_1) { e_15 = { error: e_15_1 }; }
1472
- finally {
1473
- try {
1474
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1475
- }
1476
- finally { if (e_15) throw e_15.error; }
1028
+ }
1029
+ destroySystems() {
1030
+ for (const system of [...this.systems]) {
1031
+ this.removeSystem(system);
1477
1032
  }
1478
1033
  this.systems.length = 0;
1479
- };
1480
- Game.prototype.destroy = function () {
1034
+ }
1035
+ destroy() {
1481
1036
  this.removeAllListeners();
1482
1037
  this.pause();
1483
1038
  this.scene.destroy();
@@ -1486,9 +1041,8 @@ var Game = (function (_super) {
1486
1041
  this.scene = null;
1487
1042
  this.canvas = null;
1488
1043
  this.multiScenes = null;
1489
- };
1490
- Game.prototype.loadScene = function (_a) {
1491
- var scene = _a.scene, _b = _a.mode, mode = _b === void 0 ? exports.LOAD_SCENE_MODE.SINGLE : _b, _c = _a.params, params = _c === void 0 ? {} : _c;
1044
+ }
1045
+ loadScene({ scene, mode = exports.LOAD_SCENE_MODE.SINGLE, params = {} }) {
1492
1046
  if (!scene) {
1493
1047
  return;
1494
1048
  }
@@ -1500,10 +1054,9 @@ var Game = (function (_super) {
1500
1054
  this.multiScenes.push(scene);
1501
1055
  break;
1502
1056
  }
1503
- this.emit('sceneChanged', { scene: scene, mode: mode, params: params });
1504
- };
1505
- return Game;
1506
- }(EventEmitter__default));
1057
+ this.emit('sceneChanged', { scene, mode, params });
1058
+ }
1059
+ }
1507
1060
  var Game$1 = Game;
1508
1061
 
1509
1062
  function IDEProp(target, propertyKey) {
@@ -1513,16 +1066,15 @@ function IDEProp(target, propertyKey) {
1513
1066
  target.constructor.IDEProps.push(propertyKey);
1514
1067
  }
1515
1068
 
1516
- function componentObserver(observerInfo) {
1517
- if (observerInfo === void 0) { observerInfo = {}; }
1069
+ function componentObserver(observerInfo = {}) {
1518
1070
  return function (constructor) {
1519
1071
  if (!constructor.observerInfo) {
1520
- for (var key in observerInfo) {
1521
- for (var index in observerInfo[key]) {
1072
+ for (const key in observerInfo) {
1073
+ for (const index in observerInfo[key]) {
1522
1074
  if (typeof observerInfo[key][index] === 'string') {
1523
1075
  observerInfo[key][index] = [observerInfo[key][index]];
1524
1076
  }
1525
- var observerProp = void 0;
1077
+ let observerProp;
1526
1078
  if (Array.isArray(observerInfo[key][index])) {
1527
1079
  observerProp = {
1528
1080
  prop: observerInfo[key][index],
@@ -1541,25 +1093,22 @@ function componentObserver(observerInfo) {
1541
1093
  };
1542
1094
  }
1543
1095
 
1544
- var Progress = (function (_super) {
1545
- __extends(Progress, _super);
1546
- function Progress(_a) {
1547
- var resource = _a.resource, resourceTotal = _a.resourceTotal;
1548
- var _this = _super.call(this) || this;
1549
- _this.progress = 0;
1550
- _this.resourceTotal = 0;
1551
- _this.resourceLoadedCount = 0;
1552
- _this.resource = resource;
1553
- _this.resourceTotal = resourceTotal;
1096
+ class Progress extends EventEmitter__default {
1097
+ constructor({ resource, resourceTotal }) {
1098
+ super();
1099
+ this.progress = 0;
1100
+ this.resourceTotal = 0;
1101
+ this.resourceLoadedCount = 0;
1102
+ this.resource = resource;
1103
+ this.resourceTotal = resourceTotal;
1554
1104
  if (resourceTotal === 0) {
1555
- _this.resource.emit(exports.LOAD_EVENT.COMPLETE, _this);
1105
+ this.resource.emit(exports.LOAD_EVENT.COMPLETE, this);
1556
1106
  }
1557
- return _this;
1558
1107
  }
1559
- Progress.prototype.onStart = function () {
1108
+ onStart() {
1560
1109
  this.resource.emit(exports.LOAD_EVENT.START, this);
1561
- };
1562
- Progress.prototype.onProgress = function (param) {
1110
+ }
1111
+ onProgress(param) {
1563
1112
  this.resourceLoadedCount++;
1564
1113
  this.progress = Math.floor((this.resourceLoadedCount / this.resourceTotal) * 100) / 100;
1565
1114
  if (param.success) {
@@ -1572,12 +1121,10 @@ var Progress = (function (_super) {
1572
1121
  if (this.resourceLoadedCount === this.resourceTotal) {
1573
1122
  this.resource.emit(exports.LOAD_EVENT.COMPLETE, this);
1574
1123
  }
1575
- };
1576
- return Progress;
1577
- }(EventEmitter__default));
1578
- var Progress$1 = Progress;
1124
+ }
1125
+ }
1579
1126
 
1580
- var resourceLoader = {
1127
+ const resourceLoader = {
1581
1128
  AbstractLoadStrategy: resourceLoader$1.AbstractLoadStrategy,
1582
1129
  AudioLoadStrategy: resourceLoader$1.AudioLoadStrategy,
1583
1130
  ImageLoadStrategy: resourceLoader$1.ImageLoadStrategy,
@@ -1606,201 +1153,140 @@ exports.RESOURCE_TYPE = void 0;
1606
1153
  RESOURCE_TYPE["AUDIO"] = "AUDIO";
1607
1154
  RESOURCE_TYPE["VIDEO"] = "VIDEO";
1608
1155
  })(exports.RESOURCE_TYPE || (exports.RESOURCE_TYPE = {}));
1609
- var Resource = (function (_super) {
1610
- __extends(Resource, _super);
1611
- function Resource(options) {
1612
- var _this = _super.call(this) || this;
1613
- _this.timeout = 6000;
1614
- _this.preProcessResourceHandlers = [];
1615
- _this.resourcesMap = {};
1616
- _this.makeInstanceFunctions = {};
1617
- _this.destroyInstanceFunctions = {};
1618
- _this.promiseMap = {};
1156
+ class Resource extends EventEmitter__default {
1157
+ constructor(options) {
1158
+ super();
1159
+ this.timeout = 6000;
1160
+ this.preProcessResourceHandlers = [];
1161
+ this.resourcesMap = {};
1162
+ this.makeInstanceFunctions = {};
1163
+ this.destroyInstanceFunctions = {};
1164
+ this.promiseMap = {};
1619
1165
  if (options && typeof options.timeout === 'number') {
1620
- _this.timeout = options.timeout;
1166
+ this.timeout = options.timeout;
1621
1167
  }
1622
- return _this;
1623
1168
  }
1624
- Resource.prototype.loadConfig = function (resources) {
1169
+ loadConfig(resources) {
1625
1170
  this.addResource(resources);
1626
1171
  this.preload();
1627
- };
1628
- Resource.prototype.loadSingle = function (resource) {
1172
+ }
1173
+ loadSingle(resource) {
1629
1174
  this.addResource([resource]);
1630
1175
  return this.getResource(resource.name);
1631
- };
1632
- Resource.prototype.addResource = function (resources) {
1633
- var e_1, _a;
1176
+ }
1177
+ addResource(resources) {
1634
1178
  if (!resources || resources.length < 1) {
1635
1179
  console.warn('no resources');
1636
1180
  return;
1637
1181
  }
1638
- try {
1639
- for (var resources_1 = __values(resources), resources_1_1 = resources_1.next(); !resources_1_1.done; resources_1_1 = resources_1.next()) {
1640
- var res = resources_1_1.value;
1641
- if (this.resourcesMap[res.name]) {
1642
- console.warn(res.name + ' was already added');
1643
- continue;
1644
- }
1645
- this.resourcesMap[res.name] = res;
1646
- this.resourcesMap[res.name].data = {};
1182
+ for (const res of resources) {
1183
+ if (this.resourcesMap[res.name]) {
1184
+ console.warn(res.name + ' was already added');
1185
+ continue;
1647
1186
  }
1187
+ this.resourcesMap[res.name] = res;
1188
+ this.resourcesMap[res.name].data = {};
1648
1189
  }
1649
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
1650
- finally {
1651
- try {
1652
- if (resources_1_1 && !resources_1_1.done && (_a = resources_1.return)) _a.call(resources_1);
1653
- }
1654
- finally { if (e_1) throw e_1.error; }
1655
- }
1656
- };
1657
- Resource.prototype.addPreProcessResourceHandler = function (handler) {
1190
+ }
1191
+ addPreProcessResourceHandler(handler) {
1658
1192
  this.preProcessResourceHandlers.push(handler);
1659
- };
1660
- Resource.prototype.removePreProcessResourceHandler = function (handler) {
1193
+ }
1194
+ removePreProcessResourceHandler(handler) {
1661
1195
  this.preProcessResourceHandlers.splice(this.preProcessResourceHandlers.indexOf(handler), 1);
1662
- };
1663
- Resource.prototype.preload = function () {
1664
- var names = [];
1665
- for (var key in this.resourcesMap) {
1666
- var resource_1 = this.resourcesMap[key];
1667
- if (resource_1.preload && !resource_1.complete && !this.promiseMap[key]) {
1668
- names.push(resource_1.name);
1196
+ }
1197
+ preload() {
1198
+ const names = [];
1199
+ for (const key in this.resourcesMap) {
1200
+ const resource = this.resourcesMap[key];
1201
+ if (resource.preload && !resource.complete && !this.promiseMap[key]) {
1202
+ names.push(resource.name);
1669
1203
  }
1670
1204
  }
1671
- this.progress = new Progress$1({
1205
+ this.progress = new Progress({
1672
1206
  resource: this,
1673
1207
  resourceTotal: names.length,
1674
1208
  });
1675
- this.loadResource({ names: names, preload: true });
1676
- };
1677
- Resource.prototype.getResource = function (name) {
1678
- return __awaiter(this, void 0, void 0, function () {
1679
- return __generator(this, function (_a) {
1680
- this.loadResource({ names: [name] });
1681
- return [2, this.promiseMap[name] || Promise.resolve({})];
1682
- });
1209
+ this.loadResource({ names, preload: true });
1210
+ }
1211
+ getResource(name) {
1212
+ return __awaiter(this, void 0, void 0, function* () {
1213
+ this.loadResource({ names: [name] });
1214
+ return this.promiseMap[name] || Promise.resolve({});
1683
1215
  });
1684
- };
1685
- Resource.prototype.instance = function (name) {
1686
- return __awaiter(this, void 0, void 0, function () {
1687
- var res, _a;
1688
- return __generator(this, function (_b) {
1689
- switch (_b.label) {
1690
- case 0:
1691
- res = this.resourcesMap[name];
1692
- _a = this.makeInstanceFunctions[res.type];
1693
- if (!_a) return [3, 2];
1694
- return [4, this.makeInstanceFunctions[res.type](res)];
1695
- case 1:
1696
- _a = (_b.sent());
1697
- _b.label = 2;
1698
- case 2: return [2, _a];
1699
- }
1700
- });
1216
+ }
1217
+ instance(name) {
1218
+ return __awaiter(this, void 0, void 0, function* () {
1219
+ const res = this.resourcesMap[name];
1220
+ return this.makeInstanceFunctions[res.type] && (yield this.makeInstanceFunctions[res.type](res));
1701
1221
  });
1702
- };
1703
- Resource.prototype.destroy = function (name) {
1704
- return __awaiter(this, void 0, void 0, function () {
1705
- return __generator(this, function (_a) {
1706
- switch (_a.label) {
1707
- case 0: return [4, this._destroy(name)];
1708
- case 1:
1709
- _a.sent();
1710
- return [2];
1711
- }
1712
- });
1222
+ }
1223
+ destroy(name) {
1224
+ return __awaiter(this, void 0, void 0, function* () {
1225
+ yield this._destroy(name);
1713
1226
  });
1714
- };
1715
- Resource.prototype._destroy = function (name, loadError) {
1716
- if (loadError === void 0) { loadError = false; }
1717
- return __awaiter(this, void 0, void 0, function () {
1718
- var resource, e_2;
1719
- return __generator(this, function (_a) {
1720
- switch (_a.label) {
1721
- case 0:
1722
- resource = this.resourcesMap[name];
1723
- if (!resource)
1724
- return [2];
1725
- if (!!loadError) return [3, 5];
1726
- _a.label = 1;
1727
- case 1:
1728
- _a.trys.push([1, 4, , 5]);
1729
- if (!this.destroyInstanceFunctions[resource.type]) return [3, 3];
1730
- return [4, this.destroyInstanceFunctions[resource.type](resource)];
1731
- case 2:
1732
- _a.sent();
1733
- _a.label = 3;
1734
- case 3: return [3, 5];
1735
- case 4:
1736
- e_2 = _a.sent();
1737
- console.warn("destroy resource " + resource.name + " error with '" + e_2.message + "'");
1738
- return [3, 5];
1739
- case 5:
1740
- delete this.promiseMap[name];
1741
- resource.data = {};
1742
- resource.complete = false;
1743
- resource.instance = undefined;
1744
- return [2];
1227
+ }
1228
+ _destroy(name, loadError = false) {
1229
+ return __awaiter(this, void 0, void 0, function* () {
1230
+ const resource = this.resourcesMap[name];
1231
+ if (!resource)
1232
+ return;
1233
+ if (!loadError) {
1234
+ try {
1235
+ if (this.destroyInstanceFunctions[resource.type]) {
1236
+ yield this.destroyInstanceFunctions[resource.type](resource);
1237
+ }
1745
1238
  }
1746
- });
1239
+ catch (e) {
1240
+ console.warn(`destroy resource ${resource.name} error with '${e.message}'`);
1241
+ }
1242
+ }
1243
+ delete this.promiseMap[name];
1244
+ resource.data = {};
1245
+ resource.complete = false;
1246
+ resource.instance = undefined;
1747
1247
  });
1748
- };
1749
- Resource.prototype.registerResourceType = function (type, value) {
1750
- if (value === void 0) { value = type; }
1248
+ }
1249
+ registerResourceType(type, value = type) {
1751
1250
  if (exports.RESOURCE_TYPE[type]) {
1752
- throw new Error("The type " + type + " already exists in RESOURCE_TYPE");
1251
+ throw new Error(`The type ${type} already exists in RESOURCE_TYPE`);
1753
1252
  }
1754
1253
  exports.RESOURCE_TYPE[type] = value;
1755
- };
1756
- Resource.prototype.registerInstance = function (type, callback) {
1254
+ }
1255
+ registerInstance(type, callback) {
1757
1256
  this.makeInstanceFunctions[type] = callback;
1758
- };
1759
- Resource.prototype.registerDestroy = function (type, callback) {
1257
+ }
1258
+ registerDestroy(type, callback) {
1760
1259
  this.destroyInstanceFunctions[type] = callback;
1761
- };
1762
- Resource.prototype.loadResource = function (_a) {
1763
- var _this = this;
1764
- var _b = _a.names, names = _b === void 0 ? [] : _b, _c = _a.preload, preload = _c === void 0 ? false : _c;
1765
- var unLoadNames = names.filter(function (name) { return !_this.promiseMap[name] && _this.resourcesMap[name]; });
1260
+ }
1261
+ loadResource({ names = [], preload = false }) {
1262
+ const unLoadNames = names.filter(name => !this.promiseMap[name] && this.resourcesMap[name]);
1766
1263
  if (!unLoadNames.length)
1767
1264
  return;
1768
- var resolves = {};
1769
- unLoadNames.forEach(function (name) {
1770
- var e_3, _a;
1771
- var _b;
1772
- _this.promiseMap[name] = new Promise(function (r) { return (resolves[name] = r); });
1773
- var res = _this.resourcesMap[name];
1774
- try {
1775
- for (var _c = __values(_this.preProcessResourceHandlers), _d = _c.next(); !_d.done; _d = _c.next()) {
1776
- var handler = _d.value;
1777
- handler(res);
1778
- }
1265
+ const resolves = {};
1266
+ unLoadNames.forEach(name => {
1267
+ var _a;
1268
+ this.promiseMap[name] = new Promise(r => (resolves[name] = r));
1269
+ const res = this.resourcesMap[name];
1270
+ for (const handler of this.preProcessResourceHandlers) {
1271
+ handler(res);
1779
1272
  }
1780
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
1781
- finally {
1782
- try {
1783
- if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
1784
- }
1785
- finally { if (e_3) throw e_3.error; }
1786
- }
1787
- var _loop_1 = function (key) {
1788
- var resourceType = res.src[key].type;
1273
+ for (const key in res.src) {
1274
+ const resourceType = res.src[key].type;
1789
1275
  if (resourceType === 'data') {
1790
1276
  res.data[key] = res.src[key].data;
1791
- _this.doComplete(name, resolves[name], preload);
1277
+ this.doComplete(name, resolves[name], preload);
1792
1278
  }
1793
1279
  else {
1794
- var url = (_b = res.src[key]) === null || _b === void 0 ? void 0 : _b.url;
1280
+ let url = (_a = res.src[key]) === null || _a === void 0 ? void 0 : _a.url;
1795
1281
  if (typeof url === 'string' && url.startsWith('//')) {
1796
- url = "" + window.location.protocol + res.src[key].url;
1282
+ url = `${window.location.protocol}${res.src[key].url}`;
1797
1283
  }
1798
1284
  if (key === 'atlas') {
1799
1285
  pixi_js.Assets.add({
1800
1286
  alias: url,
1801
1287
  src: url,
1802
1288
  data: {
1803
- resolve: function () { return pixi_js.Assets.load(res.src['image'].url); },
1289
+ resolve: () => pixi_js.Assets.load(res.src['image'].url),
1804
1290
  },
1805
1291
  });
1806
1292
  }
@@ -1811,126 +1297,99 @@ var Resource = (function (_super) {
1811
1297
  });
1812
1298
  }
1813
1299
  pixi_js.Assets.load(url)
1814
- .then(function (data) {
1815
- _this.onLoad({
1816
- preload: preload,
1300
+ .then(data => {
1301
+ this.onLoad({
1302
+ preload,
1817
1303
  resource: {
1818
- metadata: { key: key, name: name, resolves: resolves },
1304
+ metadata: { key, name, resolves },
1819
1305
  data: data,
1820
1306
  },
1821
1307
  });
1822
1308
  })
1823
- .catch(function (e) {
1309
+ .catch(e => {
1824
1310
  console.log('>>>E', e);
1825
- _this.onError({
1826
- preload: preload,
1311
+ this.onError({
1312
+ preload,
1827
1313
  errMsg: e.message,
1828
1314
  resource: {
1829
- metadata: { key: key, name: name, resolves: resolves },
1315
+ metadata: { key, name, resolves },
1830
1316
  },
1831
1317
  });
1832
1318
  });
1833
1319
  }
1834
- };
1835
- for (var key in res.src) {
1836
- _loop_1(key);
1837
1320
  }
1838
1321
  });
1839
- };
1840
- Resource.prototype.doComplete = function (name, resolve, preload) {
1841
- if (preload === void 0) { preload = false; }
1842
- return __awaiter(this, void 0, void 0, function () {
1843
- var res, param, _a, err_1;
1844
- return __generator(this, function (_b) {
1845
- switch (_b.label) {
1846
- case 0:
1847
- res = this.resourcesMap[name];
1848
- param = {
1849
- name: name,
1850
- resource: this.resourcesMap[name],
1851
- success: true,
1852
- };
1853
- if (!this.checkAllLoaded(name)) return [3, 4];
1854
- _b.label = 1;
1855
- case 1:
1856
- _b.trys.push([1, 3, , 4]);
1857
- _a = res;
1858
- return [4, this.instance(name)];
1859
- case 2:
1860
- _a.instance = _b.sent();
1861
- res.complete = true;
1862
- if (preload) {
1863
- this.progress.onProgress(param);
1864
- }
1865
- resolve(res);
1866
- return [3, 4];
1867
- case 3:
1868
- err_1 = _b.sent();
1869
- console.error(err_1);
1870
- res.complete = false;
1871
- if (preload) {
1872
- param.errMsg = err_1.message;
1873
- param.success = false;
1874
- this.progress.onProgress(param);
1875
- }
1876
- resolve({});
1877
- return [3, 4];
1878
- case 4: return [2];
1322
+ }
1323
+ doComplete(name, resolve, preload = false) {
1324
+ return __awaiter(this, void 0, void 0, function* () {
1325
+ const res = this.resourcesMap[name];
1326
+ const param = {
1327
+ name,
1328
+ resource: this.resourcesMap[name],
1329
+ success: true,
1330
+ };
1331
+ if (this.checkAllLoaded(name)) {
1332
+ try {
1333
+ res.instance = yield this.instance(name);
1334
+ res.complete = true;
1335
+ if (preload) {
1336
+ this.progress.onProgress(param);
1337
+ }
1338
+ resolve(res);
1879
1339
  }
1880
- });
1340
+ catch (err) {
1341
+ console.error(err);
1342
+ res.complete = false;
1343
+ if (preload) {
1344
+ param.errMsg = err.message;
1345
+ param.success = false;
1346
+ this.progress.onProgress(param);
1347
+ }
1348
+ resolve({});
1349
+ }
1350
+ }
1881
1351
  });
1882
- };
1883
- Resource.prototype.checkAllLoaded = function (name) {
1884
- var res = this.resourcesMap[name];
1885
- return Array.from(Object.keys(res.src)).every(function (resourceKey) { return res.data[resourceKey]; });
1886
- };
1887
- Resource.prototype.getLoader = function (_preload) {
1888
- };
1889
- Resource.prototype.onLoad = function (_a) {
1890
- var _b = _a.preload, preload = _b === void 0 ? false : _b, resource = _a.resource;
1891
- return __awaiter(this, void 0, void 0, function () {
1892
- var _c, key, name, resolves, data, res;
1893
- return __generator(this, function (_d) {
1894
- _c = resource.metadata, key = _c.key, name = _c.name, resolves = _c.resolves, data = resource.data;
1895
- res = this.resourcesMap[name];
1896
- res.data[key] = data;
1897
- this.doComplete(name, resolves[name], preload);
1898
- return [2];
1899
- });
1352
+ }
1353
+ checkAllLoaded(name) {
1354
+ const res = this.resourcesMap[name];
1355
+ return Array.from(Object.keys(res.src)).every(resourceKey => res.data[resourceKey]);
1356
+ }
1357
+ getLoader(_preload = false) {
1358
+ }
1359
+ onLoad({ preload = false, resource }) {
1360
+ return __awaiter(this, void 0, void 0, function* () {
1361
+ const { metadata: { key, name, resolves }, data, } = resource;
1362
+ const res = this.resourcesMap[name];
1363
+ res.data[key] = data;
1364
+ this.doComplete(name, resolves[name], preload);
1900
1365
  });
1901
- };
1902
- Resource.prototype.onError = function (_a) {
1903
- var errMsg = _a.errMsg, _b = _a.preload, preload = _b === void 0 ? false : _b, resource = _a.resource;
1904
- return __awaiter(this, void 0, void 0, function () {
1905
- var _c, name, resolves, param;
1906
- return __generator(this, function (_d) {
1907
- _c = resource.metadata, name = _c.name, resolves = _c.resolves;
1908
- this._destroy(name, true);
1909
- resolves[name]({});
1910
- if (preload) {
1911
- param = {
1912
- name: name,
1913
- resource: this.resourcesMap[name],
1914
- success: false,
1915
- errMsg: errMsg,
1916
- };
1917
- this.progress.onProgress(param);
1918
- }
1919
- return [2];
1920
- });
1366
+ }
1367
+ onError({ errMsg, preload = false, resource }) {
1368
+ return __awaiter(this, void 0, void 0, function* () {
1369
+ const { metadata: { name, resolves }, } = resource;
1370
+ this._destroy(name, true);
1371
+ resolves[name]({});
1372
+ if (preload) {
1373
+ const param = {
1374
+ name,
1375
+ resource: this.resourcesMap[name],
1376
+ success: false,
1377
+ errMsg,
1378
+ };
1379
+ this.progress.onProgress(param);
1380
+ }
1921
1381
  });
1922
- };
1923
- return Resource;
1924
- }(EventEmitter__default));
1925
- var resource = new Resource();
1382
+ }
1383
+ }
1384
+ const resource = new Resource();
1926
1385
 
1927
- var decorators = {
1928
- IDEProp: IDEProp,
1929
- componentObserver: componentObserver,
1386
+ const decorators = {
1387
+ IDEProp,
1388
+ componentObserver,
1930
1389
  };
1931
- var version = '2.0.0-beta.1';
1932
- console.log("Eva.js version: " + version);
1933
- var RESOURCE_TYPE_STRATEGY = {};
1390
+ const version = '2.0.0-beta.2';
1391
+ console.log(`Eva.js version: ${version}`);
1392
+ const RESOURCE_TYPE_STRATEGY = {};
1934
1393
 
1935
1394
  exports.Component = Component$1;
1936
1395
  exports.Game = Game$1;