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