@eva/eva.js 1.2.2-alpha.1 → 1.2.2-alpha.5

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