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