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