@eva/eva.js 1.2.7-fix.4 → 1.2.7-fix.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/EVA.js +1017 -246
- package/dist/EVA.js.map +1 -0
- package/dist/EVA.min.js +1 -1
- package/dist/eva.js.cjs.js +5 -112
- package/dist/eva.js.cjs.js.map +1 -0
- package/dist/eva.js.cjs.prod.js +2 -2
- package/dist/eva.js.d.ts +1 -12
- package/dist/eva.js.esm.js +4 -111
- package/dist/eva.js.esm.js.map +1 -0
- package/dist/miniprogram.js +722 -54
- package/package.json +1 -1
package/dist/miniprogram.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
function _extends() { _extends = Object.assign
|
|
1
|
+
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
|
+
|
|
2
3
|
import { __extends as __extends$1, __spread, __values, __decorate, __awaiter, __generator } from 'tslib';
|
|
3
4
|
import EventEmitter from 'eventemitter3';
|
|
4
5
|
import { isEqual, isObject } from 'lodash-es';
|
|
5
6
|
import { type, step } from '@eva/inspector-decorator';
|
|
6
7
|
import { requestAnimationFrame, windowAlias, navigator, documentAlias, XMLHttpRequestAlias } from '@eva/miniprogram-adapter';
|
|
8
|
+
|
|
7
9
|
function getComponentName(component) {
|
|
8
10
|
if (component instanceof Component) {
|
|
9
11
|
return component.name;
|
|
@@ -11,60 +13,76 @@ function getComponentName(component) {
|
|
|
11
13
|
return component.componentName;
|
|
12
14
|
}
|
|
13
15
|
}
|
|
16
|
+
|
|
14
17
|
var Component = function (_super) {
|
|
15
18
|
__extends$1(Component, _super);
|
|
19
|
+
|
|
16
20
|
function Component(params) {
|
|
17
21
|
var _this = _super.call(this) || this;
|
|
22
|
+
|
|
18
23
|
_this.started = false;
|
|
19
24
|
_this.name = _this.constructor.componentName;
|
|
20
25
|
_this.__componentDefaultParams = params;
|
|
21
26
|
return _this;
|
|
22
27
|
}
|
|
28
|
+
|
|
23
29
|
return Component;
|
|
24
30
|
}(EventEmitter);
|
|
31
|
+
|
|
25
32
|
var Component$1 = Component;
|
|
26
33
|
var ObserverType;
|
|
34
|
+
|
|
27
35
|
(function (ObserverType) {
|
|
28
36
|
ObserverType["ADD"] = "ADD";
|
|
29
37
|
ObserverType["REMOVE"] = "REMOVE";
|
|
30
38
|
ObserverType["CHANGE"] = "CHANGE";
|
|
31
39
|
})(ObserverType || (ObserverType = {}));
|
|
40
|
+
|
|
32
41
|
var objectCache = {};
|
|
33
42
|
var systemInstance = {};
|
|
34
43
|
var observerInfos = {};
|
|
35
44
|
var componentProps = {};
|
|
45
|
+
|
|
36
46
|
function getObjectCache(component, keys) {
|
|
37
47
|
if (!objectCache[component.gameObject.id]) {
|
|
38
48
|
objectCache[component.gameObject.id] = {};
|
|
39
49
|
}
|
|
50
|
+
|
|
40
51
|
var cache = objectCache[component.gameObject.id];
|
|
41
52
|
var key = component.name + '_' + keys.join(',');
|
|
53
|
+
|
|
42
54
|
if (cache[key]) {
|
|
43
55
|
return cache[key];
|
|
44
56
|
}
|
|
57
|
+
|
|
45
58
|
var keyIndex = keys.length - 1;
|
|
46
59
|
var property = component;
|
|
60
|
+
|
|
47
61
|
for (var i = 0; i < keyIndex; i++) {
|
|
48
62
|
property = property[keys[i]];
|
|
49
63
|
}
|
|
64
|
+
|
|
50
65
|
cache[key] = {
|
|
51
66
|
property: property,
|
|
52
67
|
key: keys[keyIndex]
|
|
53
68
|
};
|
|
54
69
|
return cache[key];
|
|
55
70
|
}
|
|
71
|
+
|
|
56
72
|
function removeObjectCache(component) {
|
|
57
73
|
if (component.gameObject) {
|
|
58
74
|
delete objectCache[component.gameObject.id];
|
|
59
75
|
}
|
|
60
76
|
}
|
|
77
|
+
|
|
61
78
|
function addObserver(_a) {
|
|
62
79
|
var _b, _c;
|
|
80
|
+
|
|
63
81
|
var systemName = _a.systemName,
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
82
|
+
componentName = _a.componentName,
|
|
83
|
+
component = _a.component,
|
|
84
|
+
prop = _a.prop,
|
|
85
|
+
type = _a.type;
|
|
68
86
|
(_c = (_b = systemInstance[systemName]) === null || _b === void 0 ? void 0 : _b.componentObserver) === null || _c === void 0 ? void 0 : _c.add({
|
|
69
87
|
component: component,
|
|
70
88
|
prop: prop,
|
|
@@ -72,10 +90,12 @@ function addObserver(_a) {
|
|
|
72
90
|
componentName: componentName
|
|
73
91
|
});
|
|
74
92
|
}
|
|
93
|
+
|
|
75
94
|
function pushToQueue(_a) {
|
|
76
95
|
var prop = _a.prop,
|
|
77
|
-
|
|
78
|
-
|
|
96
|
+
component = _a.component,
|
|
97
|
+
componentName = _a.componentName;
|
|
98
|
+
|
|
79
99
|
for (var systemName in observerInfos) {
|
|
80
100
|
var observerInfo = observerInfos[systemName] || {};
|
|
81
101
|
var info = observerInfo[componentName];
|
|
@@ -83,6 +103,7 @@ function pushToQueue(_a) {
|
|
|
83
103
|
var index = info.findIndex(function (p) {
|
|
84
104
|
return isEqual(p, prop);
|
|
85
105
|
});
|
|
106
|
+
|
|
86
107
|
if (index > -1) {
|
|
87
108
|
addObserver({
|
|
88
109
|
systemName: systemName,
|
|
@@ -94,25 +115,31 @@ function pushToQueue(_a) {
|
|
|
94
115
|
}
|
|
95
116
|
}
|
|
96
117
|
}
|
|
118
|
+
|
|
97
119
|
function defineProperty(_a) {
|
|
98
120
|
var e_1, _b;
|
|
121
|
+
|
|
99
122
|
var obj = _a.obj,
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
123
|
+
key = _a.key,
|
|
124
|
+
prop = _a.prop,
|
|
125
|
+
component = _a.component,
|
|
126
|
+
componentName = _a.componentName;
|
|
127
|
+
|
|
104
128
|
if (obj === undefined) {
|
|
105
129
|
return;
|
|
106
130
|
}
|
|
131
|
+
|
|
107
132
|
if (!(key in obj)) {
|
|
108
133
|
console.error("prop " + key + " not in component: " + componentName + ", Can not observer");
|
|
109
134
|
return;
|
|
110
135
|
}
|
|
136
|
+
|
|
111
137
|
Object.defineProperty(obj, "_" + key, {
|
|
112
138
|
enumerable: false,
|
|
113
139
|
writable: true,
|
|
114
140
|
value: obj[key]
|
|
115
141
|
});
|
|
142
|
+
|
|
116
143
|
if (prop.deep && isObject(obj[key])) {
|
|
117
144
|
try {
|
|
118
145
|
for (var _c = __values(Object.keys(obj[key])), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
@@ -137,6 +164,7 @@ function defineProperty(_a) {
|
|
|
137
164
|
}
|
|
138
165
|
}
|
|
139
166
|
}
|
|
167
|
+
|
|
140
168
|
Object.defineProperty(obj, key, {
|
|
141
169
|
enumerable: true,
|
|
142
170
|
set: function set(val) {
|
|
@@ -153,34 +181,44 @@ function defineProperty(_a) {
|
|
|
153
181
|
}
|
|
154
182
|
});
|
|
155
183
|
}
|
|
184
|
+
|
|
156
185
|
function isComponent(comp) {
|
|
157
186
|
return comp && comp.constructor && 'componentName' in comp.constructor;
|
|
158
187
|
}
|
|
188
|
+
|
|
159
189
|
function initObserver(Systems) {
|
|
160
190
|
var e_2, _a, e_3, _b;
|
|
191
|
+
|
|
161
192
|
var Ss = [];
|
|
193
|
+
|
|
162
194
|
if (Systems instanceof Array) {
|
|
163
195
|
Ss.push.apply(Ss, __spread(Systems));
|
|
164
196
|
} else {
|
|
165
197
|
Ss.push(Systems);
|
|
166
198
|
}
|
|
199
|
+
|
|
167
200
|
try {
|
|
168
201
|
for (var Ss_1 = __values(Ss), Ss_1_1 = Ss_1.next(); !Ss_1_1.done; Ss_1_1 = Ss_1.next()) {
|
|
169
202
|
var S = Ss_1_1.value;
|
|
203
|
+
|
|
170
204
|
for (var componentName in S.observerInfo) {
|
|
171
205
|
componentProps[componentName] = componentProps[componentName] || [];
|
|
172
206
|
var props = componentProps[componentName];
|
|
207
|
+
|
|
173
208
|
var _loop_1 = function _loop_1(prop) {
|
|
174
209
|
var index = props.findIndex(function (p) {
|
|
175
210
|
return isEqual(p, prop);
|
|
176
211
|
});
|
|
212
|
+
|
|
177
213
|
if (index === -1) {
|
|
178
214
|
componentProps[componentName].push(prop);
|
|
179
215
|
}
|
|
180
216
|
};
|
|
217
|
+
|
|
181
218
|
try {
|
|
182
219
|
for (var _c = (e_3 = void 0, __values(S.observerInfo[componentName])), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
183
220
|
var prop = _d.value;
|
|
221
|
+
|
|
184
222
|
_loop_1(prop);
|
|
185
223
|
}
|
|
186
224
|
} catch (e_3_1) {
|
|
@@ -208,26 +246,34 @@ function initObserver(Systems) {
|
|
|
208
246
|
}
|
|
209
247
|
}
|
|
210
248
|
}
|
|
249
|
+
|
|
211
250
|
function observer(component, componentName) {
|
|
212
251
|
var e_4, _a;
|
|
252
|
+
|
|
213
253
|
if (componentName === void 0) {
|
|
214
254
|
componentName = component.name;
|
|
215
255
|
}
|
|
256
|
+
|
|
216
257
|
if (!componentName || !componentProps[componentName]) {
|
|
217
258
|
return;
|
|
218
259
|
}
|
|
260
|
+
|
|
219
261
|
if (!component || !isComponent(component)) {
|
|
220
262
|
throw new Error('component param must be an instance of Component');
|
|
221
263
|
}
|
|
264
|
+
|
|
222
265
|
if (!component.gameObject || !component.gameObject.id) {
|
|
223
266
|
throw new Error('component should be add to a gameObject');
|
|
224
267
|
}
|
|
268
|
+
|
|
225
269
|
try {
|
|
226
270
|
for (var _b = __values(componentProps[componentName]), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
227
271
|
var item = _c.value;
|
|
272
|
+
|
|
228
273
|
var _d = getObjectCache(component, item.prop),
|
|
229
|
-
|
|
230
|
-
|
|
274
|
+
property = _d.property,
|
|
275
|
+
key = _d.key;
|
|
276
|
+
|
|
231
277
|
defineProperty({
|
|
232
278
|
obj: property,
|
|
233
279
|
key: key,
|
|
@@ -248,14 +294,18 @@ function observer(component, componentName) {
|
|
|
248
294
|
}
|
|
249
295
|
}
|
|
250
296
|
}
|
|
297
|
+
|
|
251
298
|
function observerAdded(component, componentName) {
|
|
252
299
|
var _a, _b;
|
|
300
|
+
|
|
253
301
|
if (componentName === void 0) {
|
|
254
302
|
componentName = component.name;
|
|
255
303
|
}
|
|
304
|
+
|
|
256
305
|
for (var systemName in observerInfos) {
|
|
257
306
|
var observerInfo = observerInfos[systemName] || {};
|
|
258
307
|
var info = observerInfo[componentName];
|
|
308
|
+
|
|
259
309
|
if (info) {
|
|
260
310
|
(_b = (_a = systemInstance[systemName]) === null || _a === void 0 ? void 0 : _a.componentObserver) === null || _b === void 0 ? void 0 : _b.add({
|
|
261
311
|
component: component,
|
|
@@ -265,14 +315,18 @@ function observerAdded(component, componentName) {
|
|
|
265
315
|
}
|
|
266
316
|
}
|
|
267
317
|
}
|
|
318
|
+
|
|
268
319
|
function observerRemoved(component, componentName) {
|
|
269
320
|
var _a, _b;
|
|
321
|
+
|
|
270
322
|
if (componentName === void 0) {
|
|
271
323
|
componentName = component.name;
|
|
272
324
|
}
|
|
325
|
+
|
|
273
326
|
for (var systemName in observerInfos) {
|
|
274
327
|
var observerInfo = observerInfos[systemName] || {};
|
|
275
328
|
var info = observerInfo[componentName];
|
|
329
|
+
|
|
276
330
|
if (info) {
|
|
277
331
|
(_b = (_a = systemInstance[systemName]) === null || _a === void 0 ? void 0 : _a.componentObserver) === null || _b === void 0 ? void 0 : _b.add({
|
|
278
332
|
component: component,
|
|
@@ -281,16 +335,21 @@ function observerRemoved(component, componentName) {
|
|
|
281
335
|
});
|
|
282
336
|
}
|
|
283
337
|
}
|
|
338
|
+
|
|
284
339
|
removeObjectCache(component);
|
|
285
340
|
}
|
|
341
|
+
|
|
286
342
|
function setSystemObserver(system, S) {
|
|
287
343
|
observerInfos[S.systemName] = S.observerInfo;
|
|
288
344
|
systemInstance[S.systemName] = system;
|
|
289
345
|
}
|
|
346
|
+
|
|
290
347
|
var Transform = function (_super) {
|
|
291
348
|
__extends$1(Transform, _super);
|
|
349
|
+
|
|
292
350
|
function Transform() {
|
|
293
351
|
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
352
|
+
|
|
294
353
|
_this.name = 'Transform';
|
|
295
354
|
_this._parent = null;
|
|
296
355
|
_this.inScene = false;
|
|
@@ -322,15 +381,20 @@ var Transform = function (_super) {
|
|
|
322
381
|
_this.rotation = 0;
|
|
323
382
|
return _this;
|
|
324
383
|
}
|
|
384
|
+
|
|
325
385
|
Transform.prototype.init = function (params) {
|
|
326
386
|
var e_1, _a;
|
|
387
|
+
|
|
327
388
|
if (params === void 0) {
|
|
328
389
|
params = {};
|
|
329
390
|
}
|
|
391
|
+
|
|
330
392
|
var props = ['position', 'size', 'origin', 'anchor', 'scale', 'skew'];
|
|
393
|
+
|
|
331
394
|
try {
|
|
332
395
|
for (var props_1 = __values(props), props_1_1 = props_1.next(); !props_1_1.done; props_1_1 = props_1.next()) {
|
|
333
396
|
var key = props_1_1.value;
|
|
397
|
+
|
|
334
398
|
_extends(this[key], params[key]);
|
|
335
399
|
}
|
|
336
400
|
} catch (e_1_1) {
|
|
@@ -344,8 +408,10 @@ var Transform = function (_super) {
|
|
|
344
408
|
if (e_1) throw e_1.error;
|
|
345
409
|
}
|
|
346
410
|
}
|
|
411
|
+
|
|
347
412
|
this.rotation = params.rotation || this.rotation;
|
|
348
413
|
};
|
|
414
|
+
|
|
349
415
|
Object.defineProperty(Transform.prototype, "parent", {
|
|
350
416
|
get: function get() {
|
|
351
417
|
return this._parent;
|
|
@@ -360,6 +426,7 @@ var Transform = function (_super) {
|
|
|
360
426
|
enumerable: false,
|
|
361
427
|
configurable: true
|
|
362
428
|
});
|
|
429
|
+
|
|
363
430
|
Transform.prototype.addChild = function (child) {
|
|
364
431
|
if (child.parent === this) {
|
|
365
432
|
var index = this.children.findIndex(function (item) {
|
|
@@ -369,36 +436,52 @@ var Transform = function (_super) {
|
|
|
369
436
|
} else if (child.parent) {
|
|
370
437
|
child.parent.removeChild(child);
|
|
371
438
|
}
|
|
439
|
+
|
|
372
440
|
child._parent = this;
|
|
373
441
|
this.children.push(child);
|
|
374
442
|
};
|
|
443
|
+
|
|
375
444
|
Transform.prototype.removeChild = function (child) {
|
|
376
445
|
var index = this.children.findIndex(function (item) {
|
|
377
446
|
return item === child;
|
|
378
447
|
});
|
|
448
|
+
|
|
379
449
|
if (index > -1) {
|
|
380
450
|
this.children.splice(index, 1);
|
|
381
451
|
child._parent = null;
|
|
382
452
|
}
|
|
383
453
|
};
|
|
454
|
+
|
|
384
455
|
Transform.prototype.clearChildren = function () {
|
|
385
456
|
this.children.length = 0;
|
|
386
457
|
};
|
|
458
|
+
|
|
387
459
|
Transform.componentName = 'Transform';
|
|
460
|
+
|
|
388
461
|
__decorate([type('vector2'), step(1)], Transform.prototype, "position", void 0);
|
|
462
|
+
|
|
389
463
|
__decorate([type('size'), step(1)], Transform.prototype, "size", void 0);
|
|
464
|
+
|
|
390
465
|
__decorate([type('vector2'), step(0.1)], Transform.prototype, "origin", void 0);
|
|
466
|
+
|
|
391
467
|
__decorate([type('vector2'), step(0.1)], Transform.prototype, "anchor", void 0);
|
|
468
|
+
|
|
392
469
|
__decorate([type('vector2'), step(0.1)], Transform.prototype, "scale", void 0);
|
|
470
|
+
|
|
393
471
|
__decorate([type('vector2'), step(0.1)], Transform.prototype, "skew", void 0);
|
|
472
|
+
|
|
394
473
|
__decorate([type('number'), step(0.1)], Transform.prototype, "rotation", void 0);
|
|
474
|
+
|
|
395
475
|
return Transform;
|
|
396
476
|
}(Component$1);
|
|
477
|
+
|
|
397
478
|
var Transform$1 = Transform;
|
|
398
479
|
var _id = 0;
|
|
480
|
+
|
|
399
481
|
function getId() {
|
|
400
482
|
return ++_id;
|
|
401
483
|
}
|
|
484
|
+
|
|
402
485
|
var GameObject = function () {
|
|
403
486
|
function GameObject(name, obj) {
|
|
404
487
|
this._componentCache = {};
|
|
@@ -408,6 +491,7 @@ var GameObject = function () {
|
|
|
408
491
|
this.id = getId();
|
|
409
492
|
this.addComponent(Transform$1, obj);
|
|
410
493
|
}
|
|
494
|
+
|
|
411
495
|
Object.defineProperty(GameObject.prototype, "transform", {
|
|
412
496
|
get: function get() {
|
|
413
497
|
return this.getComponent(Transform$1);
|
|
@@ -435,9 +519,11 @@ var GameObject = function () {
|
|
|
435
519
|
},
|
|
436
520
|
set: function set(val) {
|
|
437
521
|
var e_1, _a;
|
|
522
|
+
|
|
438
523
|
if (this._scene === val) return;
|
|
439
524
|
var scene = this._scene;
|
|
440
525
|
this._scene = val;
|
|
526
|
+
|
|
441
527
|
if (this.transform && this.transform.children) {
|
|
442
528
|
try {
|
|
443
529
|
for (var _b = __values(this.transform.children), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
@@ -456,6 +542,7 @@ var GameObject = function () {
|
|
|
456
542
|
}
|
|
457
543
|
}
|
|
458
544
|
}
|
|
545
|
+
|
|
459
546
|
if (val) {
|
|
460
547
|
val.addGameObject(this);
|
|
461
548
|
} else {
|
|
@@ -465,30 +552,38 @@ var GameObject = function () {
|
|
|
465
552
|
enumerable: false,
|
|
466
553
|
configurable: true
|
|
467
554
|
});
|
|
555
|
+
|
|
468
556
|
GameObject.prototype.addChild = function (gameObject) {
|
|
469
557
|
if (!gameObject || !gameObject.transform || gameObject === this) return;
|
|
558
|
+
|
|
470
559
|
if (!(gameObject instanceof GameObject)) {
|
|
471
560
|
throw new Error('addChild only receive GameObject');
|
|
472
561
|
}
|
|
562
|
+
|
|
473
563
|
if (!this.transform) {
|
|
474
564
|
throw new Error("gameObject '" + this.name + "' has been destroy");
|
|
475
565
|
}
|
|
566
|
+
|
|
476
567
|
gameObject.transform.parent = this.transform;
|
|
477
568
|
gameObject.scene = this.scene;
|
|
478
569
|
};
|
|
570
|
+
|
|
479
571
|
GameObject.prototype.removeChild = function (gameObject) {
|
|
480
572
|
if (!(gameObject instanceof GameObject) || !gameObject.parent || gameObject.parent !== this) {
|
|
481
573
|
return gameObject;
|
|
482
574
|
}
|
|
575
|
+
|
|
483
576
|
gameObject.transform.parent = null;
|
|
484
577
|
gameObject.scene = null;
|
|
485
578
|
return gameObject;
|
|
486
579
|
};
|
|
580
|
+
|
|
487
581
|
GameObject.prototype.addComponent = function (C, obj) {
|
|
488
582
|
if (this.destroyed) return;
|
|
489
583
|
var componentName = getComponentName(C);
|
|
490
584
|
if (this._componentCache[componentName]) return;
|
|
491
585
|
var component;
|
|
586
|
+
|
|
492
587
|
if (C instanceof Function) {
|
|
493
588
|
component = new C(obj);
|
|
494
589
|
} else if (C instanceof Component$1) {
|
|
@@ -496,9 +591,11 @@ var GameObject = function () {
|
|
|
496
591
|
} else {
|
|
497
592
|
throw new Error('addComponent recieve Component and Component Constructor');
|
|
498
593
|
}
|
|
594
|
+
|
|
499
595
|
if (component.gameObject) {
|
|
500
596
|
throw new Error("component has been added on gameObject " + component.gameObject.name);
|
|
501
597
|
}
|
|
598
|
+
|
|
502
599
|
component.gameObject = this;
|
|
503
600
|
component.init && component.init(component.__componentDefaultParams);
|
|
504
601
|
observerAdded(component, component.name);
|
|
@@ -508,8 +605,10 @@ var GameObject = function () {
|
|
|
508
605
|
component.awake && component.awake();
|
|
509
606
|
return component;
|
|
510
607
|
};
|
|
608
|
+
|
|
511
609
|
GameObject.prototype.removeComponent = function (c) {
|
|
512
610
|
var componentName;
|
|
611
|
+
|
|
513
612
|
if (typeof c === 'string') {
|
|
514
613
|
componentName = c;
|
|
515
614
|
} else if (c instanceof Component$1) {
|
|
@@ -517,11 +616,14 @@ var GameObject = function () {
|
|
|
517
616
|
} else if (c.componentName) {
|
|
518
617
|
componentName = c.componentName;
|
|
519
618
|
}
|
|
619
|
+
|
|
520
620
|
if (componentName === 'Transform') {
|
|
521
621
|
throw new Error("Transform can't be removed");
|
|
522
622
|
}
|
|
623
|
+
|
|
523
624
|
return this._removeComponent(componentName);
|
|
524
625
|
};
|
|
626
|
+
|
|
525
627
|
GameObject.prototype._removeComponent = function (componentName) {
|
|
526
628
|
var index = this.components.findIndex(function (_a) {
|
|
527
629
|
var name = _a.name;
|
|
@@ -536,8 +638,10 @@ var GameObject = function () {
|
|
|
536
638
|
component.gameObject = undefined;
|
|
537
639
|
return component;
|
|
538
640
|
};
|
|
641
|
+
|
|
539
642
|
GameObject.prototype.getComponent = function (c) {
|
|
540
643
|
var componentName;
|
|
644
|
+
|
|
541
645
|
if (typeof c === 'string') {
|
|
542
646
|
componentName = c;
|
|
543
647
|
} else if (c instanceof Component$1) {
|
|
@@ -545,44 +649,55 @@ var GameObject = function () {
|
|
|
545
649
|
} else if (c.componentName) {
|
|
546
650
|
componentName = c.componentName;
|
|
547
651
|
}
|
|
652
|
+
|
|
548
653
|
if (typeof this._componentCache[componentName] !== 'undefined') {
|
|
549
654
|
return this._componentCache[componentName];
|
|
550
655
|
} else {
|
|
551
656
|
return;
|
|
552
657
|
}
|
|
553
658
|
};
|
|
659
|
+
|
|
554
660
|
GameObject.prototype.remove = function () {
|
|
555
661
|
if (this.parent) return this.parent.removeChild(this);
|
|
556
662
|
};
|
|
663
|
+
|
|
557
664
|
GameObject.prototype.destroy = function () {
|
|
558
665
|
if (!this.transform) {
|
|
559
666
|
console.error('Cannot destroy gameObject that have already been destroyed.');
|
|
560
667
|
return;
|
|
561
668
|
}
|
|
669
|
+
|
|
562
670
|
Array.from(this.transform.children).forEach(function (_a) {
|
|
563
671
|
var gameObject = _a.gameObject;
|
|
564
672
|
gameObject.destroy();
|
|
565
673
|
});
|
|
566
674
|
this.remove();
|
|
567
675
|
this.transform.clearChildren();
|
|
676
|
+
|
|
568
677
|
for (var key in this._componentCache) {
|
|
569
678
|
this._removeComponent(key);
|
|
570
679
|
}
|
|
680
|
+
|
|
571
681
|
this.components.length = 0;
|
|
572
682
|
this.destroyed = true;
|
|
573
683
|
};
|
|
684
|
+
|
|
574
685
|
return GameObject;
|
|
575
686
|
}();
|
|
687
|
+
|
|
576
688
|
var GameObject$1 = GameObject;
|
|
689
|
+
|
|
577
690
|
var ComponentObserver = function () {
|
|
578
691
|
function ComponentObserver() {
|
|
579
692
|
this.events = [];
|
|
580
693
|
}
|
|
694
|
+
|
|
581
695
|
ComponentObserver.prototype.add = function (_a) {
|
|
582
696
|
var component = _a.component,
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
697
|
+
prop = _a.prop,
|
|
698
|
+
type = _a.type,
|
|
699
|
+
componentName = _a.componentName;
|
|
700
|
+
|
|
586
701
|
if (type === ObserverType.REMOVE) {
|
|
587
702
|
if (this.events.find(function (changed) {
|
|
588
703
|
return changed.component === component && changed.type === ObserverType.ADD;
|
|
@@ -592,16 +707,20 @@ var ComponentObserver = function () {
|
|
|
592
707
|
});
|
|
593
708
|
return;
|
|
594
709
|
}
|
|
710
|
+
|
|
595
711
|
this.events = this.events.filter(function (changed) {
|
|
596
712
|
return changed.component !== component;
|
|
597
713
|
});
|
|
598
714
|
}
|
|
715
|
+
|
|
599
716
|
var index = this.events.findIndex(function (changed) {
|
|
600
717
|
return changed.component === component && isEqual(changed.prop, prop) && changed.type === type;
|
|
601
718
|
});
|
|
719
|
+
|
|
602
720
|
if (index > -1) {
|
|
603
721
|
this.events.splice(index, 1);
|
|
604
722
|
}
|
|
723
|
+
|
|
605
724
|
this.events.push({
|
|
606
725
|
gameObject: component.gameObject,
|
|
607
726
|
component: component,
|
|
@@ -610,9 +729,11 @@ var ComponentObserver = function () {
|
|
|
610
729
|
componentName: componentName
|
|
611
730
|
});
|
|
612
731
|
};
|
|
732
|
+
|
|
613
733
|
ComponentObserver.prototype.getChanged = function () {
|
|
614
734
|
return this.events;
|
|
615
735
|
};
|
|
736
|
+
|
|
616
737
|
Object.defineProperty(ComponentObserver.prototype, "changed", {
|
|
617
738
|
get: function get() {
|
|
618
739
|
return this.events;
|
|
@@ -620,14 +741,18 @@ var ComponentObserver = function () {
|
|
|
620
741
|
enumerable: false,
|
|
621
742
|
configurable: true
|
|
622
743
|
});
|
|
744
|
+
|
|
623
745
|
ComponentObserver.prototype.clear = function () {
|
|
624
746
|
var events = this.events;
|
|
625
747
|
this.events = [];
|
|
626
748
|
return events;
|
|
627
749
|
};
|
|
750
|
+
|
|
628
751
|
return ComponentObserver;
|
|
629
752
|
}();
|
|
753
|
+
|
|
630
754
|
var ComponentObserver$1 = ComponentObserver;
|
|
755
|
+
|
|
631
756
|
var System = function () {
|
|
632
757
|
function System(params) {
|
|
633
758
|
this.started = false;
|
|
@@ -635,17 +760,23 @@ var System = function () {
|
|
|
635
760
|
this.__systemDefaultParams = params;
|
|
636
761
|
this.name = this.constructor.systemName;
|
|
637
762
|
}
|
|
763
|
+
|
|
638
764
|
System.prototype.destroy = function () {
|
|
639
765
|
var _a;
|
|
766
|
+
|
|
640
767
|
this.componentObserver = null;
|
|
641
768
|
this.__systemDefaultParams = null;
|
|
642
769
|
(_a = this.onDestroy) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
643
770
|
};
|
|
771
|
+
|
|
644
772
|
return System;
|
|
645
773
|
}();
|
|
774
|
+
|
|
646
775
|
var System$1 = System;
|
|
776
|
+
|
|
647
777
|
function createNowTime() {
|
|
648
778
|
var nowtime = null;
|
|
779
|
+
|
|
649
780
|
if (Date.now) {
|
|
650
781
|
nowtime = Date.now;
|
|
651
782
|
} else {
|
|
@@ -653,23 +784,30 @@ function createNowTime() {
|
|
|
653
784
|
return new Date().getTime();
|
|
654
785
|
};
|
|
655
786
|
}
|
|
787
|
+
|
|
656
788
|
return nowtime;
|
|
657
789
|
}
|
|
790
|
+
|
|
658
791
|
var _nowtime = createNowTime();
|
|
792
|
+
|
|
659
793
|
var defaultOptions$1 = {
|
|
660
794
|
originTime: 0,
|
|
661
795
|
playbackRate: 1.0
|
|
662
796
|
};
|
|
797
|
+
|
|
663
798
|
var Timeline = function () {
|
|
664
799
|
function Timeline(options, parent) {
|
|
665
800
|
if (options instanceof Timeline) {
|
|
666
801
|
parent = options;
|
|
667
802
|
options = {};
|
|
668
803
|
}
|
|
804
|
+
|
|
669
805
|
options = _extends({}, defaultOptions$1, options);
|
|
806
|
+
|
|
670
807
|
if (parent) {
|
|
671
808
|
this._parent = parent;
|
|
672
809
|
}
|
|
810
|
+
|
|
673
811
|
this._createTime = _nowtime();
|
|
674
812
|
this._timeMark = [{
|
|
675
813
|
globalTime: this.globalTime,
|
|
@@ -678,11 +816,14 @@ var Timeline = function () {
|
|
|
678
816
|
playbackRate: options.playbackRate,
|
|
679
817
|
globalEntropy: 0
|
|
680
818
|
}];
|
|
819
|
+
|
|
681
820
|
if (this._parent) {
|
|
682
821
|
this._timeMark[0].globalEntropy = this._parent.entropy;
|
|
683
822
|
}
|
|
823
|
+
|
|
684
824
|
this._playbackRate = options.playbackRate;
|
|
685
825
|
}
|
|
826
|
+
|
|
686
827
|
Object.defineProperty(Timeline.prototype, "globalTime", {
|
|
687
828
|
get: function get() {
|
|
688
829
|
return this.parent ? this.parent.currentTime : _nowtime() - this._createTime;
|
|
@@ -704,14 +845,16 @@ var Timeline = function () {
|
|
|
704
845
|
enumerable: false,
|
|
705
846
|
configurable: true
|
|
706
847
|
});
|
|
848
|
+
|
|
707
849
|
Timeline.prototype.markTime = function (_a) {
|
|
708
850
|
var _b = _a === void 0 ? {} : _a,
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
851
|
+
_c = _b.time,
|
|
852
|
+
time = _c === void 0 ? this.currentTime : _c,
|
|
853
|
+
_d = _b.entropy,
|
|
854
|
+
entropy = _d === void 0 ? this.entropy : _d,
|
|
855
|
+
_e = _b.playbackRate,
|
|
856
|
+
playbackRate = _e === void 0 ? this.playbackRate : _e;
|
|
857
|
+
|
|
715
858
|
var timeMark = {
|
|
716
859
|
globalTime: this.globalTime,
|
|
717
860
|
localTime: time,
|
|
@@ -719,13 +862,15 @@ var Timeline = function () {
|
|
|
719
862
|
playbackRate: playbackRate,
|
|
720
863
|
globalEntropy: this.globalEntropy
|
|
721
864
|
};
|
|
865
|
+
|
|
722
866
|
this._timeMark.push(timeMark);
|
|
723
867
|
};
|
|
868
|
+
|
|
724
869
|
Object.defineProperty(Timeline.prototype, "currentTime", {
|
|
725
870
|
get: function get() {
|
|
726
871
|
var _a = this.lastTimeMark,
|
|
727
|
-
|
|
728
|
-
|
|
872
|
+
localTime = _a.localTime,
|
|
873
|
+
globalTime = _a.globalTime;
|
|
729
874
|
return localTime + (this.globalTime - globalTime) * this.playbackRate;
|
|
730
875
|
},
|
|
731
876
|
set: function set(time) {
|
|
@@ -746,8 +891,8 @@ var Timeline = function () {
|
|
|
746
891
|
Object.defineProperty(Timeline.prototype, "entropy", {
|
|
747
892
|
get: function get() {
|
|
748
893
|
var _a = this.lastTimeMark,
|
|
749
|
-
|
|
750
|
-
|
|
894
|
+
entropy = _a.entropy,
|
|
895
|
+
globalEntropy = _a.globalEntropy;
|
|
751
896
|
return entropy + Math.abs((this.globalEntropy - globalEntropy) * this.playbackRate);
|
|
752
897
|
},
|
|
753
898
|
set: function set(entropy) {
|
|
@@ -755,6 +900,7 @@ var Timeline = function () {
|
|
|
755
900
|
var idx = this.seekTimeMark(entropy);
|
|
756
901
|
this._timeMark.length = idx + 1;
|
|
757
902
|
}
|
|
903
|
+
|
|
758
904
|
this.markTime({
|
|
759
905
|
entropy: entropy
|
|
760
906
|
});
|
|
@@ -762,52 +908,66 @@ var Timeline = function () {
|
|
|
762
908
|
enumerable: false,
|
|
763
909
|
configurable: true
|
|
764
910
|
});
|
|
911
|
+
|
|
765
912
|
Timeline.prototype.fork = function (options) {
|
|
766
913
|
return new Timeline(options, this);
|
|
767
914
|
};
|
|
915
|
+
|
|
768
916
|
Timeline.prototype.seekGlobalTime = function (seekEntropy) {
|
|
769
917
|
var idx = this.seekTimeMark(seekEntropy),
|
|
770
|
-
|
|
918
|
+
timeMark = this._timeMark[idx];
|
|
771
919
|
var entropy = timeMark.entropy,
|
|
772
|
-
|
|
773
|
-
|
|
920
|
+
playbackRate = timeMark.playbackRate,
|
|
921
|
+
globalTime = timeMark.globalTime;
|
|
774
922
|
return globalTime + (seekEntropy - entropy) / Math.abs(playbackRate);
|
|
775
923
|
};
|
|
924
|
+
|
|
776
925
|
Timeline.prototype.seekLocalTime = function (seekEntropy) {
|
|
777
926
|
var idx = this.seekTimeMark(seekEntropy),
|
|
778
|
-
|
|
927
|
+
timeMark = this._timeMark[idx];
|
|
779
928
|
var localTime = timeMark.localTime,
|
|
780
|
-
|
|
781
|
-
|
|
929
|
+
entropy = timeMark.entropy,
|
|
930
|
+
playbackRate = timeMark.playbackRate;
|
|
931
|
+
|
|
782
932
|
if (playbackRate > 0) {
|
|
783
933
|
return localTime + (seekEntropy - entropy);
|
|
784
934
|
}
|
|
935
|
+
|
|
785
936
|
return localTime - (seekEntropy - entropy);
|
|
786
937
|
};
|
|
938
|
+
|
|
787
939
|
Timeline.prototype.seekTimeMark = function (entropy) {
|
|
788
940
|
var timeMark = this._timeMark;
|
|
789
941
|
var l = 0,
|
|
790
|
-
|
|
942
|
+
r = timeMark.length - 1;
|
|
943
|
+
|
|
791
944
|
if (entropy <= timeMark[l].entropy) {
|
|
792
945
|
return l;
|
|
793
946
|
}
|
|
947
|
+
|
|
794
948
|
if (entropy >= timeMark[r].entropy) {
|
|
795
949
|
return r;
|
|
796
950
|
}
|
|
951
|
+
|
|
797
952
|
var m = Math.floor((l + r) / 2);
|
|
953
|
+
|
|
798
954
|
while (m > l && m < r) {
|
|
799
955
|
if (entropy === timeMark[m].entropy) {
|
|
800
956
|
return m;
|
|
801
957
|
}
|
|
958
|
+
|
|
802
959
|
if (entropy < timeMark[m].entropy) {
|
|
803
960
|
r = m;
|
|
804
961
|
} else if (entropy > timeMark[m].entropy) {
|
|
805
962
|
l = m;
|
|
806
963
|
}
|
|
964
|
+
|
|
807
965
|
m = Math.floor((l + r) / 2);
|
|
808
966
|
}
|
|
967
|
+
|
|
809
968
|
return l;
|
|
810
969
|
};
|
|
970
|
+
|
|
811
971
|
Object.defineProperty(Timeline.prototype, "playbackRate", {
|
|
812
972
|
get: function get() {
|
|
813
973
|
return this._playbackRate;
|
|
@@ -827,10 +987,12 @@ var Timeline = function () {
|
|
|
827
987
|
get: function get() {
|
|
828
988
|
if (this.playbackRate === 0) return true;
|
|
829
989
|
var parent = this.parent;
|
|
990
|
+
|
|
830
991
|
while (parent) {
|
|
831
992
|
if (parent.playbackRate === 0) return true;
|
|
832
993
|
parent = parent.parent;
|
|
833
994
|
}
|
|
995
|
+
|
|
834
996
|
return false;
|
|
835
997
|
},
|
|
836
998
|
enumerable: false,
|
|
@@ -838,14 +1000,17 @@ var Timeline = function () {
|
|
|
838
1000
|
});
|
|
839
1001
|
return Timeline;
|
|
840
1002
|
}();
|
|
1003
|
+
|
|
841
1004
|
var Timeline$1 = Timeline;
|
|
842
1005
|
var defaultOptions = {
|
|
843
1006
|
autoStart: true,
|
|
844
1007
|
frameRate: 60
|
|
845
1008
|
};
|
|
1009
|
+
|
|
846
1010
|
var Ticker = function () {
|
|
847
1011
|
function Ticker(options) {
|
|
848
1012
|
var _this = this;
|
|
1013
|
+
|
|
849
1014
|
options = _extends({}, defaultOptions, options);
|
|
850
1015
|
this._frameCount = 0;
|
|
851
1016
|
this._frameDuration = 1000 / options.frameRate;
|
|
@@ -858,20 +1023,26 @@ var Ticker = function () {
|
|
|
858
1023
|
this._lastFrameTime = this.timeline.currentTime;
|
|
859
1024
|
this._tickers = new Set();
|
|
860
1025
|
this._requestId = null;
|
|
1026
|
+
|
|
861
1027
|
this._ticker = function () {
|
|
862
1028
|
if (_this._started) {
|
|
863
1029
|
_this._requestId = requestAnimationFrame(_this._ticker);
|
|
1030
|
+
|
|
864
1031
|
_this.update();
|
|
865
1032
|
}
|
|
866
1033
|
};
|
|
1034
|
+
|
|
867
1035
|
if (this.autoStart) {
|
|
868
1036
|
this.start();
|
|
869
1037
|
}
|
|
870
1038
|
}
|
|
1039
|
+
|
|
871
1040
|
Ticker.prototype.update = function () {
|
|
872
1041
|
var e_1, _a;
|
|
1042
|
+
|
|
873
1043
|
var currentTime = this.timeline.currentTime;
|
|
874
1044
|
var durationTime = currentTime - this._lastFrameTime;
|
|
1045
|
+
|
|
875
1046
|
if (durationTime >= this._frameDuration) {
|
|
876
1047
|
var frameTime = currentTime - durationTime % this._frameDuration;
|
|
877
1048
|
var deltaTime = frameTime - this._lastFrameTime;
|
|
@@ -883,9 +1054,11 @@ var Ticker = function () {
|
|
|
883
1054
|
frameCount: ++this._frameCount,
|
|
884
1055
|
fps: Math.round(1000 / deltaTime)
|
|
885
1056
|
};
|
|
1057
|
+
|
|
886
1058
|
try {
|
|
887
1059
|
for (var _b = __values(this._tickers), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
888
1060
|
var func = _c.value;
|
|
1061
|
+
|
|
889
1062
|
if (typeof func === 'function') {
|
|
890
1063
|
func(options);
|
|
891
1064
|
}
|
|
@@ -903,68 +1076,91 @@ var Ticker = function () {
|
|
|
903
1076
|
}
|
|
904
1077
|
}
|
|
905
1078
|
};
|
|
1079
|
+
|
|
906
1080
|
Ticker.prototype.add = function (fn) {
|
|
907
1081
|
this._tickers.add(fn);
|
|
908
1082
|
};
|
|
1083
|
+
|
|
909
1084
|
Ticker.prototype.remove = function (fn) {
|
|
910
1085
|
this._tickers.delete(fn);
|
|
911
1086
|
};
|
|
1087
|
+
|
|
912
1088
|
Ticker.prototype.start = function () {
|
|
913
1089
|
if (this._started) return;
|
|
914
1090
|
this._started = true;
|
|
915
1091
|
this.timeline.playbackRate = 1.0;
|
|
916
1092
|
this._requestId = requestAnimationFrame(this._ticker);
|
|
917
1093
|
};
|
|
1094
|
+
|
|
918
1095
|
Ticker.prototype.pause = function () {
|
|
919
1096
|
this._started = false;
|
|
920
1097
|
this.timeline.playbackRate = 0;
|
|
921
1098
|
};
|
|
1099
|
+
|
|
922
1100
|
Ticker.prototype.setPlaybackRate = function (rate) {
|
|
923
1101
|
this.timeline.playbackRate = rate;
|
|
924
1102
|
};
|
|
1103
|
+
|
|
925
1104
|
return Ticker;
|
|
926
1105
|
}();
|
|
1106
|
+
|
|
927
1107
|
var Ticker$1 = Ticker;
|
|
1108
|
+
|
|
928
1109
|
var Scene = function (_super) {
|
|
929
1110
|
__extends$1(Scene, _super);
|
|
1111
|
+
|
|
930
1112
|
function Scene(name, obj) {
|
|
931
1113
|
var _this = _super.call(this, name, obj) || this;
|
|
1114
|
+
|
|
932
1115
|
_this.gameObjects = [];
|
|
933
1116
|
_this.scene = _this;
|
|
934
1117
|
return _this;
|
|
935
1118
|
}
|
|
1119
|
+
|
|
936
1120
|
Scene.prototype.addGameObject = function (gameObject) {
|
|
937
1121
|
this.gameObjects.push(gameObject);
|
|
1122
|
+
|
|
938
1123
|
if (gameObject.transform) {
|
|
939
1124
|
gameObject.transform.inScene = true;
|
|
940
1125
|
}
|
|
941
1126
|
};
|
|
1127
|
+
|
|
942
1128
|
Scene.prototype.removeGameObject = function (gameObject) {
|
|
943
1129
|
var index = this.gameObjects.indexOf(gameObject);
|
|
944
1130
|
if (index === -1) return;
|
|
1131
|
+
|
|
945
1132
|
if (gameObject.transform) {
|
|
946
1133
|
gameObject.transform.inScene = false;
|
|
947
1134
|
}
|
|
1135
|
+
|
|
948
1136
|
this.gameObjects.splice(index, 1);
|
|
949
1137
|
};
|
|
1138
|
+
|
|
950
1139
|
Scene.prototype.destroy = function () {
|
|
951
1140
|
this.scene = null;
|
|
1141
|
+
|
|
952
1142
|
_super.prototype.destroy.call(this);
|
|
1143
|
+
|
|
953
1144
|
this.gameObjects = null;
|
|
954
1145
|
this.canvas = null;
|
|
955
1146
|
};
|
|
1147
|
+
|
|
956
1148
|
return Scene;
|
|
957
1149
|
}(GameObject$1);
|
|
1150
|
+
|
|
958
1151
|
var Scene$1 = Scene;
|
|
959
1152
|
var LOAD_SCENE_MODE;
|
|
1153
|
+
|
|
960
1154
|
(function (LOAD_SCENE_MODE) {
|
|
961
1155
|
LOAD_SCENE_MODE["SINGLE"] = "SINGLE";
|
|
962
1156
|
LOAD_SCENE_MODE["MULTI_CANVAS"] = "MULTI_CANVAS";
|
|
963
1157
|
})(LOAD_SCENE_MODE || (LOAD_SCENE_MODE = {}));
|
|
1158
|
+
|
|
964
1159
|
var triggerStart = function triggerStart(obj) {
|
|
965
1160
|
if (!(obj instanceof System$1) && !(obj instanceof Component$1)) return;
|
|
966
1161
|
if (obj.started) return;
|
|
967
1162
|
obj.started = true;
|
|
1163
|
+
|
|
968
1164
|
try {
|
|
969
1165
|
obj.start && obj.start();
|
|
970
1166
|
} catch (e) {
|
|
@@ -975,15 +1171,19 @@ var triggerStart = function triggerStart(obj) {
|
|
|
975
1171
|
}
|
|
976
1172
|
}
|
|
977
1173
|
};
|
|
1174
|
+
|
|
978
1175
|
var getAllGameObjects = function getAllGameObjects(game) {
|
|
979
1176
|
var e_1, _a;
|
|
1177
|
+
|
|
980
1178
|
var _b;
|
|
1179
|
+
|
|
981
1180
|
var mainSceneGameObjects = ((_b = game === null || game === void 0 ? void 0 : game.scene) === null || _b === void 0 ? void 0 : _b.gameObjects) || [];
|
|
982
1181
|
var gameObjectsArray = game === null || game === void 0 ? void 0 : game.multiScenes.map(function (_a) {
|
|
983
1182
|
var gameObjects = _a.gameObjects;
|
|
984
1183
|
return gameObjects;
|
|
985
1184
|
});
|
|
986
1185
|
var otherSceneGameObjects = [];
|
|
1186
|
+
|
|
987
1187
|
try {
|
|
988
1188
|
for (var gameObjectsArray_1 = __values(gameObjectsArray), gameObjectsArray_1_1 = gameObjectsArray_1.next(); !gameObjectsArray_1_1.done; gameObjectsArray_1_1 = gameObjectsArray_1.next()) {
|
|
989
1189
|
var gameObjects = gameObjectsArray_1_1.value;
|
|
@@ -1000,19 +1200,25 @@ var getAllGameObjects = function getAllGameObjects(game) {
|
|
|
1000
1200
|
if (e_1) throw e_1.error;
|
|
1001
1201
|
}
|
|
1002
1202
|
}
|
|
1203
|
+
|
|
1003
1204
|
return __spread(mainSceneGameObjects, otherSceneGameObjects);
|
|
1004
1205
|
};
|
|
1206
|
+
|
|
1005
1207
|
var gameObjectLoop = function gameObjectLoop(e, gameObjects) {
|
|
1006
1208
|
var e_2, _a, e_3, _b, e_4, _c, e_5, _d;
|
|
1209
|
+
|
|
1007
1210
|
if (gameObjects === void 0) {
|
|
1008
1211
|
gameObjects = [];
|
|
1009
1212
|
}
|
|
1213
|
+
|
|
1010
1214
|
try {
|
|
1011
1215
|
for (var gameObjects_1 = __values(gameObjects), gameObjects_1_1 = gameObjects_1.next(); !gameObjects_1_1.done; gameObjects_1_1 = gameObjects_1.next()) {
|
|
1012
1216
|
var gameObject = gameObjects_1_1.value;
|
|
1217
|
+
|
|
1013
1218
|
try {
|
|
1014
1219
|
for (var _e = (e_3 = void 0, __values(gameObject.components)), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
1015
1220
|
var component = _f.value;
|
|
1221
|
+
|
|
1016
1222
|
try {
|
|
1017
1223
|
triggerStart(component);
|
|
1018
1224
|
component.update && component.update(e);
|
|
@@ -1043,12 +1249,15 @@ var gameObjectLoop = function gameObjectLoop(e, gameObjects) {
|
|
|
1043
1249
|
if (e_2) throw e_2.error;
|
|
1044
1250
|
}
|
|
1045
1251
|
}
|
|
1252
|
+
|
|
1046
1253
|
try {
|
|
1047
1254
|
for (var gameObjects_2 = __values(gameObjects), gameObjects_2_1 = gameObjects_2.next(); !gameObjects_2_1.done; gameObjects_2_1 = gameObjects_2.next()) {
|
|
1048
1255
|
var gameObject = gameObjects_2_1.value;
|
|
1256
|
+
|
|
1049
1257
|
try {
|
|
1050
1258
|
for (var _g = (e_5 = void 0, __values(gameObject.components)), _h = _g.next(); !_h.done; _h = _g.next()) {
|
|
1051
1259
|
var component = _h.value;
|
|
1260
|
+
|
|
1052
1261
|
try {
|
|
1053
1262
|
component.lateUpdate && component.lateUpdate(e);
|
|
1054
1263
|
} catch (e) {
|
|
@@ -1079,14 +1288,18 @@ var gameObjectLoop = function gameObjectLoop(e, gameObjects) {
|
|
|
1079
1288
|
}
|
|
1080
1289
|
}
|
|
1081
1290
|
};
|
|
1291
|
+
|
|
1082
1292
|
var gameObjectResume = function gameObjectResume(gameObjects) {
|
|
1083
1293
|
var e_6, _a, e_7, _b;
|
|
1294
|
+
|
|
1084
1295
|
try {
|
|
1085
1296
|
for (var gameObjects_3 = __values(gameObjects), gameObjects_3_1 = gameObjects_3.next(); !gameObjects_3_1.done; gameObjects_3_1 = gameObjects_3.next()) {
|
|
1086
1297
|
var gameObject = gameObjects_3_1.value;
|
|
1298
|
+
|
|
1087
1299
|
try {
|
|
1088
1300
|
for (var _c = (e_7 = void 0, __values(gameObject.components)), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
1089
1301
|
var component = _d.value;
|
|
1302
|
+
|
|
1090
1303
|
try {
|
|
1091
1304
|
component.onResume && component.onResume();
|
|
1092
1305
|
} catch (e) {
|
|
@@ -1117,14 +1330,18 @@ var gameObjectResume = function gameObjectResume(gameObjects) {
|
|
|
1117
1330
|
}
|
|
1118
1331
|
}
|
|
1119
1332
|
};
|
|
1333
|
+
|
|
1120
1334
|
var gameObjectPause = function gameObjectPause(gameObjects) {
|
|
1121
1335
|
var e_8, _a, e_9, _b;
|
|
1336
|
+
|
|
1122
1337
|
try {
|
|
1123
1338
|
for (var gameObjects_4 = __values(gameObjects), gameObjects_4_1 = gameObjects_4.next(); !gameObjects_4_1.done; gameObjects_4_1 = gameObjects_4.next()) {
|
|
1124
1339
|
var gameObject = gameObjects_4_1.value;
|
|
1340
|
+
|
|
1125
1341
|
try {
|
|
1126
1342
|
for (var _c = (e_9 = void 0, __values(gameObject.components)), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
1127
1343
|
var component = _d.value;
|
|
1344
|
+
|
|
1128
1345
|
try {
|
|
1129
1346
|
component.onPause && component.onPause();
|
|
1130
1347
|
} catch (e) {
|
|
@@ -1155,35 +1372,45 @@ var gameObjectPause = function gameObjectPause(gameObjects) {
|
|
|
1155
1372
|
}
|
|
1156
1373
|
}
|
|
1157
1374
|
};
|
|
1375
|
+
|
|
1158
1376
|
var Game = function (_super) {
|
|
1159
1377
|
__extends$1(Game, _super);
|
|
1378
|
+
|
|
1160
1379
|
function Game(_a) {
|
|
1161
1380
|
var e_10, _b;
|
|
1381
|
+
|
|
1162
1382
|
var _c = _a === void 0 ? {} : _a,
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1383
|
+
systems = _c.systems,
|
|
1384
|
+
_d = _c.frameRate,
|
|
1385
|
+
frameRate = _d === void 0 ? 60 : _d,
|
|
1386
|
+
_e = _c.autoStart,
|
|
1387
|
+
autoStart = _e === void 0 ? true : _e,
|
|
1388
|
+
_f = _c.needScene,
|
|
1389
|
+
needScene = _f === void 0 ? true : _f;
|
|
1390
|
+
|
|
1170
1391
|
var _this = _super.call(this) || this;
|
|
1392
|
+
|
|
1171
1393
|
_this.playing = false;
|
|
1172
1394
|
_this.started = false;
|
|
1173
1395
|
_this.multiScenes = [];
|
|
1174
1396
|
_this.systems = [];
|
|
1397
|
+
|
|
1175
1398
|
if (windowAlias.__EVA_INSPECTOR_ENV__) {
|
|
1176
1399
|
windowAlias.__EVA_GAME_INSTANCE__ = _this;
|
|
1177
1400
|
}
|
|
1401
|
+
|
|
1178
1402
|
_this.ticker = new Ticker$1({
|
|
1179
1403
|
autoStart: false,
|
|
1180
1404
|
frameRate: frameRate
|
|
1181
1405
|
});
|
|
1406
|
+
|
|
1182
1407
|
_this.initTicker();
|
|
1408
|
+
|
|
1183
1409
|
if (systems && systems.length) {
|
|
1184
1410
|
try {
|
|
1185
1411
|
for (var systems_1 = __values(systems), systems_1_1 = systems_1.next(); !systems_1_1.done; systems_1_1 = systems_1.next()) {
|
|
1186
1412
|
var system = systems_1_1.value;
|
|
1413
|
+
|
|
1187
1414
|
_this.addSystem(system);
|
|
1188
1415
|
}
|
|
1189
1416
|
} catch (e_10_1) {
|
|
@@ -1198,14 +1425,18 @@ var Game = function (_super) {
|
|
|
1198
1425
|
}
|
|
1199
1426
|
}
|
|
1200
1427
|
}
|
|
1428
|
+
|
|
1201
1429
|
if (needScene) {
|
|
1202
1430
|
_this.loadScene(new Scene$1('scene'));
|
|
1203
1431
|
}
|
|
1432
|
+
|
|
1204
1433
|
if (autoStart) {
|
|
1205
1434
|
_this.start();
|
|
1206
1435
|
}
|
|
1436
|
+
|
|
1207
1437
|
return _this;
|
|
1208
1438
|
}
|
|
1439
|
+
|
|
1209
1440
|
Object.defineProperty(Game.prototype, "scene", {
|
|
1210
1441
|
get: function get() {
|
|
1211
1442
|
return this._scene;
|
|
@@ -1223,8 +1454,10 @@ var Game = function (_super) {
|
|
|
1223
1454
|
enumerable: false,
|
|
1224
1455
|
configurable: true
|
|
1225
1456
|
});
|
|
1457
|
+
|
|
1226
1458
|
Game.prototype.addSystem = function (S, obj) {
|
|
1227
1459
|
var system;
|
|
1460
|
+
|
|
1228
1461
|
if (S instanceof Function) {
|
|
1229
1462
|
system = new S(obj);
|
|
1230
1463
|
} else if (S instanceof System$1) {
|
|
@@ -1233,28 +1466,35 @@ var Game = function (_super) {
|
|
|
1233
1466
|
console.warn('can only add System');
|
|
1234
1467
|
return;
|
|
1235
1468
|
}
|
|
1469
|
+
|
|
1236
1470
|
var hasTheSystem = this.systems.find(function (item) {
|
|
1237
1471
|
return item.constructor === system.constructor;
|
|
1238
1472
|
});
|
|
1473
|
+
|
|
1239
1474
|
if (hasTheSystem) {
|
|
1240
1475
|
console.warn(system.constructor.systemName + " System has been added");
|
|
1241
1476
|
return;
|
|
1242
1477
|
}
|
|
1478
|
+
|
|
1243
1479
|
system.game = this;
|
|
1244
1480
|
system.init && system.init(system.__systemDefaultParams);
|
|
1245
1481
|
setSystemObserver(system, system.constructor);
|
|
1246
1482
|
initObserver(system.constructor);
|
|
1483
|
+
|
|
1247
1484
|
try {
|
|
1248
1485
|
system.awake && system.awake();
|
|
1249
1486
|
} catch (e) {
|
|
1250
1487
|
console.error(system.constructor.systemName + " awake error", e);
|
|
1251
1488
|
}
|
|
1489
|
+
|
|
1252
1490
|
this.systems.push(system);
|
|
1253
1491
|
return system;
|
|
1254
1492
|
};
|
|
1493
|
+
|
|
1255
1494
|
Game.prototype.removeSystem = function (system) {
|
|
1256
1495
|
if (!system) return;
|
|
1257
1496
|
var index = -1;
|
|
1497
|
+
|
|
1258
1498
|
if (typeof system === 'string') {
|
|
1259
1499
|
index = this.systems.findIndex(function (s) {
|
|
1260
1500
|
return s.name === system;
|
|
@@ -1268,11 +1508,13 @@ var Game = function (_super) {
|
|
|
1268
1508
|
return s === system;
|
|
1269
1509
|
});
|
|
1270
1510
|
}
|
|
1511
|
+
|
|
1271
1512
|
if (index > -1) {
|
|
1272
1513
|
this.systems[index].destroy && this.systems[index].destroy();
|
|
1273
1514
|
this.systems.splice(index, 1);
|
|
1274
1515
|
}
|
|
1275
1516
|
};
|
|
1517
|
+
|
|
1276
1518
|
Game.prototype.getSystem = function (S) {
|
|
1277
1519
|
return this.systems.find(function (system) {
|
|
1278
1520
|
if (typeof S === 'string') {
|
|
@@ -1282,32 +1524,40 @@ var Game = function (_super) {
|
|
|
1282
1524
|
}
|
|
1283
1525
|
});
|
|
1284
1526
|
};
|
|
1527
|
+
|
|
1285
1528
|
Game.prototype.pause = function () {
|
|
1286
1529
|
if (!this.playing) return;
|
|
1287
1530
|
this.playing = false;
|
|
1288
1531
|
this.ticker.pause();
|
|
1289
1532
|
this.triggerPause();
|
|
1290
1533
|
};
|
|
1534
|
+
|
|
1291
1535
|
Game.prototype.start = function () {
|
|
1292
1536
|
if (this.playing) return;
|
|
1293
1537
|
this.playing = true;
|
|
1294
1538
|
this.started = true;
|
|
1295
1539
|
this.ticker.start();
|
|
1296
1540
|
};
|
|
1541
|
+
|
|
1297
1542
|
Game.prototype.resume = function () {
|
|
1298
1543
|
if (this.playing) return;
|
|
1299
1544
|
this.playing = true;
|
|
1300
1545
|
this.ticker.start();
|
|
1301
1546
|
this.triggerResume();
|
|
1302
1547
|
};
|
|
1548
|
+
|
|
1303
1549
|
Game.prototype.initTicker = function () {
|
|
1304
1550
|
var _this = this;
|
|
1551
|
+
|
|
1305
1552
|
this.ticker.add(function (e) {
|
|
1306
1553
|
var e_11, _a, e_12, _b;
|
|
1554
|
+
|
|
1307
1555
|
_this.scene && gameObjectLoop(e, _this.gameObjects);
|
|
1556
|
+
|
|
1308
1557
|
try {
|
|
1309
1558
|
for (var _c = __values(_this.systems), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
1310
1559
|
var system = _d.value;
|
|
1560
|
+
|
|
1311
1561
|
try {
|
|
1312
1562
|
triggerStart(system);
|
|
1313
1563
|
system.update && system.update(e);
|
|
@@ -1326,9 +1576,11 @@ var Game = function (_super) {
|
|
|
1326
1576
|
if (e_11) throw e_11.error;
|
|
1327
1577
|
}
|
|
1328
1578
|
}
|
|
1579
|
+
|
|
1329
1580
|
try {
|
|
1330
1581
|
for (var _e = __values(_this.systems), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
1331
1582
|
var system = _f.value;
|
|
1583
|
+
|
|
1332
1584
|
try {
|
|
1333
1585
|
system.lateUpdate && system.lateUpdate(e);
|
|
1334
1586
|
} catch (e) {
|
|
@@ -1348,12 +1600,16 @@ var Game = function (_super) {
|
|
|
1348
1600
|
}
|
|
1349
1601
|
});
|
|
1350
1602
|
};
|
|
1603
|
+
|
|
1351
1604
|
Game.prototype.triggerResume = function () {
|
|
1352
1605
|
var e_13, _a;
|
|
1606
|
+
|
|
1353
1607
|
gameObjectResume(this.gameObjects);
|
|
1608
|
+
|
|
1354
1609
|
try {
|
|
1355
1610
|
for (var _b = __values(this.systems), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1356
1611
|
var system = _c.value;
|
|
1612
|
+
|
|
1357
1613
|
try {
|
|
1358
1614
|
system.onResume && system.onResume();
|
|
1359
1615
|
} catch (e) {
|
|
@@ -1372,12 +1628,16 @@ var Game = function (_super) {
|
|
|
1372
1628
|
}
|
|
1373
1629
|
}
|
|
1374
1630
|
};
|
|
1631
|
+
|
|
1375
1632
|
Game.prototype.triggerPause = function () {
|
|
1376
1633
|
var e_14, _a;
|
|
1634
|
+
|
|
1377
1635
|
gameObjectPause(this.gameObjects);
|
|
1636
|
+
|
|
1378
1637
|
try {
|
|
1379
1638
|
for (var _b = __values(this.systems), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1380
1639
|
var system = _c.value;
|
|
1640
|
+
|
|
1381
1641
|
try {
|
|
1382
1642
|
system.onPause && system.onPause();
|
|
1383
1643
|
} catch (e) {
|
|
@@ -1396,8 +1656,10 @@ var Game = function (_super) {
|
|
|
1396
1656
|
}
|
|
1397
1657
|
}
|
|
1398
1658
|
};
|
|
1659
|
+
|
|
1399
1660
|
Game.prototype.destroySystems = function () {
|
|
1400
1661
|
var e_15, _a;
|
|
1662
|
+
|
|
1401
1663
|
try {
|
|
1402
1664
|
for (var _b = __values(__spread(this.systems)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1403
1665
|
var system = _c.value;
|
|
@@ -1414,8 +1676,10 @@ var Game = function (_super) {
|
|
|
1414
1676
|
if (e_15) throw e_15.error;
|
|
1415
1677
|
}
|
|
1416
1678
|
}
|
|
1679
|
+
|
|
1417
1680
|
this.systems.length = 0;
|
|
1418
1681
|
};
|
|
1682
|
+
|
|
1419
1683
|
Game.prototype.destroy = function () {
|
|
1420
1684
|
this.removeAllListeners();
|
|
1421
1685
|
this.pause();
|
|
@@ -1426,42 +1690,53 @@ var Game = function (_super) {
|
|
|
1426
1690
|
this.canvas = null;
|
|
1427
1691
|
this.multiScenes = null;
|
|
1428
1692
|
};
|
|
1693
|
+
|
|
1429
1694
|
Game.prototype.loadScene = function (_a) {
|
|
1430
1695
|
var scene = _a.scene,
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1696
|
+
_b = _a.mode,
|
|
1697
|
+
mode = _b === void 0 ? LOAD_SCENE_MODE.SINGLE : _b,
|
|
1698
|
+
_c = _a.params,
|
|
1699
|
+
params = _c === void 0 ? {} : _c;
|
|
1700
|
+
|
|
1435
1701
|
if (!scene) {
|
|
1436
1702
|
return;
|
|
1437
1703
|
}
|
|
1704
|
+
|
|
1438
1705
|
switch (mode) {
|
|
1439
1706
|
case LOAD_SCENE_MODE.SINGLE:
|
|
1440
1707
|
this.scene = scene;
|
|
1441
1708
|
break;
|
|
1709
|
+
|
|
1442
1710
|
case LOAD_SCENE_MODE.MULTI_CANVAS:
|
|
1443
1711
|
this.multiScenes.push(scene);
|
|
1444
1712
|
break;
|
|
1445
1713
|
}
|
|
1714
|
+
|
|
1446
1715
|
this.emit('sceneChanged', {
|
|
1447
1716
|
scene: scene,
|
|
1448
1717
|
mode: mode,
|
|
1449
1718
|
params: params
|
|
1450
1719
|
});
|
|
1451
1720
|
};
|
|
1721
|
+
|
|
1452
1722
|
return Game;
|
|
1453
1723
|
}(EventEmitter);
|
|
1724
|
+
|
|
1454
1725
|
var Game$1 = Game;
|
|
1726
|
+
|
|
1455
1727
|
function IDEProp(target, propertyKey) {
|
|
1456
1728
|
if (!target.constructor.IDEProps) {
|
|
1457
1729
|
target.constructor.IDEProps = [];
|
|
1458
1730
|
}
|
|
1731
|
+
|
|
1459
1732
|
target.constructor.IDEProps.push(propertyKey);
|
|
1460
1733
|
}
|
|
1734
|
+
|
|
1461
1735
|
function componentObserver(observerInfo) {
|
|
1462
1736
|
if (observerInfo === void 0) {
|
|
1463
1737
|
observerInfo = {};
|
|
1464
1738
|
}
|
|
1739
|
+
|
|
1465
1740
|
return function (constructor) {
|
|
1466
1741
|
if (!constructor.observerInfo) {
|
|
1467
1742
|
for (var key in observerInfo) {
|
|
@@ -1469,7 +1744,9 @@ function componentObserver(observerInfo) {
|
|
|
1469
1744
|
if (typeof observerInfo[key][index] === 'string') {
|
|
1470
1745
|
observerInfo[key][index] = [observerInfo[key][index]];
|
|
1471
1746
|
}
|
|
1747
|
+
|
|
1472
1748
|
var observerProp = void 0;
|
|
1749
|
+
|
|
1473
1750
|
if (Array.isArray(observerInfo[key][index])) {
|
|
1474
1751
|
observerProp = {
|
|
1475
1752
|
prop: observerInfo[key][index],
|
|
@@ -1477,12 +1754,15 @@ function componentObserver(observerInfo) {
|
|
|
1477
1754
|
};
|
|
1478
1755
|
observerInfo[key][index] = observerProp;
|
|
1479
1756
|
}
|
|
1757
|
+
|
|
1480
1758
|
observerProp = observerInfo[key][index];
|
|
1759
|
+
|
|
1481
1760
|
if (typeof observerProp.prop === 'string') {
|
|
1482
1761
|
observerProp.prop = [observerProp.prop];
|
|
1483
1762
|
}
|
|
1484
1763
|
}
|
|
1485
1764
|
}
|
|
1765
|
+
|
|
1486
1766
|
constructor.observerInfo = observerInfo;
|
|
1487
1767
|
}
|
|
1488
1768
|
};
|
|
@@ -1493,6 +1773,7 @@ var SignalBindingImpl = function () {
|
|
|
1493
1773
|
if (once === void 0) {
|
|
1494
1774
|
once = false;
|
|
1495
1775
|
}
|
|
1776
|
+
|
|
1496
1777
|
this.next = null;
|
|
1497
1778
|
this.prev = null;
|
|
1498
1779
|
this.owner = null;
|
|
@@ -1500,71 +1781,92 @@ var SignalBindingImpl = function () {
|
|
|
1500
1781
|
this.once = once;
|
|
1501
1782
|
this.thisArg = thisArg;
|
|
1502
1783
|
}
|
|
1784
|
+
|
|
1503
1785
|
SignalBindingImpl.prototype.detach = function () {
|
|
1504
1786
|
if (this.owner === null) return false;
|
|
1505
1787
|
this.owner.detach(this);
|
|
1506
1788
|
return true;
|
|
1507
1789
|
};
|
|
1790
|
+
|
|
1508
1791
|
SignalBindingImpl.prototype.dispose = function () {
|
|
1509
1792
|
this.detach();
|
|
1510
1793
|
};
|
|
1794
|
+
|
|
1511
1795
|
return SignalBindingImpl;
|
|
1512
1796
|
}();
|
|
1797
|
+
|
|
1513
1798
|
var Signal = function () {
|
|
1514
1799
|
function Signal() {
|
|
1515
1800
|
this._head = null;
|
|
1516
1801
|
this._tail = null;
|
|
1517
1802
|
this._filter = null;
|
|
1518
1803
|
}
|
|
1804
|
+
|
|
1519
1805
|
Signal.prototype.handlers = function () {
|
|
1520
1806
|
var node = this._head;
|
|
1521
1807
|
var handlers = [];
|
|
1808
|
+
|
|
1522
1809
|
while (node) {
|
|
1523
1810
|
handlers.push(node);
|
|
1524
1811
|
node = node.next;
|
|
1525
1812
|
}
|
|
1813
|
+
|
|
1526
1814
|
return handlers;
|
|
1527
1815
|
};
|
|
1816
|
+
|
|
1528
1817
|
Signal.prototype.hasAny = function () {
|
|
1529
1818
|
return !!this._head;
|
|
1530
1819
|
};
|
|
1820
|
+
|
|
1531
1821
|
Signal.prototype.has = function (node) {
|
|
1532
1822
|
return node.owner === this;
|
|
1533
1823
|
};
|
|
1824
|
+
|
|
1534
1825
|
Signal.prototype.dispatch = function () {
|
|
1535
1826
|
var args = [];
|
|
1827
|
+
|
|
1536
1828
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1537
1829
|
args[_i] = arguments[_i];
|
|
1538
1830
|
}
|
|
1831
|
+
|
|
1539
1832
|
var node = this._head;
|
|
1540
1833
|
if (!node) return false;
|
|
1541
1834
|
if (this._filter && !this._filter.apply(this, args)) return false;
|
|
1835
|
+
|
|
1542
1836
|
while (node) {
|
|
1543
1837
|
if (node.once) this.detach(node);
|
|
1544
1838
|
node.fn.apply(node.thisArg, args);
|
|
1545
1839
|
node = node.next;
|
|
1546
1840
|
}
|
|
1841
|
+
|
|
1547
1842
|
return true;
|
|
1548
1843
|
};
|
|
1844
|
+
|
|
1549
1845
|
Signal.prototype.add = function (fn, thisArg) {
|
|
1550
1846
|
if (thisArg === void 0) {
|
|
1551
1847
|
thisArg = null;
|
|
1552
1848
|
}
|
|
1849
|
+
|
|
1553
1850
|
return this._addSignalBinding(new SignalBindingImpl(fn, false, thisArg));
|
|
1554
1851
|
};
|
|
1852
|
+
|
|
1555
1853
|
Signal.prototype.once = function (fn, thisArg) {
|
|
1556
1854
|
if (thisArg === void 0) {
|
|
1557
1855
|
thisArg = null;
|
|
1558
1856
|
}
|
|
1857
|
+
|
|
1559
1858
|
return this._addSignalBinding(new SignalBindingImpl(fn, true, thisArg));
|
|
1560
1859
|
};
|
|
1860
|
+
|
|
1561
1861
|
Signal.prototype.detach = function (node_) {
|
|
1562
1862
|
var node = node_;
|
|
1563
1863
|
if (node.owner !== this) return this;
|
|
1564
1864
|
if (node.prev) node.prev.next = node.next;
|
|
1565
1865
|
if (node.next) node.next.prev = node.prev;
|
|
1866
|
+
|
|
1566
1867
|
if (node === this._head) {
|
|
1567
1868
|
this._head = node.next;
|
|
1869
|
+
|
|
1568
1870
|
if (node.next === null) {
|
|
1569
1871
|
this._tail = null;
|
|
1570
1872
|
}
|
|
@@ -1572,43 +1874,58 @@ var Signal = function () {
|
|
|
1572
1874
|
this._tail = node.prev;
|
|
1573
1875
|
if (this._tail) this._tail.next = null;
|
|
1574
1876
|
}
|
|
1877
|
+
|
|
1575
1878
|
node.owner = null;
|
|
1576
1879
|
return this;
|
|
1577
1880
|
};
|
|
1881
|
+
|
|
1578
1882
|
Signal.prototype.detachAll = function () {
|
|
1579
1883
|
var node = this._head;
|
|
1580
1884
|
if (!node) return this;
|
|
1581
1885
|
this._head = null;
|
|
1582
1886
|
this._tail = null;
|
|
1887
|
+
|
|
1583
1888
|
while (node) {
|
|
1584
1889
|
node.owner = null;
|
|
1585
1890
|
node = node.next;
|
|
1586
1891
|
}
|
|
1892
|
+
|
|
1587
1893
|
return this;
|
|
1588
1894
|
};
|
|
1895
|
+
|
|
1589
1896
|
Signal.prototype.filter = function (filter) {
|
|
1590
1897
|
this._filter = filter;
|
|
1591
1898
|
};
|
|
1899
|
+
|
|
1592
1900
|
Signal.prototype.proxy = function () {
|
|
1593
1901
|
var _this = this;
|
|
1902
|
+
|
|
1594
1903
|
var signals = [];
|
|
1904
|
+
|
|
1595
1905
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1596
1906
|
signals[_i] = arguments[_i];
|
|
1597
1907
|
}
|
|
1908
|
+
|
|
1598
1909
|
var fn = function fn() {
|
|
1599
1910
|
var args = [];
|
|
1911
|
+
|
|
1600
1912
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1601
1913
|
args[_i] = arguments[_i];
|
|
1602
1914
|
}
|
|
1915
|
+
|
|
1603
1916
|
return _this.dispatch.apply(_this, args);
|
|
1604
1917
|
};
|
|
1918
|
+
|
|
1605
1919
|
for (var i = 0; i < signals.length; ++i) {
|
|
1606
1920
|
signals[i].add(fn);
|
|
1607
1921
|
}
|
|
1922
|
+
|
|
1608
1923
|
return this;
|
|
1609
1924
|
};
|
|
1925
|
+
|
|
1610
1926
|
Signal.prototype._addSignalBinding = function (node_) {
|
|
1611
1927
|
var node = node_;
|
|
1928
|
+
|
|
1612
1929
|
if (!this._head) {
|
|
1613
1930
|
this._head = node;
|
|
1614
1931
|
this._tail = node;
|
|
@@ -1617,15 +1934,19 @@ var Signal = function () {
|
|
|
1617
1934
|
node.prev = this._tail;
|
|
1618
1935
|
this._tail = node;
|
|
1619
1936
|
}
|
|
1937
|
+
|
|
1620
1938
|
node.owner = this;
|
|
1621
1939
|
return node;
|
|
1622
1940
|
};
|
|
1941
|
+
|
|
1623
1942
|
return Signal;
|
|
1624
1943
|
}();
|
|
1944
|
+
|
|
1625
1945
|
var src = function src(str, opts) {
|
|
1626
1946
|
if (opts === void 0) {
|
|
1627
1947
|
opts = {};
|
|
1628
1948
|
}
|
|
1949
|
+
|
|
1629
1950
|
if (!str) return undefined;
|
|
1630
1951
|
var o = {
|
|
1631
1952
|
key: ['source', 'protocol', 'authority', 'userInfo', 'user', 'password', 'host', 'port', 'relative', 'path', 'directory', 'file', 'query', 'anchor'],
|
|
@@ -1641,16 +1962,20 @@ var src = function src(str, opts) {
|
|
|
1641
1962
|
var m = o.parser[opts.strictMode ? 'strict' : 'loose'].exec(str);
|
|
1642
1963
|
var uri = {};
|
|
1643
1964
|
var i = 14;
|
|
1965
|
+
|
|
1644
1966
|
while (i--) {
|
|
1645
1967
|
uri[o.key[i]] = m[i] || '';
|
|
1646
1968
|
}
|
|
1969
|
+
|
|
1647
1970
|
uri[o.q.name] = {};
|
|
1648
1971
|
uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) {
|
|
1649
1972
|
if ($1) uri[o.q.name][$1] = $2;
|
|
1650
1973
|
});
|
|
1651
1974
|
return uri;
|
|
1652
1975
|
};
|
|
1976
|
+
|
|
1653
1977
|
var parseUri = src;
|
|
1978
|
+
|
|
1654
1979
|
var AbstractLoadStrategy = function () {
|
|
1655
1980
|
function AbstractLoadStrategy(config) {
|
|
1656
1981
|
this.config = config;
|
|
@@ -1658,6 +1983,7 @@ var AbstractLoadStrategy = function () {
|
|
|
1658
1983
|
this.onComplete = new Signal();
|
|
1659
1984
|
this.onProgress = new Signal();
|
|
1660
1985
|
}
|
|
1986
|
+
|
|
1661
1987
|
return AbstractLoadStrategy;
|
|
1662
1988
|
}();
|
|
1663
1989
|
|
|
@@ -1671,29 +1997,38 @@ var _extendStatics = function extendStatics(d, b) {
|
|
|
1671
1997
|
if (b.hasOwnProperty(p)) d[p] = b[p];
|
|
1672
1998
|
}
|
|
1673
1999
|
};
|
|
2000
|
+
|
|
1674
2001
|
return _extendStatics(d, b);
|
|
1675
2002
|
};
|
|
2003
|
+
|
|
1676
2004
|
function __extends(d, b) {
|
|
1677
2005
|
_extendStatics(d, b);
|
|
2006
|
+
|
|
1678
2007
|
function __() {
|
|
1679
2008
|
this.constructor = d;
|
|
1680
2009
|
}
|
|
2010
|
+
|
|
1681
2011
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
1682
2012
|
}
|
|
2013
|
+
|
|
1683
2014
|
function __spreadArrays() {
|
|
1684
2015
|
for (var s = 0, i = 0, il = arguments.length; i < il; i++) {
|
|
1685
2016
|
s += arguments[i].length;
|
|
1686
2017
|
}
|
|
2018
|
+
|
|
1687
2019
|
for (var r = Array(s), k = 0, i = 0; i < il; i++) {
|
|
1688
2020
|
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) {
|
|
1689
2021
|
r[k] = a[j];
|
|
1690
2022
|
}
|
|
1691
2023
|
}
|
|
2024
|
+
|
|
1692
2025
|
return r;
|
|
1693
2026
|
}
|
|
2027
|
+
|
|
1694
2028
|
function getExtension(url) {
|
|
1695
2029
|
var isDataUrl = url.indexOf('data:') === 0;
|
|
1696
2030
|
var ext = '';
|
|
2031
|
+
|
|
1697
2032
|
if (isDataUrl) {
|
|
1698
2033
|
var slashIndex = url.indexOf('/');
|
|
1699
2034
|
ext = url.substring(slashIndex + 1, url.indexOf(';', slashIndex));
|
|
@@ -1704,12 +2039,16 @@ function getExtension(url) {
|
|
|
1704
2039
|
url = url.substring(0, index);
|
|
1705
2040
|
ext = url.substring(url.lastIndexOf('.') + 1);
|
|
1706
2041
|
}
|
|
2042
|
+
|
|
1707
2043
|
return ext.toLowerCase();
|
|
1708
2044
|
}
|
|
2045
|
+
|
|
1709
2046
|
function assertNever(x) {
|
|
1710
2047
|
throw new Error('Unexpected value. Should have been never.');
|
|
1711
2048
|
}
|
|
2049
|
+
|
|
1712
2050
|
var ResourceType;
|
|
2051
|
+
|
|
1713
2052
|
(function (ResourceType) {
|
|
1714
2053
|
ResourceType[ResourceType["Unknown"] = 0] = "Unknown";
|
|
1715
2054
|
ResourceType[ResourceType["Buffer"] = 1] = "Buffer";
|
|
@@ -1721,16 +2060,21 @@ var ResourceType;
|
|
|
1721
2060
|
ResourceType[ResourceType["Video"] = 7] = "Video";
|
|
1722
2061
|
ResourceType[ResourceType["Text"] = 8] = "Text";
|
|
1723
2062
|
})(ResourceType || (ResourceType = {}));
|
|
2063
|
+
|
|
1724
2064
|
var ResourceState;
|
|
2065
|
+
|
|
1725
2066
|
(function (ResourceState) {
|
|
1726
2067
|
ResourceState[ResourceState["NotStarted"] = 0] = "NotStarted";
|
|
1727
2068
|
ResourceState[ResourceState["Loading"] = 1] = "Loading";
|
|
1728
2069
|
ResourceState[ResourceState["Complete"] = 2] = "Complete";
|
|
1729
2070
|
})(ResourceState || (ResourceState = {}));
|
|
2071
|
+
|
|
1730
2072
|
var MediaElementLoadStrategy = function (_super) {
|
|
1731
2073
|
__extends(MediaElementLoadStrategy, _super);
|
|
2074
|
+
|
|
1732
2075
|
function MediaElementLoadStrategy(config, elementType) {
|
|
1733
2076
|
var _this = _super.call(this, config) || this;
|
|
2077
|
+
|
|
1734
2078
|
_this.elementType = elementType;
|
|
1735
2079
|
_this._boundOnLoad = _this._onLoad.bind(_this);
|
|
1736
2080
|
_this._boundOnError = _this._onError.bind(_this);
|
|
@@ -1739,10 +2083,12 @@ var MediaElementLoadStrategy = function (_super) {
|
|
|
1739
2083
|
_this._elementTimer = 0;
|
|
1740
2084
|
return _this;
|
|
1741
2085
|
}
|
|
2086
|
+
|
|
1742
2087
|
MediaElementLoadStrategy.prototype.load = function () {
|
|
1743
2088
|
var config = this.config;
|
|
1744
2089
|
if (config.crossOrigin) this._element.crossOrigin = config.crossOrigin;
|
|
1745
2090
|
var urls = config.sourceSet || [config.url];
|
|
2091
|
+
|
|
1746
2092
|
if (navigator.isCocoonJS) {
|
|
1747
2093
|
this._element.src = urls[0];
|
|
1748
2094
|
} else {
|
|
@@ -1753,73 +2099,106 @@ var MediaElementLoadStrategy = function (_super) {
|
|
|
1753
2099
|
var source = documentAlias.createElement('source');
|
|
1754
2100
|
source.src = url;
|
|
1755
2101
|
source.type = mimeType;
|
|
2102
|
+
|
|
1756
2103
|
this._element.appendChild(source);
|
|
1757
2104
|
}
|
|
1758
2105
|
}
|
|
2106
|
+
|
|
1759
2107
|
this._element.addEventListener('load', this._boundOnLoad, false);
|
|
2108
|
+
|
|
1760
2109
|
this._element.addEventListener('canplaythrough', this._boundOnLoad, false);
|
|
2110
|
+
|
|
1761
2111
|
this._element.addEventListener('error', this._boundOnError, false);
|
|
2112
|
+
|
|
1762
2113
|
this._element.load();
|
|
2114
|
+
|
|
1763
2115
|
if (config.timeout) this._elementTimer = windowAlias.setTimeout(this._boundOnTimeout, config.timeout);
|
|
1764
2116
|
};
|
|
2117
|
+
|
|
1765
2118
|
MediaElementLoadStrategy.prototype.abort = function () {
|
|
1766
2119
|
this._clearEvents();
|
|
2120
|
+
|
|
1767
2121
|
while (this._element.firstChild) {
|
|
1768
2122
|
this._element.removeChild(this._element.firstChild);
|
|
1769
2123
|
}
|
|
2124
|
+
|
|
1770
2125
|
this._error(this.elementType + " load aborted by the user.");
|
|
1771
2126
|
};
|
|
2127
|
+
|
|
1772
2128
|
MediaElementLoadStrategy.prototype._createElement = function () {
|
|
1773
2129
|
if (this.config.loadElement) return this.config.loadElement;else return documentAlias.createElement(this.elementType);
|
|
1774
2130
|
};
|
|
2131
|
+
|
|
1775
2132
|
MediaElementLoadStrategy.prototype._clearEvents = function () {
|
|
1776
2133
|
clearTimeout(this._elementTimer);
|
|
2134
|
+
|
|
1777
2135
|
this._element.removeEventListener('load', this._boundOnLoad, false);
|
|
2136
|
+
|
|
1778
2137
|
this._element.removeEventListener('canplaythrough', this._boundOnLoad, false);
|
|
2138
|
+
|
|
1779
2139
|
this._element.removeEventListener('error', this._boundOnError, false);
|
|
1780
2140
|
};
|
|
2141
|
+
|
|
1781
2142
|
MediaElementLoadStrategy.prototype._error = function (errMessage) {
|
|
1782
2143
|
this._clearEvents();
|
|
2144
|
+
|
|
1783
2145
|
this.onError.dispatch(errMessage);
|
|
1784
2146
|
};
|
|
2147
|
+
|
|
1785
2148
|
MediaElementLoadStrategy.prototype._complete = function () {
|
|
1786
2149
|
this._clearEvents();
|
|
2150
|
+
|
|
1787
2151
|
var resourceType = ResourceType.Unknown;
|
|
2152
|
+
|
|
1788
2153
|
switch (this.elementType) {
|
|
1789
2154
|
case 'audio':
|
|
1790
2155
|
resourceType = ResourceType.Audio;
|
|
1791
2156
|
break;
|
|
2157
|
+
|
|
1792
2158
|
case 'video':
|
|
1793
2159
|
resourceType = ResourceType.Video;
|
|
1794
2160
|
break;
|
|
2161
|
+
|
|
1795
2162
|
default:
|
|
1796
2163
|
assertNever(this.elementType);
|
|
1797
2164
|
}
|
|
2165
|
+
|
|
1798
2166
|
this.onComplete.dispatch(resourceType, this._element);
|
|
1799
2167
|
};
|
|
2168
|
+
|
|
1800
2169
|
MediaElementLoadStrategy.prototype._onLoad = function () {
|
|
1801
2170
|
this._complete();
|
|
1802
2171
|
};
|
|
2172
|
+
|
|
1803
2173
|
MediaElementLoadStrategy.prototype._onError = function () {
|
|
1804
2174
|
this._error(this.elementType + " failed to load.");
|
|
1805
2175
|
};
|
|
2176
|
+
|
|
1806
2177
|
MediaElementLoadStrategy.prototype._onTimeout = function () {
|
|
1807
2178
|
this._error(this.elementType + " load timed out.");
|
|
1808
2179
|
};
|
|
2180
|
+
|
|
1809
2181
|
return MediaElementLoadStrategy;
|
|
1810
2182
|
}(AbstractLoadStrategy);
|
|
2183
|
+
|
|
1811
2184
|
var AudioLoadStrategy = function (_super) {
|
|
1812
2185
|
__extends(AudioLoadStrategy, _super);
|
|
2186
|
+
|
|
1813
2187
|
function AudioLoadStrategy(config) {
|
|
1814
2188
|
return _super.call(this, config, 'audio') || this;
|
|
1815
2189
|
}
|
|
2190
|
+
|
|
1816
2191
|
return AudioLoadStrategy;
|
|
1817
2192
|
}(MediaElementLoadStrategy);
|
|
2193
|
+
|
|
1818
2194
|
var EMPTY_GIF = 'data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==';
|
|
2195
|
+
|
|
1819
2196
|
var ImageLoadStrategy = function (_super) {
|
|
1820
2197
|
__extends(ImageLoadStrategy, _super);
|
|
2198
|
+
|
|
1821
2199
|
function ImageLoadStrategy() {
|
|
1822
2200
|
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
2201
|
+
|
|
1823
2202
|
_this._boundOnLoad = _this._onLoad.bind(_this);
|
|
1824
2203
|
_this._boundOnError = _this._onError.bind(_this);
|
|
1825
2204
|
_this._boundOnTimeout = _this._onTimeout.bind(_this);
|
|
@@ -1827,55 +2206,79 @@ var ImageLoadStrategy = function (_super) {
|
|
|
1827
2206
|
_this._elementTimer = 0;
|
|
1828
2207
|
return _this;
|
|
1829
2208
|
}
|
|
2209
|
+
|
|
1830
2210
|
ImageLoadStrategy.prototype.load = function () {
|
|
1831
2211
|
var config = this.config;
|
|
1832
2212
|
if (config.crossOrigin) this._element.crossOrigin = config.crossOrigin;
|
|
1833
2213
|
this._element.src = config.url;
|
|
2214
|
+
|
|
1834
2215
|
this._element.addEventListener('load', this._boundOnLoad, false);
|
|
2216
|
+
|
|
1835
2217
|
this._element.addEventListener('error', this._boundOnError, false);
|
|
2218
|
+
|
|
1836
2219
|
if (config.timeout) this._elementTimer = windowAlias.setTimeout(this._boundOnTimeout, config.timeout);
|
|
1837
2220
|
};
|
|
2221
|
+
|
|
1838
2222
|
ImageLoadStrategy.prototype.abort = function () {
|
|
1839
2223
|
this._clearEvents();
|
|
2224
|
+
|
|
1840
2225
|
this._element.src = EMPTY_GIF;
|
|
2226
|
+
|
|
1841
2227
|
this._error('Image load aborted by the user.');
|
|
1842
2228
|
};
|
|
2229
|
+
|
|
1843
2230
|
ImageLoadStrategy.prototype._createElement = function () {
|
|
1844
2231
|
if (this.config.loadElement) return this.config.loadElement;else return documentAlias.createElement('img');
|
|
1845
2232
|
};
|
|
2233
|
+
|
|
1846
2234
|
ImageLoadStrategy.prototype._clearEvents = function () {
|
|
1847
2235
|
clearTimeout(this._elementTimer);
|
|
2236
|
+
|
|
1848
2237
|
this._element.removeEventListener('load', this._boundOnLoad, false);
|
|
2238
|
+
|
|
1849
2239
|
this._element.removeEventListener('error', this._boundOnError, false);
|
|
1850
2240
|
};
|
|
2241
|
+
|
|
1851
2242
|
ImageLoadStrategy.prototype._error = function (errMessage) {
|
|
1852
2243
|
this._clearEvents();
|
|
2244
|
+
|
|
1853
2245
|
this.onError.dispatch(errMessage);
|
|
1854
2246
|
};
|
|
2247
|
+
|
|
1855
2248
|
ImageLoadStrategy.prototype._complete = function () {
|
|
1856
2249
|
this._clearEvents();
|
|
2250
|
+
|
|
1857
2251
|
this.onComplete.dispatch(ResourceType.Image, this._element);
|
|
1858
2252
|
};
|
|
2253
|
+
|
|
1859
2254
|
ImageLoadStrategy.prototype._onLoad = function () {
|
|
1860
2255
|
this._complete();
|
|
1861
2256
|
};
|
|
2257
|
+
|
|
1862
2258
|
ImageLoadStrategy.prototype._onError = function () {
|
|
1863
2259
|
this._error('Image failed to load.');
|
|
1864
2260
|
};
|
|
2261
|
+
|
|
1865
2262
|
ImageLoadStrategy.prototype._onTimeout = function () {
|
|
1866
2263
|
this._error('Image load timed out.');
|
|
1867
2264
|
};
|
|
2265
|
+
|
|
1868
2266
|
return ImageLoadStrategy;
|
|
1869
2267
|
}(AbstractLoadStrategy);
|
|
2268
|
+
|
|
1870
2269
|
var VideoLoadStrategy = function (_super) {
|
|
1871
2270
|
__extends(VideoLoadStrategy, _super);
|
|
2271
|
+
|
|
1872
2272
|
function VideoLoadStrategy(config) {
|
|
1873
2273
|
return _super.call(this, config, 'video') || this;
|
|
1874
2274
|
}
|
|
2275
|
+
|
|
1875
2276
|
return VideoLoadStrategy;
|
|
1876
2277
|
}(MediaElementLoadStrategy);
|
|
2278
|
+
|
|
1877
2279
|
var useXdr = !!(windowAlias.XDomainRequest && !('withCredentials' in new XMLHttpRequestAlias()));
|
|
1878
2280
|
var XhrResponseType;
|
|
2281
|
+
|
|
1879
2282
|
(function (XhrResponseType) {
|
|
1880
2283
|
XhrResponseType["Default"] = "text";
|
|
1881
2284
|
XhrResponseType["Buffer"] = "arraybuffer";
|
|
@@ -1884,13 +2287,17 @@ var XhrResponseType;
|
|
|
1884
2287
|
XhrResponseType["Json"] = "json";
|
|
1885
2288
|
XhrResponseType["Text"] = "text";
|
|
1886
2289
|
})(XhrResponseType || (XhrResponseType = {}));
|
|
2290
|
+
|
|
1887
2291
|
function reqType(xhr) {
|
|
1888
2292
|
return xhr.toString().replace('object ', '');
|
|
1889
2293
|
}
|
|
2294
|
+
|
|
1890
2295
|
var XhrLoadStrategy = function (_super) {
|
|
1891
2296
|
__extends(XhrLoadStrategy, _super);
|
|
2297
|
+
|
|
1892
2298
|
function XhrLoadStrategy() {
|
|
1893
2299
|
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
2300
|
+
|
|
1894
2301
|
_this._boundOnLoad = _this._onLoad.bind(_this);
|
|
1895
2302
|
_this._boundOnAbort = _this._onAbort.bind(_this);
|
|
1896
2303
|
_this._boundOnError = _this._onError.bind(_this);
|
|
@@ -1900,14 +2307,18 @@ var XhrLoadStrategy = function (_super) {
|
|
|
1900
2307
|
_this._xhrType = XhrResponseType.Default;
|
|
1901
2308
|
return _this;
|
|
1902
2309
|
}
|
|
2310
|
+
|
|
1903
2311
|
XhrLoadStrategy.prototype.load = function () {
|
|
1904
2312
|
var config = this.config;
|
|
1905
2313
|
var ext = getExtension(config.url);
|
|
2314
|
+
|
|
1906
2315
|
if (typeof config.xhrType !== 'string') {
|
|
1907
2316
|
config.xhrType = this._determineXhrType(ext);
|
|
1908
2317
|
}
|
|
2318
|
+
|
|
1909
2319
|
var xhr = this._xhr;
|
|
1910
2320
|
this._xhrType = config.xhrType || XhrResponseType.Default;
|
|
2321
|
+
|
|
1911
2322
|
if (useXdr) {
|
|
1912
2323
|
xhr.timeout = config.timeout || 5000;
|
|
1913
2324
|
xhr.onload = this._boundOnLoad;
|
|
@@ -1930,21 +2341,27 @@ var XhrLoadStrategy = function (_super) {
|
|
|
1930
2341
|
xhr.send();
|
|
1931
2342
|
}
|
|
1932
2343
|
};
|
|
2344
|
+
|
|
1933
2345
|
XhrLoadStrategy.prototype.abort = function () {
|
|
1934
2346
|
if (useXdr) {
|
|
1935
2347
|
this._clearEvents();
|
|
2348
|
+
|
|
1936
2349
|
this._xhr.abort();
|
|
2350
|
+
|
|
1937
2351
|
this._onAbort();
|
|
1938
2352
|
} else {
|
|
1939
2353
|
this._xhr.abort();
|
|
1940
2354
|
}
|
|
1941
2355
|
};
|
|
2356
|
+
|
|
1942
2357
|
XhrLoadStrategy.prototype._createRequest = function () {
|
|
1943
2358
|
if (useXdr) return new windowAlias.XDomainRequest();else return new XMLHttpRequestAlias();
|
|
1944
2359
|
};
|
|
2360
|
+
|
|
1945
2361
|
XhrLoadStrategy.prototype._determineXhrType = function (ext) {
|
|
1946
2362
|
return XhrLoadStrategy._xhrTypeMap[ext] || XhrResponseType.Default;
|
|
1947
2363
|
};
|
|
2364
|
+
|
|
1948
2365
|
XhrLoadStrategy.prototype._clearEvents = function () {
|
|
1949
2366
|
if (useXdr) {
|
|
1950
2367
|
this._xhr.onload = null;
|
|
@@ -1953,103 +2370,142 @@ var XhrLoadStrategy = function (_super) {
|
|
|
1953
2370
|
this._xhr.onprogress = null;
|
|
1954
2371
|
} else {
|
|
1955
2372
|
this._xhr.removeEventListener('load', this._boundOnLoad, false);
|
|
2373
|
+
|
|
1956
2374
|
this._xhr.removeEventListener('abort', this._boundOnAbort, false);
|
|
2375
|
+
|
|
1957
2376
|
this._xhr.removeEventListener('error', this._boundOnError, false);
|
|
2377
|
+
|
|
1958
2378
|
this._xhr.removeEventListener('timeout', this._boundOnTimeout, false);
|
|
2379
|
+
|
|
1959
2380
|
this._xhr.removeEventListener('progress', this._boundOnProgress, false);
|
|
1960
2381
|
}
|
|
1961
2382
|
};
|
|
2383
|
+
|
|
1962
2384
|
XhrLoadStrategy.prototype._error = function (errMessage) {
|
|
1963
2385
|
this._clearEvents();
|
|
2386
|
+
|
|
1964
2387
|
this.onError.dispatch(errMessage);
|
|
1965
2388
|
};
|
|
2389
|
+
|
|
1966
2390
|
XhrLoadStrategy.prototype._complete = function (type, data) {
|
|
1967
2391
|
this._clearEvents();
|
|
2392
|
+
|
|
1968
2393
|
this.onComplete.dispatch(type, data);
|
|
1969
2394
|
};
|
|
2395
|
+
|
|
1970
2396
|
XhrLoadStrategy.prototype._onLoad = function () {
|
|
1971
2397
|
var xhr = this._xhr;
|
|
1972
2398
|
var text = '';
|
|
1973
2399
|
var status = typeof xhr.status === 'undefined' ? 200 : xhr.status;
|
|
2400
|
+
|
|
1974
2401
|
if (typeof xhr.responseType === 'undefined' || xhr.responseType === '' || xhr.responseType === 'text') {
|
|
1975
2402
|
text = xhr.responseText;
|
|
1976
2403
|
}
|
|
2404
|
+
|
|
1977
2405
|
if (status === 0 && (text.length > 0 || xhr.responseType === XhrResponseType.Buffer)) {
|
|
1978
2406
|
status = 200;
|
|
1979
2407
|
} else if (status === 1223) {
|
|
1980
2408
|
status = 204;
|
|
1981
2409
|
}
|
|
2410
|
+
|
|
1982
2411
|
var flattenedStatus = Math.floor(status / 100) * 100;
|
|
2412
|
+
|
|
1983
2413
|
if (flattenedStatus !== 200) {
|
|
1984
2414
|
this._error("[" + xhr.status + "] " + xhr.statusText + ": " + xhr.responseURL);
|
|
2415
|
+
|
|
1985
2416
|
return;
|
|
1986
2417
|
}
|
|
2418
|
+
|
|
1987
2419
|
switch (this._xhrType) {
|
|
1988
2420
|
case XhrResponseType.Buffer:
|
|
1989
2421
|
this._complete(ResourceType.Buffer, xhr.response);
|
|
2422
|
+
|
|
1990
2423
|
break;
|
|
2424
|
+
|
|
1991
2425
|
case XhrResponseType.Blob:
|
|
1992
2426
|
this._complete(ResourceType.Blob, xhr.response);
|
|
2427
|
+
|
|
1993
2428
|
break;
|
|
2429
|
+
|
|
1994
2430
|
case XhrResponseType.Document:
|
|
1995
2431
|
this._parseDocument(text);
|
|
2432
|
+
|
|
1996
2433
|
break;
|
|
2434
|
+
|
|
1997
2435
|
case XhrResponseType.Json:
|
|
1998
2436
|
this._parseJson(text);
|
|
2437
|
+
|
|
1999
2438
|
break;
|
|
2439
|
+
|
|
2000
2440
|
case XhrResponseType.Default:
|
|
2001
2441
|
case XhrResponseType.Text:
|
|
2002
2442
|
this._complete(ResourceType.Text, text);
|
|
2443
|
+
|
|
2003
2444
|
break;
|
|
2445
|
+
|
|
2004
2446
|
default:
|
|
2005
2447
|
assertNever(this._xhrType);
|
|
2006
2448
|
}
|
|
2007
2449
|
};
|
|
2450
|
+
|
|
2008
2451
|
XhrLoadStrategy.prototype._parseDocument = function (text) {
|
|
2009
2452
|
try {
|
|
2010
2453
|
if (windowAlias.DOMParser) {
|
|
2011
2454
|
var parser = new DOMParser();
|
|
2012
2455
|
var data = parser.parseFromString(text, 'text/xml');
|
|
2456
|
+
|
|
2013
2457
|
this._complete(ResourceType.Xml, data);
|
|
2014
2458
|
} else {
|
|
2015
2459
|
var div = documentAlias.createElement('div');
|
|
2016
2460
|
div.innerHTML = text;
|
|
2461
|
+
|
|
2017
2462
|
this._complete(ResourceType.Xml, div);
|
|
2018
2463
|
}
|
|
2019
2464
|
} catch (e) {
|
|
2020
2465
|
this._error("Error trying to parse loaded xml: " + e);
|
|
2021
2466
|
}
|
|
2022
2467
|
};
|
|
2468
|
+
|
|
2023
2469
|
XhrLoadStrategy.prototype._parseJson = function (text) {
|
|
2024
2470
|
try {
|
|
2025
2471
|
var data = JSON.parse(text);
|
|
2472
|
+
|
|
2026
2473
|
this._complete(ResourceType.Json, data);
|
|
2027
2474
|
} catch (e) {
|
|
2028
2475
|
this._error("Error trying to parse loaded json: " + e);
|
|
2029
2476
|
}
|
|
2030
2477
|
};
|
|
2478
|
+
|
|
2031
2479
|
XhrLoadStrategy.prototype._onAbort = function () {
|
|
2032
2480
|
var xhr = this._xhr;
|
|
2481
|
+
|
|
2033
2482
|
this._error(reqType(xhr) + " Request was aborted by the user.");
|
|
2034
2483
|
};
|
|
2484
|
+
|
|
2035
2485
|
XhrLoadStrategy.prototype._onError = function () {
|
|
2036
2486
|
var xhr = this._xhr;
|
|
2487
|
+
|
|
2037
2488
|
this._error(reqType(xhr) + " Request failed. Status: " + xhr.status + ", text: \"" + xhr.statusText + "\"");
|
|
2038
2489
|
};
|
|
2490
|
+
|
|
2039
2491
|
XhrLoadStrategy.prototype._onTimeout = function () {
|
|
2040
2492
|
var xhr = this._xhr;
|
|
2493
|
+
|
|
2041
2494
|
this._error(reqType(xhr) + " Request timed out.");
|
|
2042
2495
|
};
|
|
2496
|
+
|
|
2043
2497
|
XhrLoadStrategy.prototype._onProgress = function (event) {
|
|
2044
2498
|
if (event && event.lengthComputable) {
|
|
2045
2499
|
this.onProgress.dispatch(event.loaded / event.total);
|
|
2046
2500
|
}
|
|
2047
2501
|
};
|
|
2502
|
+
|
|
2048
2503
|
XhrLoadStrategy.setExtensionXhrType = function (extname, xhrType) {
|
|
2049
2504
|
if (extname && extname.indexOf('.') === 0) extname = extname.substring(1);
|
|
2050
2505
|
if (!extname) return;
|
|
2051
2506
|
XhrLoadStrategy._xhrTypeMap[extname] = xhrType;
|
|
2052
2507
|
};
|
|
2508
|
+
|
|
2053
2509
|
XhrLoadStrategy.ResponseType = XhrResponseType;
|
|
2054
2510
|
XhrLoadStrategy._xhrTypeMap = {
|
|
2055
2511
|
xhtml: XhrResponseType.Document,
|
|
@@ -2076,24 +2532,29 @@ var XhrLoadStrategy = function (_super) {
|
|
|
2076
2532
|
};
|
|
2077
2533
|
return XhrLoadStrategy;
|
|
2078
2534
|
}(AbstractLoadStrategy);
|
|
2535
|
+
|
|
2079
2536
|
function onlyOnce(func) {
|
|
2080
2537
|
var fn = func;
|
|
2081
2538
|
return function onceWrapper() {
|
|
2082
2539
|
var args = [];
|
|
2540
|
+
|
|
2083
2541
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2084
2542
|
args[_i] = arguments[_i];
|
|
2085
2543
|
}
|
|
2544
|
+
|
|
2086
2545
|
if (fn === null) throw new Error('Callback was already called.');
|
|
2087
2546
|
var callFn = fn;
|
|
2088
2547
|
fn = null;
|
|
2089
2548
|
return callFn.apply(this, args);
|
|
2090
2549
|
};
|
|
2091
2550
|
}
|
|
2551
|
+
|
|
2092
2552
|
var AsyncQueue = function () {
|
|
2093
2553
|
function AsyncQueue(worker, concurrency) {
|
|
2094
2554
|
if (concurrency === void 0) {
|
|
2095
2555
|
concurrency = 1;
|
|
2096
2556
|
}
|
|
2557
|
+
|
|
2097
2558
|
this.worker = worker;
|
|
2098
2559
|
this.concurrency = concurrency;
|
|
2099
2560
|
this.workers = 0;
|
|
@@ -2109,6 +2570,7 @@ var AsyncQueue = function () {
|
|
|
2109
2570
|
if (concurrency === 0) throw new Error('Concurrency must not be zero');
|
|
2110
2571
|
this.buffer = concurrency / 4;
|
|
2111
2572
|
}
|
|
2573
|
+
|
|
2112
2574
|
Object.defineProperty(AsyncQueue.prototype, "started", {
|
|
2113
2575
|
get: function get() {
|
|
2114
2576
|
return this._started;
|
|
@@ -2116,62 +2578,79 @@ var AsyncQueue = function () {
|
|
|
2116
2578
|
enumerable: true,
|
|
2117
2579
|
configurable: true
|
|
2118
2580
|
});
|
|
2581
|
+
|
|
2119
2582
|
AsyncQueue.prototype.reset = function () {
|
|
2120
2583
|
this.onDrain.detachAll();
|
|
2121
2584
|
this.workers = 0;
|
|
2122
2585
|
this._started = false;
|
|
2123
2586
|
this._tasks = [];
|
|
2124
2587
|
};
|
|
2588
|
+
|
|
2125
2589
|
AsyncQueue.prototype.push = function (data, callback) {
|
|
2126
2590
|
this._insert(data, false, callback);
|
|
2127
2591
|
};
|
|
2592
|
+
|
|
2128
2593
|
AsyncQueue.prototype.unshift = function (data, callback) {
|
|
2129
2594
|
this._insert(data, true, callback);
|
|
2130
2595
|
};
|
|
2596
|
+
|
|
2131
2597
|
AsyncQueue.prototype.process = function () {
|
|
2132
2598
|
while (!this.paused && this.workers < this.concurrency && this._tasks.length) {
|
|
2133
2599
|
var task = this._tasks.shift();
|
|
2600
|
+
|
|
2134
2601
|
if (this._tasks.length === 0) this.onEmpty.dispatch();
|
|
2135
2602
|
this.workers += 1;
|
|
2136
2603
|
if (this.workers === this.concurrency) this.onSaturated.dispatch();
|
|
2137
2604
|
this.worker(task.data, onlyOnce(this._next(task)));
|
|
2138
2605
|
}
|
|
2139
2606
|
};
|
|
2607
|
+
|
|
2140
2608
|
AsyncQueue.prototype.length = function () {
|
|
2141
2609
|
return this._tasks.length;
|
|
2142
2610
|
};
|
|
2611
|
+
|
|
2143
2612
|
AsyncQueue.prototype.running = function () {
|
|
2144
2613
|
return this.workers;
|
|
2145
2614
|
};
|
|
2615
|
+
|
|
2146
2616
|
AsyncQueue.prototype.idle = function () {
|
|
2147
2617
|
return this._tasks.length + this.workers === 0;
|
|
2148
2618
|
};
|
|
2619
|
+
|
|
2149
2620
|
AsyncQueue.prototype.pause = function () {
|
|
2150
2621
|
if (this.paused === true) return;
|
|
2151
2622
|
this.paused = true;
|
|
2152
2623
|
};
|
|
2624
|
+
|
|
2153
2625
|
AsyncQueue.prototype.resume = function () {
|
|
2154
2626
|
if (this.paused === false) return;
|
|
2155
2627
|
this.paused = false;
|
|
2628
|
+
|
|
2156
2629
|
for (var w = 1; w <= this.concurrency; w++) {
|
|
2157
2630
|
this.process();
|
|
2158
2631
|
}
|
|
2159
2632
|
};
|
|
2633
|
+
|
|
2160
2634
|
AsyncQueue.prototype.getTask = function (index) {
|
|
2161
2635
|
return this._tasks[index];
|
|
2162
2636
|
};
|
|
2637
|
+
|
|
2163
2638
|
AsyncQueue.prototype._insert = function (data, insertAtFront, callback) {
|
|
2164
2639
|
var _this = this;
|
|
2640
|
+
|
|
2165
2641
|
if (callback != null && typeof callback !== 'function') {
|
|
2166
2642
|
throw new Error('task callback must be a function');
|
|
2167
2643
|
}
|
|
2644
|
+
|
|
2168
2645
|
this._started = true;
|
|
2646
|
+
|
|
2169
2647
|
if (data == null && this.idle()) {
|
|
2170
2648
|
setTimeout(function () {
|
|
2171
2649
|
return _this.onDrain.dispatch();
|
|
2172
2650
|
}, 1);
|
|
2173
2651
|
return;
|
|
2174
2652
|
}
|
|
2653
|
+
|
|
2175
2654
|
var task = {
|
|
2176
2655
|
data: data,
|
|
2177
2656
|
callback: callback
|
|
@@ -2181,23 +2660,30 @@ var AsyncQueue = function () {
|
|
|
2181
2660
|
return _this.process();
|
|
2182
2661
|
}, 1);
|
|
2183
2662
|
};
|
|
2663
|
+
|
|
2184
2664
|
AsyncQueue.prototype._next = function (task) {
|
|
2185
2665
|
var _this = this;
|
|
2666
|
+
|
|
2186
2667
|
return function (err) {
|
|
2187
2668
|
var args = [];
|
|
2669
|
+
|
|
2188
2670
|
for (var _i = 1; _i < arguments.length; _i++) {
|
|
2189
2671
|
args[_i - 1] = arguments[_i];
|
|
2190
2672
|
}
|
|
2673
|
+
|
|
2191
2674
|
_this.workers -= 1;
|
|
2192
2675
|
if (task.callback) task.callback.apply(task, __spreadArrays([err], args));
|
|
2193
2676
|
if (err) _this.onError.dispatch(err, task.data);
|
|
2194
2677
|
if (_this.workers <= _this.concurrency - _this.buffer) _this.onUnsaturated.dispatch();
|
|
2195
2678
|
if (_this.idle()) _this.onDrain.dispatch();
|
|
2679
|
+
|
|
2196
2680
|
_this.process();
|
|
2197
2681
|
};
|
|
2198
2682
|
};
|
|
2683
|
+
|
|
2199
2684
|
return AsyncQueue;
|
|
2200
2685
|
}();
|
|
2686
|
+
|
|
2201
2687
|
var Resource$1 = function () {
|
|
2202
2688
|
function Resource(name, options) {
|
|
2203
2689
|
this.children = [];
|
|
@@ -2209,12 +2695,15 @@ var Resource$1 = function () {
|
|
|
2209
2695
|
this.type = ResourceType.Unknown;
|
|
2210
2696
|
this.error = '';
|
|
2211
2697
|
this.progressChunk = 0;
|
|
2698
|
+
|
|
2212
2699
|
this._dequeue = function () {};
|
|
2700
|
+
|
|
2213
2701
|
this._onCompleteBinding = null;
|
|
2214
2702
|
this._state = ResourceState.NotStarted;
|
|
2215
2703
|
this.name = name;
|
|
2216
2704
|
this.metadata = options.metadata;
|
|
2217
2705
|
if (typeof options.crossOrigin !== 'string') options.crossOrigin = this._determineCrossOrigin(options.url);
|
|
2706
|
+
|
|
2218
2707
|
if (options.strategy && typeof options.strategy !== 'function') {
|
|
2219
2708
|
this._strategy = options.strategy;
|
|
2220
2709
|
this._strategy.config = options;
|
|
@@ -2224,18 +2713,24 @@ var Resource$1 = function () {
|
|
|
2224
2713
|
if (!StrategyCtor) StrategyCtor = Resource._defaultLoadStrategy;
|
|
2225
2714
|
this._strategy = new StrategyCtor(options);
|
|
2226
2715
|
}
|
|
2716
|
+
|
|
2227
2717
|
this._strategy.onError.add(this._error, this);
|
|
2718
|
+
|
|
2228
2719
|
this._strategy.onComplete.add(this._complete, this);
|
|
2720
|
+
|
|
2229
2721
|
this._strategy.onProgress.add(this._progress, this);
|
|
2230
2722
|
}
|
|
2723
|
+
|
|
2231
2724
|
Resource.setDefaultLoadStrategy = function (strategy) {
|
|
2232
2725
|
Resource._defaultLoadStrategy = strategy;
|
|
2233
2726
|
};
|
|
2727
|
+
|
|
2234
2728
|
Resource.setLoadStrategy = function (extname, strategy) {
|
|
2235
2729
|
if (extname && extname.indexOf('.') === 0) extname = extname.substring(1);
|
|
2236
2730
|
if (!extname) return;
|
|
2237
2731
|
Resource._loadStrategyMap[extname] = strategy;
|
|
2238
2732
|
};
|
|
2733
|
+
|
|
2239
2734
|
Object.defineProperty(Resource.prototype, "strategy", {
|
|
2240
2735
|
get: function get() {
|
|
2241
2736
|
return this._strategy;
|
|
@@ -2264,32 +2759,40 @@ var Resource$1 = function () {
|
|
|
2264
2759
|
enumerable: true,
|
|
2265
2760
|
configurable: true
|
|
2266
2761
|
});
|
|
2762
|
+
|
|
2267
2763
|
Resource.prototype.abort = function () {
|
|
2268
2764
|
this._strategy.abort();
|
|
2269
2765
|
};
|
|
2766
|
+
|
|
2270
2767
|
Resource.prototype.load = function () {
|
|
2271
2768
|
this._state = ResourceState.Loading;
|
|
2272
2769
|
this.onStart.dispatch(this);
|
|
2770
|
+
|
|
2273
2771
|
this._strategy.load();
|
|
2274
2772
|
};
|
|
2773
|
+
|
|
2275
2774
|
Resource.prototype._error = function (errMessage) {
|
|
2276
2775
|
this._state = ResourceState.Complete;
|
|
2277
2776
|
this.error = errMessage;
|
|
2278
2777
|
this.onComplete.dispatch(this);
|
|
2279
2778
|
};
|
|
2779
|
+
|
|
2280
2780
|
Resource.prototype._complete = function (type, data) {
|
|
2281
2781
|
this._state = ResourceState.Complete;
|
|
2282
2782
|
this.type = type;
|
|
2283
2783
|
this.data = data;
|
|
2284
2784
|
this.onComplete.dispatch(this);
|
|
2285
2785
|
};
|
|
2786
|
+
|
|
2286
2787
|
Resource.prototype._progress = function (percent) {
|
|
2287
2788
|
this.onProgress.dispatch(this, percent);
|
|
2288
2789
|
};
|
|
2790
|
+
|
|
2289
2791
|
Resource.prototype._determineCrossOrigin = function (url, loc) {
|
|
2290
2792
|
if (loc === void 0) {
|
|
2291
2793
|
loc = windowAlias.location;
|
|
2292
2794
|
}
|
|
2795
|
+
|
|
2293
2796
|
if (url.indexOf('data:') === 0 || url.indexOf('javascript:') === 0) return '';
|
|
2294
2797
|
if (windowAlias.origin !== windowAlias.location.origin) return 'anonymous';
|
|
2295
2798
|
if (!Resource._tempAnchor) Resource._tempAnchor = documentAlias.createElement('a');
|
|
@@ -2302,6 +2805,7 @@ var Resource$1 = function () {
|
|
|
2302
2805
|
if (parsed.host !== loc.hostname || !samePort || protocol !== loc.protocol) return 'anonymous';
|
|
2303
2806
|
return '';
|
|
2304
2807
|
};
|
|
2808
|
+
|
|
2305
2809
|
Resource._tempAnchor = null;
|
|
2306
2810
|
Resource._defaultLoadStrategy = XhrLoadStrategy;
|
|
2307
2811
|
Resource._loadStrategyMap = {
|
|
@@ -2325,32 +2829,40 @@ var Resource$1 = function () {
|
|
|
2325
2829
|
};
|
|
2326
2830
|
return Resource;
|
|
2327
2831
|
}();
|
|
2832
|
+
|
|
2328
2833
|
function eachSeries(array, iterator, callback, deferNext) {
|
|
2329
2834
|
if (deferNext === void 0) {
|
|
2330
2835
|
deferNext = false;
|
|
2331
2836
|
}
|
|
2837
|
+
|
|
2332
2838
|
var i = 0;
|
|
2333
2839
|
var len = array.length;
|
|
2840
|
+
|
|
2334
2841
|
(function next(err) {
|
|
2335
2842
|
if (err || i === len) {
|
|
2336
2843
|
if (callback) callback(err);
|
|
2337
2844
|
return;
|
|
2338
2845
|
}
|
|
2846
|
+
|
|
2339
2847
|
if (deferNext) setTimeout(function () {
|
|
2340
2848
|
return iterator(array[i++], next);
|
|
2341
2849
|
}, 1);else iterator(array[i++], next);
|
|
2342
2850
|
})();
|
|
2343
2851
|
}
|
|
2852
|
+
|
|
2344
2853
|
var MAX_PROGRESS = 100;
|
|
2345
2854
|
var rgxExtractUrlHash = /(#[\w-]+)?$/;
|
|
2855
|
+
|
|
2346
2856
|
var Loader = function () {
|
|
2347
2857
|
function Loader(baseUrl, concurrency) {
|
|
2348
2858
|
if (baseUrl === void 0) {
|
|
2349
2859
|
baseUrl = '';
|
|
2350
2860
|
}
|
|
2861
|
+
|
|
2351
2862
|
if (concurrency === void 0) {
|
|
2352
2863
|
concurrency = 10;
|
|
2353
2864
|
}
|
|
2865
|
+
|
|
2354
2866
|
this.progress = 0;
|
|
2355
2867
|
this.loading = false;
|
|
2356
2868
|
this.defaultQueryString = '';
|
|
@@ -2367,9 +2879,12 @@ var Loader = function () {
|
|
|
2367
2879
|
this._boundLoadResource = this._loadResource.bind(this);
|
|
2368
2880
|
this.baseUrl = baseUrl;
|
|
2369
2881
|
this._queue = new AsyncQueue(this._boundLoadResource, concurrency);
|
|
2882
|
+
|
|
2370
2883
|
this._queue.pause();
|
|
2884
|
+
|
|
2371
2885
|
this._middleware = Loader._defaultMiddleware.slice();
|
|
2372
2886
|
}
|
|
2887
|
+
|
|
2373
2888
|
Object.defineProperty(Loader.prototype, "baseUrl", {
|
|
2374
2889
|
get: function get() {
|
|
2375
2890
|
return this._baseUrl;
|
|
@@ -2378,24 +2893,29 @@ var Loader = function () {
|
|
|
2378
2893
|
while (url.length && url.charAt(url.length - 1) === '/') {
|
|
2379
2894
|
url = url.slice(0, -1);
|
|
2380
2895
|
}
|
|
2896
|
+
|
|
2381
2897
|
this._baseUrl = url;
|
|
2382
2898
|
},
|
|
2383
2899
|
enumerable: true,
|
|
2384
2900
|
configurable: true
|
|
2385
2901
|
});
|
|
2902
|
+
|
|
2386
2903
|
Loader.prototype.add = function (options, url_) {
|
|
2387
2904
|
if (Array.isArray(options)) {
|
|
2388
2905
|
for (var i = 0; i < options.length; ++i) {
|
|
2389
2906
|
this.add(options[i]);
|
|
2390
2907
|
}
|
|
2908
|
+
|
|
2391
2909
|
return this;
|
|
2392
2910
|
}
|
|
2911
|
+
|
|
2393
2912
|
var url = '';
|
|
2394
2913
|
var name = '';
|
|
2395
2914
|
var baseUrl = this._baseUrl;
|
|
2396
2915
|
var resOptions = {
|
|
2397
2916
|
url: ''
|
|
2398
2917
|
};
|
|
2918
|
+
|
|
2399
2919
|
if (typeof options === 'object') {
|
|
2400
2920
|
url = options.url;
|
|
2401
2921
|
name = options.name || options.url;
|
|
@@ -2405,84 +2925,114 @@ var Loader = function () {
|
|
|
2405
2925
|
name = options;
|
|
2406
2926
|
if (typeof url_ === 'string') url = url_;else url = name;
|
|
2407
2927
|
}
|
|
2928
|
+
|
|
2408
2929
|
if (!url) throw new Error('You must specify the `url` property.');
|
|
2930
|
+
|
|
2409
2931
|
if (this.loading && !resOptions.parentResource) {
|
|
2410
2932
|
throw new Error('Cannot add root resources while the loader is running.');
|
|
2411
2933
|
}
|
|
2934
|
+
|
|
2412
2935
|
if (this.resources[name]) {
|
|
2413
2936
|
throw new Error("Resource named \"" + name + "\" already exists.");
|
|
2414
2937
|
}
|
|
2938
|
+
|
|
2415
2939
|
url = this._prepareUrl(url, baseUrl);
|
|
2416
2940
|
resOptions.url = url;
|
|
2417
2941
|
var resource = new Resource$1(name, resOptions);
|
|
2418
2942
|
this.resources[name] = resource;
|
|
2943
|
+
|
|
2419
2944
|
if (typeof resOptions.onComplete === 'function') {
|
|
2420
2945
|
resource.onAfterMiddleware.once(resOptions.onComplete);
|
|
2421
2946
|
}
|
|
2947
|
+
|
|
2422
2948
|
if (this.loading) {
|
|
2423
2949
|
var parent_1 = resOptions.parentResource;
|
|
2424
2950
|
var incompleteChildren = [];
|
|
2951
|
+
|
|
2425
2952
|
for (var i = 0; i < parent_1.children.length; ++i) {
|
|
2426
2953
|
if (!parent_1.children[i].isComplete) {
|
|
2427
2954
|
incompleteChildren.push(parent_1.children[i]);
|
|
2428
2955
|
}
|
|
2429
2956
|
}
|
|
2957
|
+
|
|
2430
2958
|
var fullChunk = parent_1.progressChunk * (incompleteChildren.length + 1);
|
|
2431
2959
|
var eachChunk = fullChunk / (incompleteChildren.length + 2);
|
|
2432
2960
|
parent_1.children.push(resource);
|
|
2433
2961
|
parent_1.progressChunk = eachChunk;
|
|
2962
|
+
|
|
2434
2963
|
for (var i = 0; i < incompleteChildren.length; ++i) {
|
|
2435
2964
|
incompleteChildren[i].progressChunk = eachChunk;
|
|
2436
2965
|
}
|
|
2966
|
+
|
|
2437
2967
|
resource.progressChunk = eachChunk;
|
|
2438
2968
|
}
|
|
2969
|
+
|
|
2439
2970
|
this._queue.push(resource);
|
|
2971
|
+
|
|
2440
2972
|
return this;
|
|
2441
2973
|
};
|
|
2974
|
+
|
|
2442
2975
|
Loader.prototype.use = function (fn, priority) {
|
|
2443
2976
|
if (priority === void 0) {
|
|
2444
2977
|
priority = Loader.DefaultMiddlewarePriority;
|
|
2445
2978
|
}
|
|
2979
|
+
|
|
2446
2980
|
this._middleware.push({
|
|
2447
2981
|
fn: fn,
|
|
2448
2982
|
priority: priority
|
|
2449
2983
|
});
|
|
2984
|
+
|
|
2450
2985
|
this._middleware.sort(function (a, b) {
|
|
2451
2986
|
return a.priority - b.priority;
|
|
2452
2987
|
});
|
|
2988
|
+
|
|
2453
2989
|
return this;
|
|
2454
2990
|
};
|
|
2991
|
+
|
|
2455
2992
|
Loader.prototype.reset = function () {
|
|
2456
2993
|
this.progress = 0;
|
|
2457
2994
|
this.loading = false;
|
|
2995
|
+
|
|
2458
2996
|
this._queue.reset();
|
|
2997
|
+
|
|
2459
2998
|
this._queue.pause();
|
|
2999
|
+
|
|
2460
3000
|
for (var k in this.resources) {
|
|
2461
3001
|
var res = this.resources[k];
|
|
2462
3002
|
if (!res) continue;
|
|
2463
3003
|
if (res._onCompleteBinding) res._onCompleteBinding.detach();
|
|
2464
3004
|
if (res.isLoading) res.abort();
|
|
2465
3005
|
}
|
|
3006
|
+
|
|
2466
3007
|
this.resources = {};
|
|
2467
3008
|
return this;
|
|
2468
3009
|
};
|
|
3010
|
+
|
|
2469
3011
|
Loader.prototype.load = function (cb) {
|
|
2470
3012
|
if (typeof cb === 'function') this.onComplete.once(cb);
|
|
2471
3013
|
if (this.loading) return this;
|
|
3014
|
+
|
|
2472
3015
|
if (this._queue.idle()) {
|
|
2473
3016
|
this._onStart();
|
|
3017
|
+
|
|
2474
3018
|
this._onComplete();
|
|
2475
3019
|
} else {
|
|
2476
3020
|
var numTasks = this._queue.length();
|
|
3021
|
+
|
|
2477
3022
|
var chunk = MAX_PROGRESS / numTasks;
|
|
3023
|
+
|
|
2478
3024
|
for (var i = 0; i < this._queue.length(); ++i) {
|
|
2479
3025
|
this._queue.getTask(i).data.progressChunk = chunk;
|
|
2480
3026
|
}
|
|
3027
|
+
|
|
2481
3028
|
this._onStart();
|
|
3029
|
+
|
|
2482
3030
|
this._queue.resume();
|
|
2483
3031
|
}
|
|
3032
|
+
|
|
2484
3033
|
return this;
|
|
2485
3034
|
};
|
|
3035
|
+
|
|
2486
3036
|
Object.defineProperty(Loader.prototype, "concurrency", {
|
|
2487
3037
|
get: function get() {
|
|
2488
3038
|
return this._queue.concurrency;
|
|
@@ -2493,25 +3043,32 @@ var Loader = function () {
|
|
|
2493
3043
|
enumerable: true,
|
|
2494
3044
|
configurable: true
|
|
2495
3045
|
});
|
|
3046
|
+
|
|
2496
3047
|
Loader.prototype.addUrlResolver = function (func) {
|
|
2497
3048
|
this._urlResolvers.push(func);
|
|
3049
|
+
|
|
2498
3050
|
return this;
|
|
2499
3051
|
};
|
|
3052
|
+
|
|
2500
3053
|
Loader.prototype._prepareUrl = function (url, baseUrl) {
|
|
2501
3054
|
var parsed = parseUri(url, {
|
|
2502
3055
|
strictMode: true
|
|
2503
3056
|
});
|
|
3057
|
+
|
|
2504
3058
|
this._urlResolvers.forEach(function (resolver) {
|
|
2505
3059
|
url = resolver(url, parsed);
|
|
2506
3060
|
parsed = parseUri(url, {
|
|
2507
3061
|
strictMode: true
|
|
2508
3062
|
});
|
|
2509
3063
|
});
|
|
3064
|
+
|
|
2510
3065
|
if (!parsed.protocol && url.indexOf('//') !== 0) {
|
|
2511
3066
|
if (baseUrl.length && url.charAt(0) !== '/') url = baseUrl + "/" + url;else url = baseUrl + url;
|
|
2512
3067
|
}
|
|
3068
|
+
|
|
2513
3069
|
if (this.defaultQueryString) {
|
|
2514
3070
|
var match = rgxExtractUrlHash.exec(url);
|
|
3071
|
+
|
|
2515
3072
|
if (match) {
|
|
2516
3073
|
var hash = match[0];
|
|
2517
3074
|
url = url.substr(0, url.length - hash.length);
|
|
@@ -2519,90 +3076,121 @@ var Loader = function () {
|
|
|
2519
3076
|
url += hash;
|
|
2520
3077
|
}
|
|
2521
3078
|
}
|
|
3079
|
+
|
|
2522
3080
|
return url;
|
|
2523
3081
|
};
|
|
3082
|
+
|
|
2524
3083
|
Loader.prototype._loadResource = function (resource, dequeue) {
|
|
2525
3084
|
resource._dequeue = dequeue;
|
|
2526
3085
|
resource._onCompleteBinding = resource.onComplete.once(this._onLoad, this);
|
|
2527
3086
|
resource.load();
|
|
2528
3087
|
};
|
|
3088
|
+
|
|
2529
3089
|
Loader.prototype._onStart = function () {
|
|
2530
3090
|
this.progress = 0;
|
|
2531
3091
|
this.loading = true;
|
|
2532
3092
|
this.onStart.dispatch(this);
|
|
2533
3093
|
};
|
|
3094
|
+
|
|
2534
3095
|
Loader.prototype._onComplete = function () {
|
|
2535
3096
|
this.progress = MAX_PROGRESS;
|
|
2536
3097
|
this.loading = false;
|
|
2537
3098
|
this.onComplete.dispatch(this, this.resources);
|
|
2538
3099
|
};
|
|
3100
|
+
|
|
2539
3101
|
Loader.prototype._onLoad = function (resource) {
|
|
2540
3102
|
var _this = this;
|
|
3103
|
+
|
|
2541
3104
|
resource._onCompleteBinding = null;
|
|
3105
|
+
|
|
2542
3106
|
this._resourcesParsing.push(resource);
|
|
3107
|
+
|
|
2543
3108
|
resource._dequeue();
|
|
3109
|
+
|
|
2544
3110
|
eachSeries(this._middleware, function (middleware, next) {
|
|
2545
3111
|
middleware.fn.call(_this, resource, next);
|
|
2546
3112
|
}, function () {
|
|
2547
3113
|
resource.onAfterMiddleware.dispatch(resource);
|
|
2548
3114
|
_this.progress = Math.min(MAX_PROGRESS, _this.progress + resource.progressChunk);
|
|
3115
|
+
|
|
2549
3116
|
_this.onProgress.dispatch(_this, resource);
|
|
3117
|
+
|
|
2550
3118
|
if (resource.error) _this.onError.dispatch(resource.error, _this, resource);else _this.onLoad.dispatch(_this, resource);
|
|
3119
|
+
|
|
2551
3120
|
_this._resourcesParsing.splice(_this._resourcesParsing.indexOf(resource), 1);
|
|
3121
|
+
|
|
2552
3122
|
if (_this._queue.idle() && _this._resourcesParsing.length === 0) _this._onComplete();
|
|
2553
3123
|
}, true);
|
|
2554
3124
|
};
|
|
3125
|
+
|
|
2555
3126
|
Loader.use = function (fn, priority) {
|
|
2556
3127
|
if (priority === void 0) {
|
|
2557
3128
|
priority = Loader.DefaultMiddlewarePriority;
|
|
2558
3129
|
}
|
|
3130
|
+
|
|
2559
3131
|
Loader._defaultMiddleware.push({
|
|
2560
3132
|
fn: fn,
|
|
2561
3133
|
priority: priority
|
|
2562
3134
|
});
|
|
3135
|
+
|
|
2563
3136
|
Loader._defaultMiddleware.sort(function (a, b) {
|
|
2564
3137
|
return a.priority - b.priority;
|
|
2565
3138
|
});
|
|
3139
|
+
|
|
2566
3140
|
return Loader;
|
|
2567
3141
|
};
|
|
3142
|
+
|
|
2568
3143
|
Loader.DefaultMiddlewarePriority = 50;
|
|
2569
3144
|
Loader._defaultMiddleware = [];
|
|
2570
3145
|
return Loader;
|
|
2571
3146
|
}();
|
|
3147
|
+
|
|
2572
3148
|
var Progress = function (_super) {
|
|
2573
3149
|
__extends$1(Progress, _super);
|
|
3150
|
+
|
|
2574
3151
|
function Progress(_a) {
|
|
2575
3152
|
var resource = _a.resource,
|
|
2576
|
-
|
|
3153
|
+
resourceTotal = _a.resourceTotal;
|
|
3154
|
+
|
|
2577
3155
|
var _this = _super.call(this) || this;
|
|
3156
|
+
|
|
2578
3157
|
_this.progress = 0;
|
|
2579
3158
|
_this.resourceTotal = 0;
|
|
2580
3159
|
_this.resourceLoadedCount = 0;
|
|
2581
3160
|
_this.resource = resource;
|
|
2582
3161
|
_this.resourceTotal = resourceTotal;
|
|
3162
|
+
|
|
2583
3163
|
if (resourceTotal === 0) {
|
|
2584
3164
|
_this.resource.emit(LOAD_EVENT.COMPLETE, _this);
|
|
2585
3165
|
}
|
|
3166
|
+
|
|
2586
3167
|
return _this;
|
|
2587
3168
|
}
|
|
3169
|
+
|
|
2588
3170
|
Progress.prototype.onStart = function () {
|
|
2589
3171
|
this.resource.emit(LOAD_EVENT.START, this);
|
|
2590
3172
|
};
|
|
3173
|
+
|
|
2591
3174
|
Progress.prototype.onProgress = function (param) {
|
|
2592
3175
|
this.resourceLoadedCount++;
|
|
2593
3176
|
this.progress = Math.floor(this.resourceLoadedCount / this.resourceTotal * 100) / 100;
|
|
3177
|
+
|
|
2594
3178
|
if (param.success) {
|
|
2595
3179
|
this.resource.emit(LOAD_EVENT.LOADED, this, param);
|
|
2596
3180
|
} else {
|
|
2597
3181
|
this.resource.emit(LOAD_EVENT.ERROR, this, param);
|
|
2598
3182
|
}
|
|
3183
|
+
|
|
2599
3184
|
this.resource.emit(LOAD_EVENT.PROGRESS, this, param);
|
|
3185
|
+
|
|
2600
3186
|
if (this.resourceLoadedCount === this.resourceTotal) {
|
|
2601
3187
|
this.resource.emit(LOAD_EVENT.COMPLETE, this);
|
|
2602
3188
|
}
|
|
2603
3189
|
};
|
|
3190
|
+
|
|
2604
3191
|
return Progress;
|
|
2605
3192
|
}(EventEmitter);
|
|
3193
|
+
|
|
2606
3194
|
var Progress$1 = Progress;
|
|
2607
3195
|
var resourceLoader = {
|
|
2608
3196
|
AbstractLoadStrategy: AbstractLoadStrategy,
|
|
@@ -2618,6 +3206,7 @@ var resourceLoader = {
|
|
|
2618
3206
|
ResourceState: ResourceState
|
|
2619
3207
|
};
|
|
2620
3208
|
var LOAD_EVENT;
|
|
3209
|
+
|
|
2621
3210
|
(function (LOAD_EVENT) {
|
|
2622
3211
|
LOAD_EVENT["START"] = "start";
|
|
2623
3212
|
LOAD_EVENT["PROGRESS"] = "progress";
|
|
@@ -2625,7 +3214,9 @@ var LOAD_EVENT;
|
|
|
2625
3214
|
LOAD_EVENT["COMPLETE"] = "complete";
|
|
2626
3215
|
LOAD_EVENT["ERROR"] = "error";
|
|
2627
3216
|
})(LOAD_EVENT || (LOAD_EVENT = {}));
|
|
3217
|
+
|
|
2628
3218
|
var RESOURCE_TYPE;
|
|
3219
|
+
|
|
2629
3220
|
(function (RESOURCE_TYPE) {
|
|
2630
3221
|
RESOURCE_TYPE["IMAGE"] = "IMAGE";
|
|
2631
3222
|
RESOURCE_TYPE["SPRITE"] = "SPRITE";
|
|
@@ -2633,6 +3224,7 @@ var RESOURCE_TYPE;
|
|
|
2633
3224
|
RESOURCE_TYPE["AUDIO"] = "AUDIO";
|
|
2634
3225
|
RESOURCE_TYPE["VIDEO"] = "VIDEO";
|
|
2635
3226
|
})(RESOURCE_TYPE || (RESOURCE_TYPE = {}));
|
|
3227
|
+
|
|
2636
3228
|
XhrLoadStrategy.setExtensionXhrType('json', XhrResponseType.Json);
|
|
2637
3229
|
XhrLoadStrategy.setExtensionXhrType('tex', XhrResponseType.Json);
|
|
2638
3230
|
XhrLoadStrategy.setExtensionXhrType('ske', XhrResponseType.Json);
|
|
@@ -2651,10 +3243,13 @@ var RESOURCE_TYPE_STRATEGY = {
|
|
|
2651
3243
|
audio: XhrLoadStrategy,
|
|
2652
3244
|
video: VideoLoadStrategy
|
|
2653
3245
|
};
|
|
3246
|
+
|
|
2654
3247
|
var Resource = function (_super) {
|
|
2655
3248
|
__extends$1(Resource, _super);
|
|
3249
|
+
|
|
2656
3250
|
function Resource(options) {
|
|
2657
3251
|
var _this = _super.call(this) || this;
|
|
3252
|
+
|
|
2658
3253
|
_this.timeout = 6000;
|
|
2659
3254
|
_this.preProcessResourceHandlers = [];
|
|
2660
3255
|
_this.resourcesMap = {};
|
|
@@ -2662,32 +3257,41 @@ var Resource = function (_super) {
|
|
|
2662
3257
|
_this.destroyInstanceFunctions = {};
|
|
2663
3258
|
_this.promiseMap = {};
|
|
2664
3259
|
_this.loaders = [];
|
|
3260
|
+
|
|
2665
3261
|
if (options && typeof options.timeout === 'number') {
|
|
2666
3262
|
_this.timeout = options.timeout;
|
|
2667
3263
|
}
|
|
3264
|
+
|
|
2668
3265
|
return _this;
|
|
2669
3266
|
}
|
|
3267
|
+
|
|
2670
3268
|
Resource.prototype.loadConfig = function (resources) {
|
|
2671
3269
|
this.addResource(resources);
|
|
2672
3270
|
this.preload();
|
|
2673
3271
|
};
|
|
3272
|
+
|
|
2674
3273
|
Resource.prototype.loadSingle = function (resource) {
|
|
2675
3274
|
this.addResource([resource]);
|
|
2676
3275
|
return this.getResource(resource.name);
|
|
2677
3276
|
};
|
|
3277
|
+
|
|
2678
3278
|
Resource.prototype.addResource = function (resources) {
|
|
2679
3279
|
var e_1, _a;
|
|
3280
|
+
|
|
2680
3281
|
if (!resources || resources.length < 1) {
|
|
2681
3282
|
console.warn('no resources');
|
|
2682
3283
|
return;
|
|
2683
3284
|
}
|
|
3285
|
+
|
|
2684
3286
|
try {
|
|
2685
3287
|
for (var resources_1 = __values(resources), resources_1_1 = resources_1.next(); !resources_1_1.done; resources_1_1 = resources_1.next()) {
|
|
2686
3288
|
var res = resources_1_1.value;
|
|
3289
|
+
|
|
2687
3290
|
if (this.resourcesMap[res.name]) {
|
|
2688
3291
|
console.warn(res.name + ' was already added');
|
|
2689
3292
|
continue;
|
|
2690
3293
|
}
|
|
3294
|
+
|
|
2691
3295
|
this.resourcesMap[res.name] = res;
|
|
2692
3296
|
this.resourcesMap[res.name].data = {};
|
|
2693
3297
|
}
|
|
@@ -2703,20 +3307,26 @@ var Resource = function (_super) {
|
|
|
2703
3307
|
}
|
|
2704
3308
|
}
|
|
2705
3309
|
};
|
|
3310
|
+
|
|
2706
3311
|
Resource.prototype.addPreProcessResourceHandler = function (handler) {
|
|
2707
3312
|
this.preProcessResourceHandlers.push(handler);
|
|
2708
3313
|
};
|
|
3314
|
+
|
|
2709
3315
|
Resource.prototype.removePreProcessResourceHandler = function (handler) {
|
|
2710
3316
|
this.preProcessResourceHandlers.splice(this.preProcessResourceHandlers.indexOf(handler), 1);
|
|
2711
3317
|
};
|
|
3318
|
+
|
|
2712
3319
|
Resource.prototype.preload = function () {
|
|
2713
3320
|
var names = [];
|
|
3321
|
+
|
|
2714
3322
|
for (var key in this.resourcesMap) {
|
|
2715
3323
|
var resource_1 = this.resourcesMap[key];
|
|
3324
|
+
|
|
2716
3325
|
if (resource_1.preload && !resource_1.complete && !this.promiseMap[key]) {
|
|
2717
3326
|
names.push(resource_1.name);
|
|
2718
3327
|
}
|
|
2719
3328
|
}
|
|
3329
|
+
|
|
2720
3330
|
this.progress = new Progress$1({
|
|
2721
3331
|
resource: this,
|
|
2722
3332
|
resourceTotal: names.length
|
|
@@ -2726,6 +3336,7 @@ var Resource = function (_super) {
|
|
|
2726
3336
|
preload: true
|
|
2727
3337
|
});
|
|
2728
3338
|
};
|
|
3339
|
+
|
|
2729
3340
|
Resource.prototype.getResource = function (name) {
|
|
2730
3341
|
return __awaiter(this, void 0, void 0, function () {
|
|
2731
3342
|
return __generator(this, function (_a) {
|
|
@@ -2736,9 +3347,11 @@ var Resource = function (_super) {
|
|
|
2736
3347
|
});
|
|
2737
3348
|
});
|
|
2738
3349
|
};
|
|
3350
|
+
|
|
2739
3351
|
Resource.prototype.instance = function (name) {
|
|
2740
3352
|
return __awaiter(this, void 0, void 0, function () {
|
|
2741
3353
|
var res, _a;
|
|
3354
|
+
|
|
2742
3355
|
return __generator(this, function (_b) {
|
|
2743
3356
|
switch (_b.label) {
|
|
2744
3357
|
case 0:
|
|
@@ -2746,32 +3359,39 @@ var Resource = function (_super) {
|
|
|
2746
3359
|
_a = this.makeInstanceFunctions[res.type];
|
|
2747
3360
|
if (!_a) return [3, 2];
|
|
2748
3361
|
return [4, this.makeInstanceFunctions[res.type](res)];
|
|
3362
|
+
|
|
2749
3363
|
case 1:
|
|
2750
3364
|
_a = _b.sent();
|
|
2751
3365
|
_b.label = 2;
|
|
3366
|
+
|
|
2752
3367
|
case 2:
|
|
2753
3368
|
return [2, _a];
|
|
2754
3369
|
}
|
|
2755
3370
|
});
|
|
2756
3371
|
});
|
|
2757
3372
|
};
|
|
3373
|
+
|
|
2758
3374
|
Resource.prototype.destroy = function (name) {
|
|
2759
3375
|
return __awaiter(this, void 0, void 0, function () {
|
|
2760
3376
|
return __generator(this, function (_a) {
|
|
2761
3377
|
switch (_a.label) {
|
|
2762
3378
|
case 0:
|
|
2763
3379
|
return [4, this._destroy(name)];
|
|
3380
|
+
|
|
2764
3381
|
case 1:
|
|
2765
3382
|
_a.sent();
|
|
3383
|
+
|
|
2766
3384
|
return [2];
|
|
2767
3385
|
}
|
|
2768
3386
|
});
|
|
2769
3387
|
});
|
|
2770
3388
|
};
|
|
3389
|
+
|
|
2771
3390
|
Resource.prototype._destroy = function (name, loadError) {
|
|
2772
3391
|
if (loadError === void 0) {
|
|
2773
3392
|
loadError = false;
|
|
2774
3393
|
}
|
|
3394
|
+
|
|
2775
3395
|
return __awaiter(this, void 0, void 0, function () {
|
|
2776
3396
|
var resource, e_2;
|
|
2777
3397
|
return __generator(this, function (_a) {
|
|
@@ -2781,19 +3401,26 @@ var Resource = function (_super) {
|
|
|
2781
3401
|
if (!resource) return [2];
|
|
2782
3402
|
if (!!loadError) return [3, 5];
|
|
2783
3403
|
_a.label = 1;
|
|
3404
|
+
|
|
2784
3405
|
case 1:
|
|
2785
3406
|
_a.trys.push([1, 4,, 5]);
|
|
3407
|
+
|
|
2786
3408
|
if (!this.destroyInstanceFunctions[resource.type]) return [3, 3];
|
|
2787
3409
|
return [4, this.destroyInstanceFunctions[resource.type](resource)];
|
|
3410
|
+
|
|
2788
3411
|
case 2:
|
|
2789
3412
|
_a.sent();
|
|
3413
|
+
|
|
2790
3414
|
_a.label = 3;
|
|
3415
|
+
|
|
2791
3416
|
case 3:
|
|
2792
3417
|
return [3, 5];
|
|
3418
|
+
|
|
2793
3419
|
case 4:
|
|
2794
3420
|
e_2 = _a.sent();
|
|
2795
3421
|
console.warn("destroy resource " + resource.name + " error with '" + e_2.message + "'");
|
|
2796
3422
|
return [3, 5];
|
|
3423
|
+
|
|
2797
3424
|
case 5:
|
|
2798
3425
|
delete this.promiseMap[name];
|
|
2799
3426
|
resource.data = {};
|
|
@@ -2804,27 +3431,34 @@ var Resource = function (_super) {
|
|
|
2804
3431
|
});
|
|
2805
3432
|
});
|
|
2806
3433
|
};
|
|
3434
|
+
|
|
2807
3435
|
Resource.prototype.registerResourceType = function (type, value) {
|
|
2808
3436
|
if (value === void 0) {
|
|
2809
3437
|
value = type;
|
|
2810
3438
|
}
|
|
3439
|
+
|
|
2811
3440
|
if (RESOURCE_TYPE[type]) {
|
|
2812
3441
|
throw new Error("The type " + type + " already exists in RESOURCE_TYPE");
|
|
2813
3442
|
}
|
|
3443
|
+
|
|
2814
3444
|
RESOURCE_TYPE[type] = value;
|
|
2815
3445
|
};
|
|
3446
|
+
|
|
2816
3447
|
Resource.prototype.registerInstance = function (type, callback) {
|
|
2817
3448
|
this.makeInstanceFunctions[type] = callback;
|
|
2818
3449
|
};
|
|
3450
|
+
|
|
2819
3451
|
Resource.prototype.registerDestroy = function (type, callback) {
|
|
2820
3452
|
this.destroyInstanceFunctions[type] = callback;
|
|
2821
3453
|
};
|
|
3454
|
+
|
|
2822
3455
|
Resource.prototype.loadResource = function (_a) {
|
|
2823
3456
|
var _this = this;
|
|
3457
|
+
|
|
2824
3458
|
var _b = _a.names,
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
3459
|
+
names = _b === void 0 ? [] : _b,
|
|
3460
|
+
_c = _a.preload,
|
|
3461
|
+
preload = _c === void 0 ? false : _c;
|
|
2828
3462
|
var unLoadNames = names.filter(function (name) {
|
|
2829
3463
|
return !_this.promiseMap[name] && _this.resourcesMap[name];
|
|
2830
3464
|
});
|
|
@@ -2833,10 +3467,12 @@ var Resource = function (_super) {
|
|
|
2833
3467
|
var loader = this.getLoader(preload);
|
|
2834
3468
|
unLoadNames.forEach(function (name) {
|
|
2835
3469
|
var e_3, _a;
|
|
3470
|
+
|
|
2836
3471
|
_this.promiseMap[name] = new Promise(function (r) {
|
|
2837
3472
|
return resolves[name] = r;
|
|
2838
3473
|
});
|
|
2839
3474
|
var res = _this.resourcesMap[name];
|
|
3475
|
+
|
|
2840
3476
|
try {
|
|
2841
3477
|
for (var _b = __values(_this.preProcessResourceHandlers), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
2842
3478
|
var handler = _c.value;
|
|
@@ -2853,10 +3489,13 @@ var Resource = function (_super) {
|
|
|
2853
3489
|
if (e_3) throw e_3.error;
|
|
2854
3490
|
}
|
|
2855
3491
|
}
|
|
3492
|
+
|
|
2856
3493
|
for (var key in res.src) {
|
|
2857
3494
|
var resourceType = res.src[key].type;
|
|
3495
|
+
|
|
2858
3496
|
if (resourceType === 'data') {
|
|
2859
3497
|
res.data[key] = res.src[key].data;
|
|
3498
|
+
|
|
2860
3499
|
_this.doComplete(name, resolves[name], preload);
|
|
2861
3500
|
} else {
|
|
2862
3501
|
loader.add({
|
|
@@ -2874,12 +3513,15 @@ var Resource = function (_super) {
|
|
|
2874
3513
|
});
|
|
2875
3514
|
loader.load();
|
|
2876
3515
|
};
|
|
3516
|
+
|
|
2877
3517
|
Resource.prototype.doComplete = function (name, resolve, preload) {
|
|
2878
3518
|
if (preload === void 0) {
|
|
2879
3519
|
preload = false;
|
|
2880
3520
|
}
|
|
3521
|
+
|
|
2881
3522
|
return __awaiter(this, void 0, void 0, function () {
|
|
2882
3523
|
var res, param, _a, err_1;
|
|
3524
|
+
|
|
2883
3525
|
return __generator(this, function (_b) {
|
|
2884
3526
|
switch (_b.label) {
|
|
2885
3527
|
case 0:
|
|
@@ -2891,59 +3533,75 @@ var Resource = function (_super) {
|
|
|
2891
3533
|
};
|
|
2892
3534
|
if (!this.checkAllLoaded(name)) return [3, 4];
|
|
2893
3535
|
_b.label = 1;
|
|
3536
|
+
|
|
2894
3537
|
case 1:
|
|
2895
3538
|
_b.trys.push([1, 3,, 4]);
|
|
3539
|
+
|
|
2896
3540
|
_a = res;
|
|
2897
3541
|
return [4, this.instance(name)];
|
|
3542
|
+
|
|
2898
3543
|
case 2:
|
|
2899
3544
|
_a.instance = _b.sent();
|
|
2900
3545
|
res.complete = true;
|
|
3546
|
+
|
|
2901
3547
|
if (preload) {
|
|
2902
3548
|
this.progress.onProgress(param);
|
|
2903
3549
|
}
|
|
3550
|
+
|
|
2904
3551
|
resolve(res);
|
|
2905
3552
|
return [3, 4];
|
|
3553
|
+
|
|
2906
3554
|
case 3:
|
|
2907
3555
|
err_1 = _b.sent();
|
|
2908
3556
|
console.error(err_1);
|
|
2909
3557
|
res.complete = false;
|
|
3558
|
+
|
|
2910
3559
|
if (preload) {
|
|
2911
3560
|
param.errMsg = err_1.message;
|
|
2912
3561
|
param.success = false;
|
|
2913
3562
|
this.progress.onProgress(param);
|
|
2914
3563
|
}
|
|
3564
|
+
|
|
2915
3565
|
resolve({});
|
|
2916
3566
|
return [3, 4];
|
|
3567
|
+
|
|
2917
3568
|
case 4:
|
|
2918
3569
|
return [2];
|
|
2919
3570
|
}
|
|
2920
3571
|
});
|
|
2921
3572
|
});
|
|
2922
3573
|
};
|
|
3574
|
+
|
|
2923
3575
|
Resource.prototype.checkAllLoaded = function (name) {
|
|
2924
3576
|
var res = this.resourcesMap[name];
|
|
2925
3577
|
return Array.from(Object.keys(res.src)).every(function (resourceKey) {
|
|
2926
3578
|
return res.data[resourceKey];
|
|
2927
3579
|
});
|
|
2928
3580
|
};
|
|
3581
|
+
|
|
2929
3582
|
Resource.prototype.getLoader = function (preload) {
|
|
2930
3583
|
var _this = this;
|
|
3584
|
+
|
|
2931
3585
|
if (preload === void 0) {
|
|
2932
3586
|
preload = false;
|
|
2933
3587
|
}
|
|
3588
|
+
|
|
2934
3589
|
var loader = this.loaders.find(function (_a) {
|
|
2935
3590
|
var loading = _a.loading;
|
|
2936
3591
|
return !loading;
|
|
2937
3592
|
});
|
|
3593
|
+
|
|
2938
3594
|
if (!loader) {
|
|
2939
3595
|
loader = new Loader();
|
|
2940
3596
|
this.loaders.push(loader);
|
|
2941
3597
|
}
|
|
3598
|
+
|
|
2942
3599
|
if (preload) {
|
|
2943
3600
|
loader.onStart.once(function () {
|
|
2944
3601
|
_this.progress.onStart();
|
|
2945
3602
|
});
|
|
2946
3603
|
}
|
|
3604
|
+
|
|
2947
3605
|
loader.onLoad.add(function (_, resource) {
|
|
2948
3606
|
_this.onLoad({
|
|
2949
3607
|
preload: preload,
|
|
@@ -2964,12 +3622,14 @@ var Resource = function (_super) {
|
|
|
2964
3622
|
});
|
|
2965
3623
|
return loader;
|
|
2966
3624
|
};
|
|
3625
|
+
|
|
2967
3626
|
Resource.prototype.onLoad = function (_a) {
|
|
2968
3627
|
var _b = _a.preload,
|
|
2969
|
-
|
|
2970
|
-
|
|
3628
|
+
preload = _b === void 0 ? false : _b,
|
|
3629
|
+
resource = _a.resource;
|
|
2971
3630
|
return __awaiter(this, void 0, void 0, function () {
|
|
2972
3631
|
var _c, key, name, resolves, data, res;
|
|
3632
|
+
|
|
2973
3633
|
return __generator(this, function (_d) {
|
|
2974
3634
|
_c = resource.metadata, key = _c.key, name = _c.name, resolves = _c.resolves, data = resource.data;
|
|
2975
3635
|
res = this.resourcesMap[name];
|
|
@@ -2979,17 +3639,22 @@ var Resource = function (_super) {
|
|
|
2979
3639
|
});
|
|
2980
3640
|
});
|
|
2981
3641
|
};
|
|
3642
|
+
|
|
2982
3643
|
Resource.prototype.onError = function (_a) {
|
|
2983
3644
|
var errMsg = _a.errMsg,
|
|
2984
|
-
|
|
2985
|
-
|
|
2986
|
-
|
|
3645
|
+
_b = _a.preload,
|
|
3646
|
+
preload = _b === void 0 ? false : _b,
|
|
3647
|
+
resource = _a.resource;
|
|
2987
3648
|
return __awaiter(this, void 0, void 0, function () {
|
|
2988
3649
|
var _c, name, resolves, param;
|
|
3650
|
+
|
|
2989
3651
|
return __generator(this, function (_d) {
|
|
2990
3652
|
_c = resource.metadata, name = _c.name, resolves = _c.resolves;
|
|
3653
|
+
|
|
2991
3654
|
this._destroy(name, true);
|
|
3655
|
+
|
|
2992
3656
|
resolves[name]({});
|
|
3657
|
+
|
|
2993
3658
|
if (preload) {
|
|
2994
3659
|
param = {
|
|
2995
3660
|
name: name,
|
|
@@ -2999,17 +3664,20 @@ var Resource = function (_super) {
|
|
|
2999
3664
|
};
|
|
3000
3665
|
this.progress.onProgress(param);
|
|
3001
3666
|
}
|
|
3667
|
+
|
|
3002
3668
|
return [2];
|
|
3003
3669
|
});
|
|
3004
3670
|
});
|
|
3005
3671
|
};
|
|
3672
|
+
|
|
3006
3673
|
return Resource;
|
|
3007
3674
|
}(EventEmitter);
|
|
3675
|
+
|
|
3008
3676
|
var resource = new Resource();
|
|
3009
3677
|
var decorators = {
|
|
3010
3678
|
IDEProp: IDEProp,
|
|
3011
3679
|
componentObserver: componentObserver
|
|
3012
3680
|
};
|
|
3013
|
-
var version = '1.2.7-fix.
|
|
3681
|
+
var version = '1.2.7-fix.5';
|
|
3014
3682
|
console.log("Eva.js version: " + version);
|
|
3015
3683
|
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 };
|