hzengine-core 0.1.2-dev → 0.1.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/async/index.js +150 -162
- package/dist/audio/index.js +249 -260
- package/dist/config/index.js +57 -57
- package/dist/debug/index.js +9 -8
- package/dist/index.js +108 -103
- package/dist/plugins/basic_command/img.js +247 -249
- package/dist/plugins/basic_command/menu.js +140 -140
- package/dist/plugins/transform/animation.js +430 -440
- package/dist/plugins/transform/hz_anime.js +196 -211
- package/dist/plugins/transform/index.js +94 -93
- package/dist/script/index.js +537 -537
- package/dist/storage/index.js +447 -440
- package/dist/system/index.js +131 -144
- package/dist/ui/index.js +525 -535
- package/package.json +1 -1
- package/src/platform/index.ts +14 -12
- package/src/plugins/transform/animation.ts +1 -1
- package/src/script/index.ts +13 -0
- package/src/storage/index.ts +47 -47
- package/tsconfig.json +1 -1
- package/types/platform/index.d.ts +137 -134
- package/types/script/index.d.ts +129 -123
- package/types/script/strtools.d.ts +31 -31
|
@@ -1,440 +1,430 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* animation.js
|
|
3
|
-
* @description A library for providing multi-track animations for HZEngine. 一个用于在HZEngine中提供简单动画的库
|
|
4
|
-
* @date 2024/10/2
|
|
5
|
-
* @author CuberQAQ
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
activeRootTrack
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
if (typeof props[key] === "
|
|
137
|
-
if (_former_props[key] == undefined)
|
|
138
|
-
_former_props[key] =
|
|
139
|
-
res[key] =
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
}
|
|
208
|
-
constructor(animation, { accessKeys, index, initProps, }) {
|
|
209
|
-
this.animation = animation;
|
|
210
|
-
this.
|
|
211
|
-
this.
|
|
212
|
-
this.
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
return
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
this.
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
//
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
else
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
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
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
(
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
Status[Status["Pause"] = 2] = "Pause";
|
|
432
|
-
})(Status = ActiveTrackNode.Status || (ActiveTrackNode.Status = {}));
|
|
433
|
-
})(ActiveTrackNode || (ActiveTrackNode = {}));
|
|
434
|
-
const buildInWrappers = {
|
|
435
|
-
none: (x) => (x < 1 ? 0 : 1),
|
|
436
|
-
linear: (x) => x,
|
|
437
|
-
easeout: (x) => Math.pow(x, 3),
|
|
438
|
-
easein: (x) => 1 - Math.pow(1 - x, 3),
|
|
439
|
-
easeinout: (x) => x < 0.5 ? 0.5 * Math.pow(x, 3) : 1 - 0.5 * Math.pow(1 - x, 3),
|
|
440
|
-
};
|
|
1
|
+
/**
|
|
2
|
+
* animation.js
|
|
3
|
+
* @description A library for providing multi-track animations for HZEngine. 一个用于在HZEngine中提供简单动画的库
|
|
4
|
+
* @date 2024/10/2
|
|
5
|
+
* @author CuberQAQ
|
|
6
|
+
*/
|
|
7
|
+
export class Animation {
|
|
8
|
+
normalizedProfile;
|
|
9
|
+
initProps = {};
|
|
10
|
+
activeRootTrack = null;
|
|
11
|
+
lastTime = 0;
|
|
12
|
+
onFrame = null;
|
|
13
|
+
onEnd = null;
|
|
14
|
+
customWrappers = {};
|
|
15
|
+
constructor(profile, options) {
|
|
16
|
+
this.normalizedProfile = Profile.normalize(profile);
|
|
17
|
+
console.log(`Animation: ${JSON.stringify(profile)}`);
|
|
18
|
+
if (options) {
|
|
19
|
+
options.initProps && (this.initProps = options.initProps);
|
|
20
|
+
options.wrappers && (this.customWrappers = options.wrappers);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
onStop = null;
|
|
24
|
+
serialize() {
|
|
25
|
+
return {
|
|
26
|
+
normalizedProfile: this.normalizedProfile,
|
|
27
|
+
initProps: this.initProps,
|
|
28
|
+
activeRootTrack: this.activeRootTrack?.serialize(),
|
|
29
|
+
lastTime: this.lastTime,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
static unserialize(serialized, wrappers) {
|
|
33
|
+
let profile = serialized.normalizedProfile;
|
|
34
|
+
let animation = new Animation(profile, {
|
|
35
|
+
initProps: serialized.initProps,
|
|
36
|
+
wrappers,
|
|
37
|
+
});
|
|
38
|
+
animation.lastTime = serialized.lastTime;
|
|
39
|
+
serialized.activeRootTrack &&
|
|
40
|
+
(animation.activeRootTrack = ActiveTrackNode.unserialize(animation, serialized.activeRootTrack));
|
|
41
|
+
return animation;
|
|
42
|
+
}
|
|
43
|
+
timerCb() { }
|
|
44
|
+
init() {
|
|
45
|
+
this.activeRootTrack = new ActiveTrackNode(this, {
|
|
46
|
+
accessKeys: [],
|
|
47
|
+
index: 0,
|
|
48
|
+
initProps: this.initProps,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
goto(time) {
|
|
52
|
+
if (!this.activeRootTrack) {
|
|
53
|
+
this.init();
|
|
54
|
+
}
|
|
55
|
+
if (time < 0)
|
|
56
|
+
time = 0;
|
|
57
|
+
if (time < this.lastTime) {
|
|
58
|
+
this.init(); // reset the tracknode
|
|
59
|
+
try {
|
|
60
|
+
this.activeRootTrack.step(time);
|
|
61
|
+
}
|
|
62
|
+
catch (e) {
|
|
63
|
+
console.log(e);
|
|
64
|
+
this.activeRootTrack.status = ActiveTrackNode.Status.Pause;
|
|
65
|
+
}
|
|
66
|
+
if (this.activeRootTrack.status === ActiveTrackNode.Status.Pause) {
|
|
67
|
+
if (this.onEnd)
|
|
68
|
+
this.onEnd();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
if (this.activeRootTrack.status !== ActiveTrackNode.Status.Pause) {
|
|
73
|
+
try {
|
|
74
|
+
this.activeRootTrack.step(time - this.lastTime);
|
|
75
|
+
}
|
|
76
|
+
catch (e) {
|
|
77
|
+
console.log(e);
|
|
78
|
+
this.activeRootTrack.status = ActiveTrackNode.Status.Pause;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
this.lastTime = time;
|
|
83
|
+
if (this.onFrame) {
|
|
84
|
+
// console.log("on frame", JSON.stringify(this.calcProps()));
|
|
85
|
+
this.onFrame(this.calcProps());
|
|
86
|
+
}
|
|
87
|
+
if (this.activeRootTrack.status === ActiveTrackNode.Status.Pause) {
|
|
88
|
+
if (this.onEnd)
|
|
89
|
+
this.onEnd();
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
step(delta_time) {
|
|
93
|
+
this.goto(this.lastTime + delta_time);
|
|
94
|
+
}
|
|
95
|
+
calcProps() {
|
|
96
|
+
return this.activeRootTrack.calcProps();
|
|
97
|
+
}
|
|
98
|
+
reverse() { }
|
|
99
|
+
stop() { }
|
|
100
|
+
_accessProfile(accessKeys) {
|
|
101
|
+
let section = this.normalizedProfile;
|
|
102
|
+
for (let i = 0; i < accessKeys.length; i++) {
|
|
103
|
+
section = section[accessKeys[i]];
|
|
104
|
+
}
|
|
105
|
+
return section;
|
|
106
|
+
}
|
|
107
|
+
_getWrapper(wrapper) {
|
|
108
|
+
if (typeof wrapper === "string") {
|
|
109
|
+
return (this.customWrappers[wrapper] ??
|
|
110
|
+
buildInWrappers[wrapper] ??
|
|
111
|
+
buildInWrappers.none);
|
|
112
|
+
}
|
|
113
|
+
else if (wrapper === undefined) {
|
|
114
|
+
return buildInWrappers.none;
|
|
115
|
+
}
|
|
116
|
+
else
|
|
117
|
+
return wrapper;
|
|
118
|
+
}
|
|
119
|
+
_calcWrappedProps(former_props, props, wrapper, progress) {
|
|
120
|
+
let _former_props = { ...former_props };
|
|
121
|
+
let wrapper_func = this._getWrapper(wrapper);
|
|
122
|
+
let wraped_prog = wrapper_func(progress);
|
|
123
|
+
let res = { ..._former_props };
|
|
124
|
+
for (let key in props) {
|
|
125
|
+
if (typeof props[key] === "number") {
|
|
126
|
+
if (_former_props[key] == undefined)
|
|
127
|
+
_former_props[key] = 0;
|
|
128
|
+
res[key] =
|
|
129
|
+
_former_props[key] + wraped_prog * (props[key] - _former_props[key]);
|
|
130
|
+
}
|
|
131
|
+
else if (typeof props[key] === "boolean") {
|
|
132
|
+
if (_former_props[key] == undefined)
|
|
133
|
+
_former_props[key] = false;
|
|
134
|
+
res[key] = wraped_prog === 1 ? props[key] : _former_props[key];
|
|
135
|
+
}
|
|
136
|
+
else if (typeof props[key] === "string") {
|
|
137
|
+
if (_former_props[key] == undefined)
|
|
138
|
+
_former_props[key] = "";
|
|
139
|
+
res[key] = wraped_prog === 1 ? props[key] : _former_props[key];
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
res[key] = props[key];
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return res;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
export var Profile;
|
|
149
|
+
(function (Profile) {
|
|
150
|
+
function normalize(profile) {
|
|
151
|
+
if (!Array.isArray(profile)) {
|
|
152
|
+
// section
|
|
153
|
+
return [profile];
|
|
154
|
+
}
|
|
155
|
+
else if (profile.length === 0) {
|
|
156
|
+
// empty track/tracklist
|
|
157
|
+
return [];
|
|
158
|
+
}
|
|
159
|
+
else if (!Array.isArray(profile[0])) {
|
|
160
|
+
// track
|
|
161
|
+
return profile;
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
// tracklist
|
|
165
|
+
return [
|
|
166
|
+
{
|
|
167
|
+
syncs: profile,
|
|
168
|
+
},
|
|
169
|
+
];
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
Profile.normalize = normalize;
|
|
173
|
+
})(Profile || (Profile = {}));
|
|
174
|
+
export class ActiveTrackNode {
|
|
175
|
+
animation;
|
|
176
|
+
accessKeys;
|
|
177
|
+
currentIndex;
|
|
178
|
+
repeated = 0;
|
|
179
|
+
status = ActiveTrackNode.Status.Playing;
|
|
180
|
+
now_time = 0;
|
|
181
|
+
#currentSection = null;
|
|
182
|
+
#currentIndex = null;
|
|
183
|
+
get currentSection() {
|
|
184
|
+
if (this.#currentSection === null) {
|
|
185
|
+
if (this.currentIndex === null) {
|
|
186
|
+
this.#currentSection = this.animation._accessProfile(this.accessKeys);
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
this.#currentSection = this.currentTrack[this.currentIndex];
|
|
190
|
+
}
|
|
191
|
+
this.#currentIndex = this.currentIndex;
|
|
192
|
+
}
|
|
193
|
+
else if (this.currentIndex !== this.#currentIndex) {
|
|
194
|
+
this.#currentSection = this.currentTrack[this.currentIndex];
|
|
195
|
+
this.#currentIndex = this.currentIndex;
|
|
196
|
+
}
|
|
197
|
+
return this.#currentSection;
|
|
198
|
+
}
|
|
199
|
+
#currentTrack = null;
|
|
200
|
+
get currentTrack() {
|
|
201
|
+
if (this.#currentTrack === null && this.currentIndex !== null) {
|
|
202
|
+
this.#currentTrack = this.animation._accessProfile(this.accessKeys);
|
|
203
|
+
}
|
|
204
|
+
return this.#currentTrack;
|
|
205
|
+
}
|
|
206
|
+
lastProps = {};
|
|
207
|
+
nowProps = {};
|
|
208
|
+
constructor(animation, { accessKeys, index, initProps, }) {
|
|
209
|
+
this.animation = animation;
|
|
210
|
+
this.accessKeys = accessKeys;
|
|
211
|
+
this.currentIndex = index;
|
|
212
|
+
this.lastProps = { ...initProps };
|
|
213
|
+
this.nowProps = { ...initProps };
|
|
214
|
+
}
|
|
215
|
+
serialize() {
|
|
216
|
+
return {
|
|
217
|
+
accessKeys: this.accessKeys,
|
|
218
|
+
currentIndex: this.currentIndex,
|
|
219
|
+
repeated: this.repeated,
|
|
220
|
+
status: this.status,
|
|
221
|
+
now_time: this.now_time,
|
|
222
|
+
lastProps: this.lastProps,
|
|
223
|
+
nowProps: this.nowProps,
|
|
224
|
+
activeSyncs: this.activeSyncs.map((sync) => sync.serialize()),
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
static unserialize(animation, serialized) {
|
|
228
|
+
let node = new ActiveTrackNode(animation, {
|
|
229
|
+
accessKeys: serialized.accessKeys,
|
|
230
|
+
index: serialized.currentIndex,
|
|
231
|
+
initProps: serialized.lastProps,
|
|
232
|
+
});
|
|
233
|
+
node.lastProps = serialized.lastProps;
|
|
234
|
+
node.nowProps = serialized.nowProps;
|
|
235
|
+
node.status = serialized.status;
|
|
236
|
+
node.repeated = serialized.repeated;
|
|
237
|
+
node.now_time = serialized.now_time;
|
|
238
|
+
node.activeSyncs = serialized.activeSyncs.map((sync) => ActiveTrackNode.unserialize(animation, sync));
|
|
239
|
+
return node;
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
*
|
|
243
|
+
* @param delta_time
|
|
244
|
+
* @returns 剩餘的時間
|
|
245
|
+
*/
|
|
246
|
+
step(delta_time) {
|
|
247
|
+
// console.log(`node step: ${delta_time}`);
|
|
248
|
+
// if (this.status === ActiveTrackNode.Status.Pause) return delta_time;
|
|
249
|
+
// because we should proceed async list
|
|
250
|
+
// normal
|
|
251
|
+
if (!this.currentSection) {
|
|
252
|
+
this.status = ActiveTrackNode.Status.Pause;
|
|
253
|
+
return delta_time;
|
|
254
|
+
}
|
|
255
|
+
while (true) {
|
|
256
|
+
// constant field: time, wrapper, frame
|
|
257
|
+
// instant filed: syncs, asyncs
|
|
258
|
+
if (this.status === ActiveTrackNode.Status.Playing) {
|
|
259
|
+
if (this.currentSection.time === undefined ||
|
|
260
|
+
this.currentSection.time <= 0) {
|
|
261
|
+
this.nowProps = { ...this.nowProps, ...this.currentSection.frame };
|
|
262
|
+
}
|
|
263
|
+
else {
|
|
264
|
+
if (this.now_time + delta_time >= this.currentSection.time) {
|
|
265
|
+
// this.now_time = this.currentSection.time
|
|
266
|
+
delta_time -= this.currentSection.time - this.now_time;
|
|
267
|
+
this.nowProps = { ...this.nowProps, ...this.currentSection.frame };
|
|
268
|
+
}
|
|
269
|
+
else {
|
|
270
|
+
this.now_time += delta_time;
|
|
271
|
+
delta_time = 0;
|
|
272
|
+
// calc
|
|
273
|
+
let progress = this.now_time / this.currentSection.time;
|
|
274
|
+
// console.log(`progress: ${progress}`);
|
|
275
|
+
this.nowProps = this.animation._calcWrappedProps(this.lastProps, this.currentSection.frame ?? {}, this.currentSection.wrapper, progress);
|
|
276
|
+
break;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
// sync async
|
|
280
|
+
if (this.currentSection.syncs && this.currentSection.syncs.length > 0) {
|
|
281
|
+
this.initSyncs();
|
|
282
|
+
this.status = ActiveTrackNode.Status.WaitingSyncs;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
// step and check sync
|
|
286
|
+
if (this.status === ActiveTrackNode.Status.WaitingSyncs) {
|
|
287
|
+
delta_time = this.stepSyncs(delta_time); // returns lefted time
|
|
288
|
+
this.nowProps = Object.assign(this.nowProps, this.getSyncsProps());
|
|
289
|
+
if (this.checkSyncsFinished()) {
|
|
290
|
+
this.status = ActiveTrackNode.Status.Playing;
|
|
291
|
+
this.activeSyncs = [];
|
|
292
|
+
}
|
|
293
|
+
else {
|
|
294
|
+
// debug
|
|
295
|
+
if (delta_time !== 0)
|
|
296
|
+
throw "syncs not finished while lefted time != 0. may be bugs";
|
|
297
|
+
break;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
// check repeat , finish
|
|
301
|
+
if (this.currentSection.repeat !== undefined) {
|
|
302
|
+
this.repeated++;
|
|
303
|
+
if (this.repeated >= this.currentSection.repeat) {
|
|
304
|
+
// finish and proceed next section
|
|
305
|
+
// TODO
|
|
306
|
+
if (this._switchNextSection())
|
|
307
|
+
continue;
|
|
308
|
+
else
|
|
309
|
+
break;
|
|
310
|
+
}
|
|
311
|
+
else {
|
|
312
|
+
// continue this section
|
|
313
|
+
this.now_time = 0;
|
|
314
|
+
this.nowProps = { ...this.lastProps };
|
|
315
|
+
continue;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
else {
|
|
319
|
+
if (this._switchNextSection())
|
|
320
|
+
continue;
|
|
321
|
+
else
|
|
322
|
+
break;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
// waiting syncs
|
|
326
|
+
return delta_time;
|
|
327
|
+
}
|
|
328
|
+
calcProps() {
|
|
329
|
+
return this.nowProps;
|
|
330
|
+
}
|
|
331
|
+
_switchNextSection() {
|
|
332
|
+
if (this.currentIndex === null ||
|
|
333
|
+
this.currentTrack.length === this.currentIndex + 1) {
|
|
334
|
+
// already reach the end
|
|
335
|
+
this.status = ActiveTrackNode.Status.Pause;
|
|
336
|
+
return false;
|
|
337
|
+
}
|
|
338
|
+
else {
|
|
339
|
+
this.lastProps = { ...this.nowProps };
|
|
340
|
+
this.repeated = 0;
|
|
341
|
+
this.now_time = 0;
|
|
342
|
+
this.currentIndex++;
|
|
343
|
+
return true;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
activeSyncs = [];
|
|
347
|
+
initSyncs() {
|
|
348
|
+
// console.log("init syncs");
|
|
349
|
+
let activeSyncs = [];
|
|
350
|
+
// if (this.currentSection.syncs == null) return;
|
|
351
|
+
let subprofile = this.currentSection.syncs;
|
|
352
|
+
let activeTrackNode;
|
|
353
|
+
if (Array.isArray(subprofile)) {
|
|
354
|
+
if (subprofile.length > 0 && Array.isArray(subprofile[0])) {
|
|
355
|
+
// tracklist
|
|
356
|
+
for (let j = 0; j < subprofile.length; ++j) {
|
|
357
|
+
activeTrackNode = new ActiveTrackNode(this.animation, {
|
|
358
|
+
accessKeys: [
|
|
359
|
+
...this.accessKeys,
|
|
360
|
+
"" + this.currentIndex,
|
|
361
|
+
"syncs",
|
|
362
|
+
"" + j,
|
|
363
|
+
],
|
|
364
|
+
index: 0,
|
|
365
|
+
initProps: this.nowProps, // TODO 因为 lastProps在切换的时候才会更新,所以用nowProps
|
|
366
|
+
});
|
|
367
|
+
activeSyncs.push(activeTrackNode);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
else {
|
|
371
|
+
// Track
|
|
372
|
+
activeTrackNode = new ActiveTrackNode(this.animation, {
|
|
373
|
+
accessKeys: [...this.accessKeys, "" + this.currentIndex, "syncs"],
|
|
374
|
+
index: 0,
|
|
375
|
+
initProps: this.nowProps, // TODO 因为 lastProps在切换的时候才会更新,所以用nowProps
|
|
376
|
+
});
|
|
377
|
+
activeSyncs.push(activeTrackNode);
|
|
378
|
+
console
|
|
379
|
+
.log();
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
else {
|
|
383
|
+
// section
|
|
384
|
+
activeTrackNode = new ActiveTrackNode(this.animation, {
|
|
385
|
+
accessKeys: [...this.accessKeys, "" + this.currentIndex, "syncs"],
|
|
386
|
+
index: null,
|
|
387
|
+
initProps: this.nowProps, // TODO 因为 lastProps在切换的时候才会更新,所以用nowProps
|
|
388
|
+
});
|
|
389
|
+
activeSyncs.push(activeTrackNode);
|
|
390
|
+
}
|
|
391
|
+
// activeTrackNode?.step(0); // TODO
|
|
392
|
+
this.activeSyncs = activeSyncs;
|
|
393
|
+
}
|
|
394
|
+
stepSyncs(delta_time) {
|
|
395
|
+
let lefted_time = delta_time;
|
|
396
|
+
for (let i = 0; i < this.activeSyncs.length; ++i) {
|
|
397
|
+
lefted_time = Math.min(this.activeSyncs[i].step(delta_time), lefted_time);
|
|
398
|
+
}
|
|
399
|
+
return lefted_time;
|
|
400
|
+
}
|
|
401
|
+
checkSyncsFinished() {
|
|
402
|
+
for (let i = 0; i < this.activeSyncs.length; ++i) {
|
|
403
|
+
if (this.activeSyncs[i].status !== ActiveTrackNode.Status.Pause)
|
|
404
|
+
return false;
|
|
405
|
+
}
|
|
406
|
+
return true;
|
|
407
|
+
}
|
|
408
|
+
getSyncsProps() {
|
|
409
|
+
let res = {};
|
|
410
|
+
for (let i = 0; i < this.activeSyncs.length; ++i) {
|
|
411
|
+
Object.assign(res, this.activeSyncs[i].calcProps());
|
|
412
|
+
}
|
|
413
|
+
return res;
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
(function (ActiveTrackNode) {
|
|
417
|
+
let Status;
|
|
418
|
+
(function (Status) {
|
|
419
|
+
Status[Status["Playing"] = 0] = "Playing";
|
|
420
|
+
Status[Status["WaitingSyncs"] = 1] = "WaitingSyncs";
|
|
421
|
+
Status[Status["Pause"] = 2] = "Pause";
|
|
422
|
+
})(Status = ActiveTrackNode.Status || (ActiveTrackNode.Status = {}));
|
|
423
|
+
})(ActiveTrackNode || (ActiveTrackNode = {}));
|
|
424
|
+
const buildInWrappers = {
|
|
425
|
+
none: (x) => (x < 1 ? 0 : 1),
|
|
426
|
+
linear: (x) => x,
|
|
427
|
+
easeout: (x) => Math.pow(x, 3),
|
|
428
|
+
easein: (x) => 1 - Math.pow(1 - x, 3),
|
|
429
|
+
easeinout: (x) => x < 0.5 ? 0.5 * Math.pow(x, 3) : 1 - 0.5 * Math.pow(1 - x, 3),
|
|
430
|
+
};
|