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,249 +1,247 @@
|
|
|
1
|
-
// / <reference types="@zeppos/device-types" />
|
|
2
|
-
// import hmUI from "@zos/ui";
|
|
3
|
-
import { Async, Script } from "../../index.js";
|
|
4
|
-
export function img(core) {
|
|
5
|
-
let transform_plugin = core.plugins.get("transform");
|
|
6
|
-
if (!transform_plugin)
|
|
7
|
-
core.debug.log("[IMG Plugin] Info: Transform plugin not set up");
|
|
8
|
-
// show command
|
|
9
|
-
core.script.use((ctx, next) => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
let
|
|
21
|
-
let
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
let
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
core.ui.
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
ctx.slicedArgs
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
let
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
if (ctx.
|
|
88
|
-
|
|
89
|
-
if (ctx.slicedArgs.length ===
|
|
90
|
-
throw `Scene Command: incorrect amount of args`;
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
let
|
|
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
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
//
|
|
147
|
-
//
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
let
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
let
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
let
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
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
|
-
// };
|
|
249
|
-
}
|
|
1
|
+
// / <reference types="@zeppos/device-types" />
|
|
2
|
+
// import hmUI from "@zos/ui";
|
|
3
|
+
import { Async, Script } from "../../index.js";
|
|
4
|
+
export function img(core) {
|
|
5
|
+
let transform_plugin = core.plugins.get("transform");
|
|
6
|
+
if (!transform_plugin)
|
|
7
|
+
core.debug.log("[IMG Plugin] Info: Transform plugin not set up");
|
|
8
|
+
// show command
|
|
9
|
+
core.script.use((ctx, next) => {
|
|
10
|
+
if (ctx.rawtext.trim().split(" ")[0].toLowerCase() !== "show")
|
|
11
|
+
return next();
|
|
12
|
+
if (ctx.slicedArgs.length === 1)
|
|
13
|
+
throw `Show Command: incorrect amount of args`;
|
|
14
|
+
if (ctx.slicedArgs.length === 2)
|
|
15
|
+
throw `Show Command: incorrect amount of args`;
|
|
16
|
+
let parsedRes = parseImgCommandFields(ctx);
|
|
17
|
+
// update args to no fields
|
|
18
|
+
ctx.slicedArgs = parsedRes.leftedArgs;
|
|
19
|
+
let tag = ctx.slicedArgs[1].str;
|
|
20
|
+
let name_key = "";
|
|
21
|
+
for (let i = 1; i < ctx.slicedArgs.length; ++i) {
|
|
22
|
+
name_key += ctx.slicedArgs[i].str + " ";
|
|
23
|
+
}
|
|
24
|
+
name_key = name_key.trim().toLowerCase();
|
|
25
|
+
let path = core.storage.preloadedData.image.nameMap[name_key]?.[0];
|
|
26
|
+
if (!path)
|
|
27
|
+
throw `Show Command: image with name_key [${name_key}] not found `;
|
|
28
|
+
// let size = (hmUI as any).getImageInfo(path);
|
|
29
|
+
let size = core.platform.getImageInfo(path);
|
|
30
|
+
console.log(`IMG: path: ${path}, size: ${JSON.stringify(size)}`);
|
|
31
|
+
if (!size)
|
|
32
|
+
throw `Show Command: read size of [${path}] failed`;
|
|
33
|
+
showAction(tag, path, size, parsedRes.strategy);
|
|
34
|
+
});
|
|
35
|
+
function showAction(tag, path, size, routerStrategy) {
|
|
36
|
+
const show_view_tag_prefix = "hzengine.img";
|
|
37
|
+
const show_view_name = "fg_img";
|
|
38
|
+
let prop = {
|
|
39
|
+
imgPath: path,
|
|
40
|
+
offset: {
|
|
41
|
+
x: 0,
|
|
42
|
+
y: 0,
|
|
43
|
+
},
|
|
44
|
+
size: {
|
|
45
|
+
width: size.width,
|
|
46
|
+
height: size.height,
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
let tag_prefixed = `${show_view_tag_prefix}.${tag}`;
|
|
50
|
+
let router = core.ui.getRouter(tag_prefixed);
|
|
51
|
+
if (!router) {
|
|
52
|
+
core.ui.addRouter(tag_prefixed, "fg");
|
|
53
|
+
router = core.ui.getRouter(tag_prefixed);
|
|
54
|
+
}
|
|
55
|
+
Async.nextTick(() => {
|
|
56
|
+
// @ts-ignore
|
|
57
|
+
router.replace(show_view_name, prop, routerStrategy ?? undefined);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
// hide command
|
|
61
|
+
core.script.use((ctx, next) => {
|
|
62
|
+
if (ctx.rawtext.trim().split(" ")[0].toLowerCase() !== "hide")
|
|
63
|
+
return next();
|
|
64
|
+
let parsedRes = parseImgCommandFields(ctx);
|
|
65
|
+
ctx.slicedArgs = parsedRes.leftedArgs;
|
|
66
|
+
if (ctx.slicedArgs.length !== 2) {
|
|
67
|
+
throw `Hide Command: incorrect amount of args`;
|
|
68
|
+
}
|
|
69
|
+
let tag = ctx.slicedArgs[1].str;
|
|
70
|
+
hideAction(tag, parsedRes.strategy);
|
|
71
|
+
});
|
|
72
|
+
function hideAction(tag, routerStrategy) {
|
|
73
|
+
const show_view_tag_prefix = "hzengine.img";
|
|
74
|
+
let tag_prefixed = `${show_view_tag_prefix}.${tag}`;
|
|
75
|
+
let router = core.ui.getRouter(tag_prefixed);
|
|
76
|
+
if (!router) {
|
|
77
|
+
throw `Hide Command: router with tag [${tag}] not found `;
|
|
78
|
+
}
|
|
79
|
+
Async.nextTick(() => {
|
|
80
|
+
router.clear(routerStrategy ?? undefined);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
// scene command
|
|
84
|
+
core.script.use((ctx, next) => {
|
|
85
|
+
if (ctx.rawtext.trim().split(" ")[0].toLowerCase() !== "scene")
|
|
86
|
+
return next();
|
|
87
|
+
if (ctx.slicedArgs.length === 1)
|
|
88
|
+
throw `Scene Command: incorrect amount of args`;
|
|
89
|
+
if (ctx.slicedArgs.length === 2)
|
|
90
|
+
throw `Scene Command: incorrect amount of args`;
|
|
91
|
+
let parsedRes = parseImgCommandFields(ctx);
|
|
92
|
+
// update args to no fields
|
|
93
|
+
ctx.slicedArgs = parsedRes.leftedArgs;
|
|
94
|
+
let tag = ctx.slicedArgs[1].str;
|
|
95
|
+
let name_key = "";
|
|
96
|
+
for (let i = 1; i < ctx.slicedArgs.length; ++i) {
|
|
97
|
+
name_key += ctx.slicedArgs[i].str + " ";
|
|
98
|
+
}
|
|
99
|
+
name_key = name_key.trim().toLowerCase();
|
|
100
|
+
let path = core.storage.preloadedData.image.nameMap[name_key]?.[0];
|
|
101
|
+
if (!path)
|
|
102
|
+
throw `Scene Command: image with name_key [${name_key}] not found `;
|
|
103
|
+
// let size = (hmUI as any).getImageInfo(path);
|
|
104
|
+
let size = core.platform.getImageInfo(path);
|
|
105
|
+
if (!size)
|
|
106
|
+
throw `Scene Command: read size of [${path}] failed`;
|
|
107
|
+
sceneAction(tag, path, size, parsedRes.strategy);
|
|
108
|
+
});
|
|
109
|
+
function sceneAction(tag, path, size, routerStrategy) {
|
|
110
|
+
const scene_view_tag_prefix = "hzengine.img";
|
|
111
|
+
const scene_view_name = "bg_img";
|
|
112
|
+
let prop = {
|
|
113
|
+
imgPath: path,
|
|
114
|
+
offset: {
|
|
115
|
+
x: 0,
|
|
116
|
+
y: 0,
|
|
117
|
+
},
|
|
118
|
+
size: {
|
|
119
|
+
width: size.width,
|
|
120
|
+
height: size.height,
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
let tag_prefixed = `${scene_view_tag_prefix}.${tag}`;
|
|
124
|
+
let router = core.ui.getRouter(tag_prefixed);
|
|
125
|
+
if (!router) {
|
|
126
|
+
core.ui.addRouter(tag_prefixed, "bg");
|
|
127
|
+
router = core.ui.getRouter(tag_prefixed);
|
|
128
|
+
}
|
|
129
|
+
if (!router.length) {
|
|
130
|
+
// @ts-ignore
|
|
131
|
+
Async.nextTick(() => {
|
|
132
|
+
// @ts-ignore
|
|
133
|
+
router.push(scene_view_name, prop, routerStrategy ?? undefined);
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
// @ts-ignore
|
|
138
|
+
Async.nextTick(() => {
|
|
139
|
+
// @ts-ignore
|
|
140
|
+
router.update(prop, routerStrategy ?? undefined);
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
// with
|
|
145
|
+
// at
|
|
146
|
+
// wait
|
|
147
|
+
// nowait
|
|
148
|
+
function parseImgCommandFields(ctx) {
|
|
149
|
+
let slicedArgs = JSON.parse(JSON.stringify(ctx.slicedArgs)); // TODO 深拷贝 性能
|
|
150
|
+
// TODO 注意这里的代码超级高耦合
|
|
151
|
+
let res = {
|
|
152
|
+
strategy: null,
|
|
153
|
+
wait: false,
|
|
154
|
+
leftedArgs: slicedArgs,
|
|
155
|
+
};
|
|
156
|
+
// wait/nowait
|
|
157
|
+
if (slicedArgs[slicedArgs.length - 1].str === "wait") {
|
|
158
|
+
res.wait = true;
|
|
159
|
+
slicedArgs.pop();
|
|
160
|
+
}
|
|
161
|
+
else if (slicedArgs[slicedArgs.length - 1].str === "nowait") {
|
|
162
|
+
res.wait = false;
|
|
163
|
+
slicedArgs.pop();
|
|
164
|
+
}
|
|
165
|
+
// parse long fields
|
|
166
|
+
let keywords = ["with", "at"];
|
|
167
|
+
let inTransforms = [];
|
|
168
|
+
let outTransforms = [];
|
|
169
|
+
while (true) {
|
|
170
|
+
// console.log(`slicedArgs: ${JSON.stringify(slicedArgs)}`);
|
|
171
|
+
let keyword_index = findLastIndex(slicedArgs, (slicedArg) => !slicedArg.isQuoted &&
|
|
172
|
+
!slicedArg.isSquared &&
|
|
173
|
+
keywords.includes(slicedArg.str));
|
|
174
|
+
if (keyword_index === -1)
|
|
175
|
+
break;
|
|
176
|
+
let keyword = slicedArgs[keyword_index].str;
|
|
177
|
+
let currentFieldArgs = slicedArgs.splice(keyword_index, slicedArgs.length - keyword_index);
|
|
178
|
+
currentFieldArgs.shift();
|
|
179
|
+
if (keyword === "at") {
|
|
180
|
+
inTransforms.push(...Script.Utils.splitCommas(Script.Utils.joinSlicedArgs(currentFieldArgs)));
|
|
181
|
+
}
|
|
182
|
+
else if (keyword === "with") {
|
|
183
|
+
let args = Script.Utils.parseHzsArgs(Script.Utils.joinSlicedArgs(currentFieldArgs));
|
|
184
|
+
// console.log(`with args: ${JSON.stringify(args)}`);
|
|
185
|
+
for (let i = 0; i < args.length; i++) {
|
|
186
|
+
if (Array.isArray(args[i])) {
|
|
187
|
+
// Annoymous Transition Tuple
|
|
188
|
+
if (args[i].length > 2)
|
|
189
|
+
throw `Invalid Annoymous Transition Tuple: ${JSON.stringify(args[i])}`;
|
|
190
|
+
console.log(`Annoymous Transition Tuple: ${JSON.stringify(args[i])}`);
|
|
191
|
+
if (args[i].length >= 1) {
|
|
192
|
+
if (Array.isArray(args[i][0])) {
|
|
193
|
+
outTransforms.push(...args[i][0]);
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
outTransforms.push(args[i][0]);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
if (args[i].length >= 2) {
|
|
200
|
+
if (Array.isArray(args[i][1])) {
|
|
201
|
+
inTransforms.push(...args[i][1]);
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
inTransforms.push(args[i][1]);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
// Named Transition
|
|
210
|
+
let transition = transform_plugin.getTransition(args[i]);
|
|
211
|
+
if (!transition) {
|
|
212
|
+
core.debug.log(`Transition ${args[i]} not found`);
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
core.debug.log(`Transition ${args[i]} = ${JSON.stringify(transition)}`);
|
|
217
|
+
inTransforms.push(...transition.inTransforms);
|
|
218
|
+
outTransforms.push(...transition.outTransforms);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
// let withField: WithField = {
|
|
225
|
+
// outTransform: ctx.slicedArgs[withIndex + 1]?.str ?? null,
|
|
226
|
+
// inTransform: ctx.slicedArgs[withIndex + 2]?.str ?? null,
|
|
227
|
+
// };
|
|
228
|
+
res.strategy = transform_plugin.createStrategy(outTransforms.length ? outTransforms : null, inTransforms.length ? inTransforms : null);
|
|
229
|
+
return res;
|
|
230
|
+
}
|
|
231
|
+
function findLastIndex(array, predicator) {
|
|
232
|
+
for (let i = array.length - 1; i >= 0; i--) {
|
|
233
|
+
if (predicator(array[i])) {
|
|
234
|
+
return i;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return -1;
|
|
238
|
+
}
|
|
239
|
+
const slicedArgsToTransforms = (slicedArgs) => Script.Utils.joinSlicedArgs(slicedArgs)
|
|
240
|
+
.split(",")
|
|
241
|
+
.map((str) => str.trim())
|
|
242
|
+
.filter((str) => str.length > 0);
|
|
243
|
+
// type WithField = {
|
|
244
|
+
// inTransform: string | null;
|
|
245
|
+
// outTransform: string | null;
|
|
246
|
+
// };
|
|
247
|
+
}
|