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