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,211 +1,196 @@
|
|
|
1
|
-
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
2
|
-
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
3
|
-
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
4
|
-
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
5
|
-
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
6
|
-
var _, done = false;
|
|
7
|
-
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
8
|
-
var context = {};
|
|
9
|
-
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
10
|
-
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
11
|
-
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
12
|
-
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
13
|
-
if (kind === "accessor") {
|
|
14
|
-
if (result === void 0) continue;
|
|
15
|
-
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
16
|
-
if (_ = accept(result.get)) descriptor.get = _;
|
|
17
|
-
if (_ = accept(result.set)) descriptor.set = _;
|
|
18
|
-
if (_ = accept(result.init)) initializers.unshift(_);
|
|
19
|
-
}
|
|
20
|
-
else if (_ = accept(result)) {
|
|
21
|
-
if (kind === "field") initializers.unshift(_);
|
|
22
|
-
else descriptor[key] = _;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
26
|
-
done = true;
|
|
27
|
-
};
|
|
28
|
-
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
29
|
-
var useValue = arguments.length > 2;
|
|
30
|
-
for (var i = 0; i < initializers.length; i++) {
|
|
31
|
-
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
32
|
-
}
|
|
33
|
-
return useValue ? value : void 0;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
-
this.
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
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
|
-
destroyOnEnd: obj[id].destroyOnEnd,
|
|
198
|
-
isSave: obj[id].isSave,
|
|
199
|
-
targetViewId: obj[id].targetViewId,
|
|
200
|
-
instance: animation,
|
|
201
|
-
};
|
|
202
|
-
}
|
|
203
|
-
return res;
|
|
204
|
-
})];
|
|
205
|
-
__esDecorate(_a, null, __nextAnimationId_decorators, { kind: "accessor", name: "_nextAnimationId", static: false, private: false, access: { has: obj => "_nextAnimationId" in obj, get: obj => obj._nextAnimationId, set: (obj, value) => { obj._nextAnimationId = value; } }, metadata: _metadata }, __nextAnimationId_initializers, __nextAnimationId_extraInitializers);
|
|
206
|
-
__esDecorate(_a, null, __animationMap_decorators, { kind: "accessor", name: "_animationMap", static: false, private: false, access: { has: obj => "_animationMap" in obj, get: obj => obj._animationMap, set: (obj, value) => { obj._animationMap = value; } }, metadata: _metadata }, __animationMap_initializers, __animationMap_extraInitializers);
|
|
207
|
-
if (_metadata) Object.defineProperty(_a, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
208
|
-
})(),
|
|
209
|
-
_a;
|
|
210
|
-
})();
|
|
211
|
-
export { AnimationPlugin };
|
|
1
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
2
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
3
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
4
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
5
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
6
|
+
var _, done = false;
|
|
7
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
8
|
+
var context = {};
|
|
9
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
10
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
11
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
12
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
13
|
+
if (kind === "accessor") {
|
|
14
|
+
if (result === void 0) continue;
|
|
15
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
16
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
17
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
18
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
19
|
+
}
|
|
20
|
+
else if (_ = accept(result)) {
|
|
21
|
+
if (kind === "field") initializers.unshift(_);
|
|
22
|
+
else descriptor[key] = _;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
26
|
+
done = true;
|
|
27
|
+
};
|
|
28
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
29
|
+
var useValue = arguments.length > 2;
|
|
30
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
31
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
32
|
+
}
|
|
33
|
+
return useValue ? value : void 0;
|
|
34
|
+
};
|
|
35
|
+
import { Save, CustomSave, } from "../../storage/decorator.js";
|
|
36
|
+
import { Animation } from "./animation.js";
|
|
37
|
+
// import { Time } from "@zos/sensor";
|
|
38
|
+
let AnimationPlugin = (() => {
|
|
39
|
+
let __nextAnimationId_decorators;
|
|
40
|
+
let __nextAnimationId_initializers = [];
|
|
41
|
+
let __nextAnimationId_extraInitializers = [];
|
|
42
|
+
let __animationMap_decorators;
|
|
43
|
+
let __animationMap_initializers = [];
|
|
44
|
+
let __animationMap_extraInitializers = [];
|
|
45
|
+
return class AnimationPlugin {
|
|
46
|
+
static {
|
|
47
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
48
|
+
__nextAnimationId_decorators = [Save("anime.nid")];
|
|
49
|
+
__animationMap_decorators = [CustomSave("anime.map", function (obj) {
|
|
50
|
+
let res = {};
|
|
51
|
+
for (let id in obj) {
|
|
52
|
+
if (!obj[id].isSave)
|
|
53
|
+
continue;
|
|
54
|
+
res[id] = {
|
|
55
|
+
destroyOnEnd: obj[id].destroyOnEnd,
|
|
56
|
+
isSave: obj[id].isSave,
|
|
57
|
+
targetViewId: obj[id].targetViewId,
|
|
58
|
+
serializedInstance: obj[id].instance.serialize(),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
return res;
|
|
62
|
+
}, function (obj) {
|
|
63
|
+
let res = {};
|
|
64
|
+
for (let id in obj) {
|
|
65
|
+
if (!obj[id].isSave)
|
|
66
|
+
continue;
|
|
67
|
+
let animation = Animation.unserialize(obj[id].serializedInstance);
|
|
68
|
+
this._linkAnimationCb(animation, Number(id));
|
|
69
|
+
res[id] = {
|
|
70
|
+
destroyOnEnd: obj[id].destroyOnEnd,
|
|
71
|
+
isSave: obj[id].isSave,
|
|
72
|
+
targetViewId: obj[id].targetViewId,
|
|
73
|
+
instance: animation,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
return res;
|
|
77
|
+
})];
|
|
78
|
+
__esDecorate(this, null, __nextAnimationId_decorators, { kind: "accessor", name: "_nextAnimationId", static: false, private: false, access: { has: obj => "_nextAnimationId" in obj, get: obj => obj._nextAnimationId, set: (obj, value) => { obj._nextAnimationId = value; } }, metadata: _metadata }, __nextAnimationId_initializers, __nextAnimationId_extraInitializers);
|
|
79
|
+
__esDecorate(this, null, __animationMap_decorators, { kind: "accessor", name: "_animationMap", static: false, private: false, access: { has: obj => "_animationMap" in obj, get: obj => obj._animationMap, set: (obj, value) => { obj._animationMap = value; } }, metadata: _metadata }, __animationMap_initializers, __animationMap_extraInitializers);
|
|
80
|
+
if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
81
|
+
}
|
|
82
|
+
_core;
|
|
83
|
+
constructor(_core) {
|
|
84
|
+
this._core = _core;
|
|
85
|
+
console.log("[AnimationPlugin] init");
|
|
86
|
+
_core.loadPlugin("animation", () => this);
|
|
87
|
+
_core.on("anime.cb", this._timerCb.bind(this));
|
|
88
|
+
_core.async.addRepeatTask("anime.cb", [], 0); // 此處周期應考慮加個sync update
|
|
89
|
+
this._lastCbUtc = this._core.platform.getTime();
|
|
90
|
+
}
|
|
91
|
+
#_nextAnimationId_accessor_storage = __runInitializers(this, __nextAnimationId_initializers, 1);
|
|
92
|
+
get _nextAnimationId() { return this.#_nextAnimationId_accessor_storage; } // self-increment
|
|
93
|
+
set _nextAnimationId(value) { this.#_nextAnimationId_accessor_storage = value; }
|
|
94
|
+
#_animationMap_accessor_storage = (__runInitializers(this, __nextAnimationId_extraInitializers), __runInitializers(this, __animationMap_initializers, {}));
|
|
95
|
+
get _animationMap() { return this.#_animationMap_accessor_storage; }
|
|
96
|
+
set _animationMap(value) { this.#_animationMap_accessor_storage = value; }
|
|
97
|
+
// private _timeSensor = new Time();
|
|
98
|
+
_lastCbUtc = __runInitializers(this, __animationMap_extraInitializers);
|
|
99
|
+
applyAnimation({ profile, targetView, options, }) {
|
|
100
|
+
const id = this._nextAnimationId++;
|
|
101
|
+
let animation = new Animation(profile, {
|
|
102
|
+
// @ts-ignore
|
|
103
|
+
initProps: targetView.prop ?? {},
|
|
104
|
+
wrappers: options?.customWrappers,
|
|
105
|
+
});
|
|
106
|
+
if (!targetView.id)
|
|
107
|
+
throw "targetView.id must be not null";
|
|
108
|
+
this._animationMap[id] = {
|
|
109
|
+
destroyOnEnd: options?.destroyOnEnd ?? false,
|
|
110
|
+
isSave: options?.isSave ?? true,
|
|
111
|
+
instance: animation,
|
|
112
|
+
targetViewId: targetView.id,
|
|
113
|
+
};
|
|
114
|
+
this._linkAnimationCb(animation, id);
|
|
115
|
+
animation.goto(0);
|
|
116
|
+
this._core.on("afterLoadArchive", () => {
|
|
117
|
+
this._lastCbUtc = this._core.platform.getTime();
|
|
118
|
+
});
|
|
119
|
+
return id;
|
|
120
|
+
}
|
|
121
|
+
stopAnimation(id) {
|
|
122
|
+
if (this._animationMap[id] !== undefined) {
|
|
123
|
+
this._animationMap[id].instance.stop();
|
|
124
|
+
delete this._animationMap[id];
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
_nextTempAnimationId = -1; // self-decrement
|
|
128
|
+
_tempAnimationMap = {};
|
|
129
|
+
createTempAnimation({ profile, onFrame, onEnd, initProps, wrappers, }) {
|
|
130
|
+
let id = this._nextTempAnimationId--;
|
|
131
|
+
let animation = new Animation(profile, {
|
|
132
|
+
initProps,
|
|
133
|
+
wrappers,
|
|
134
|
+
});
|
|
135
|
+
animation.onFrame = onFrame ?? null;
|
|
136
|
+
animation.onEnd = () => {
|
|
137
|
+
if (onEnd)
|
|
138
|
+
onEnd();
|
|
139
|
+
delete this._tempAnimationMap[id];
|
|
140
|
+
};
|
|
141
|
+
this._tempAnimationMap[id] = animation;
|
|
142
|
+
return id;
|
|
143
|
+
}
|
|
144
|
+
clearTempAnimation(id) {
|
|
145
|
+
if (this._tempAnimationMap[id] !== undefined) {
|
|
146
|
+
this._tempAnimationMap[id].stop();
|
|
147
|
+
delete this._tempAnimationMap[id];
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
_timerCb() {
|
|
151
|
+
let utc = this._core.platform.getTime();
|
|
152
|
+
let delta_time = (utc - this._lastCbUtc) / 1000;
|
|
153
|
+
this._lastCbUtc = utc;
|
|
154
|
+
// this._core.debug.log(`delta time: ${delta_time}`);
|
|
155
|
+
for (let id in this._animationMap) {
|
|
156
|
+
this._animationMap[id].instance.step(delta_time);
|
|
157
|
+
}
|
|
158
|
+
for (let id in this._tempAnimationMap) {
|
|
159
|
+
this._tempAnimationMap[id].step(delta_time);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
_frameCb(props, id) {
|
|
163
|
+
if (this._animationMap[id] !== undefined) {
|
|
164
|
+
let view = this._core.ui.getView(this._animationMap[id].targetViewId);
|
|
165
|
+
if (!view) {
|
|
166
|
+
this._core.debug.log(`view ${id} not found, stop animation`);
|
|
167
|
+
this.stopAnimation(id); // TODO
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
view.commit(props);
|
|
171
|
+
// this._core.debug.log(`update view ${view.name} with ${JSON.stringify(props)}`);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
_linkAnimationCb(animation, id) {
|
|
175
|
+
animation.onFrame = (props) => {
|
|
176
|
+
// console.log("onFrame cb");
|
|
177
|
+
this._frameCb(props, id);
|
|
178
|
+
};
|
|
179
|
+
animation.onEnd = () => this._endCb(id);
|
|
180
|
+
}
|
|
181
|
+
_endCb(id) {
|
|
182
|
+
if (this._animationMap[id] !== undefined) {
|
|
183
|
+
if (this._animationMap[id].destroyOnEnd) {
|
|
184
|
+
let view = this._core.ui.getView(id);
|
|
185
|
+
if (view)
|
|
186
|
+
this._core.ui.destroyView(view);
|
|
187
|
+
}
|
|
188
|
+
delete this._animationMap[id];
|
|
189
|
+
console.log("map item", this._animationMap[id]);
|
|
190
|
+
}
|
|
191
|
+
else
|
|
192
|
+
console.log("nf map item", this._animationMap[id]);
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
})();
|
|
196
|
+
export { AnimationPlugin };
|
|
@@ -1,93 +1,94 @@
|
|
|
1
|
-
import { AnimationPlugin } from "./hz_anime.js";
|
|
2
|
-
import { Animation, Profile } from "./animation.js";
|
|
3
|
-
// import hmFS from "@zos/fs";
|
|
4
|
-
import { getTransitionMap, registerHzscriptCommands } from "./commands.js";
|
|
5
|
-
export function registerPlugin(core) {
|
|
6
|
-
let animationPlugin = new AnimationPlugin(core);
|
|
7
|
-
let profileMap = {};
|
|
8
|
-
registerHzscriptCommands(core);
|
|
9
|
-
core.on("afterLoadProject", () => {
|
|
10
|
-
profileMap = core.storage.getSaveableData(core.storage.preloadedData, false, "animation", "profileMap");
|
|
11
|
-
});
|
|
12
|
-
function getProfile(name) {
|
|
13
|
-
let profile_item = profileMap[name];
|
|
14
|
-
if (!profile_item) {
|
|
15
|
-
core.debug.log(`Animation profile [${name}] not found`);
|
|
16
|
-
return null;
|
|
17
|
-
}
|
|
18
|
-
let str = core.platform.readFileSync({
|
|
19
|
-
path: profile_item[0],
|
|
20
|
-
options: {
|
|
21
|
-
encoding: "utf8",
|
|
22
|
-
},
|
|
23
|
-
});
|
|
24
|
-
if (typeof str !== "string") {
|
|
25
|
-
core.debug.log(`Animation profile file [${name}] not found`);
|
|
26
|
-
return null;
|
|
27
|
-
}
|
|
28
|
-
try {
|
|
29
|
-
return JSON.parse(str);
|
|
30
|
-
}
|
|
31
|
-
catch (error) {
|
|
32
|
-
core.debug.log(`Animation profile file [${name}] parse error:`, error);
|
|
33
|
-
}
|
|
34
|
-
return null;
|
|
35
|
-
}
|
|
36
|
-
function applyTransform(names, target, isSave = false, destroyOnEnd = false) {
|
|
37
|
-
let profile = null;
|
|
38
|
-
if (names.length === 1) {
|
|
39
|
-
profile = getProfile(names[0]);
|
|
40
|
-
}
|
|
41
|
-
else if (names.length > 1) {
|
|
42
|
-
let syncs = [];
|
|
43
|
-
for (let i = 0; i < names.length; i++) {
|
|
44
|
-
let profile = getProfile(names[i]);
|
|
45
|
-
if (profile)
|
|
46
|
-
syncs.push(profile);
|
|
47
|
-
}
|
|
48
|
-
profile = { syncs };
|
|
49
|
-
}
|
|
50
|
-
if (!profile)
|
|
51
|
-
profile = [];
|
|
52
|
-
animationPlugin.applyAnimation({
|
|
53
|
-
profile,
|
|
54
|
-
targetView: target,
|
|
55
|
-
options: {
|
|
56
|
-
isSave,
|
|
57
|
-
destroyOnEnd,
|
|
58
|
-
},
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
class TransformRouteStrategy {
|
|
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
|
-
|
|
1
|
+
import { AnimationPlugin } from "./hz_anime.js";
|
|
2
|
+
import { Animation, Profile } from "./animation.js";
|
|
3
|
+
// import hmFS from "@zos/fs";
|
|
4
|
+
import { getTransitionMap, registerHzscriptCommands } from "./commands.js";
|
|
5
|
+
export function registerPlugin(core) {
|
|
6
|
+
let animationPlugin = new AnimationPlugin(core);
|
|
7
|
+
let profileMap = {};
|
|
8
|
+
registerHzscriptCommands(core);
|
|
9
|
+
core.on("afterLoadProject", () => {
|
|
10
|
+
profileMap = core.storage.getSaveableData(core.storage.preloadedData, false, "animation", "profileMap");
|
|
11
|
+
});
|
|
12
|
+
function getProfile(name) {
|
|
13
|
+
let profile_item = profileMap[name];
|
|
14
|
+
if (!profile_item) {
|
|
15
|
+
core.debug.log(`Animation profile [${name}] not found`);
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
let str = core.platform.readFileSync({
|
|
19
|
+
path: profile_item[0],
|
|
20
|
+
options: {
|
|
21
|
+
encoding: "utf8",
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
if (typeof str !== "string") {
|
|
25
|
+
core.debug.log(`Animation profile file [${name}] not found`);
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
return JSON.parse(str);
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
core.debug.log(`Animation profile file [${name}] parse error:`, error);
|
|
33
|
+
}
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
function applyTransform(names, target, isSave = false, destroyOnEnd = false) {
|
|
37
|
+
let profile = null;
|
|
38
|
+
if (names.length === 1) {
|
|
39
|
+
profile = getProfile(names[0]);
|
|
40
|
+
}
|
|
41
|
+
else if (names.length > 1) {
|
|
42
|
+
let syncs = [];
|
|
43
|
+
for (let i = 0; i < names.length; i++) {
|
|
44
|
+
let profile = getProfile(names[i]);
|
|
45
|
+
if (profile)
|
|
46
|
+
syncs.push(profile);
|
|
47
|
+
}
|
|
48
|
+
profile = { syncs };
|
|
49
|
+
}
|
|
50
|
+
if (!profile)
|
|
51
|
+
profile = [];
|
|
52
|
+
animationPlugin.applyAnimation({
|
|
53
|
+
profile,
|
|
54
|
+
targetView: target,
|
|
55
|
+
options: {
|
|
56
|
+
isSave,
|
|
57
|
+
destroyOnEnd,
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
class TransformRouteStrategy {
|
|
62
|
+
outTransforms;
|
|
63
|
+
inTransforms;
|
|
64
|
+
constructor(outTransforms, inTransforms) {
|
|
65
|
+
this.outTransforms = outTransforms;
|
|
66
|
+
this.inTransforms = inTransforms;
|
|
67
|
+
}
|
|
68
|
+
create(viewName, layer, prop, ui, isSave) {
|
|
69
|
+
let view = ui.createView(viewName, layer, prop, isSave);
|
|
70
|
+
this.inTransforms && applyTransform(this.inTransforms, view, isSave);
|
|
71
|
+
return view;
|
|
72
|
+
}
|
|
73
|
+
destroy(viewInstance, ui) {
|
|
74
|
+
if (this.outTransforms) {
|
|
75
|
+
applyTransform(this.outTransforms, viewInstance, viewInstance.isSave, true);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
ui.destroyView(viewInstance);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
applyTransform,
|
|
84
|
+
getProfile,
|
|
85
|
+
createStrategy(outTransforms, inTransforms) {
|
|
86
|
+
return new TransformRouteStrategy(outTransforms, inTransforms);
|
|
87
|
+
},
|
|
88
|
+
animationPlugin,
|
|
89
|
+
getTransition(name) {
|
|
90
|
+
return getTransitionMap(core)[name] ?? null;
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
export { Animation, Profile, AnimationPlugin };
|