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
package/package.json
CHANGED
package/src/platform/index.ts
CHANGED
|
@@ -12,15 +12,20 @@ export interface Platform<WidgetFactory = any> {
|
|
|
12
12
|
isFileSync({ path }: { path: string }): boolean;
|
|
13
13
|
readdirSync(option: Platform.readdirSync.Option): Platform.readdirSync.Result;
|
|
14
14
|
statSync(option: Platform.statSync.Option): Platform.statSync.Result;
|
|
15
|
-
readFileSync(
|
|
15
|
+
readFileSync(
|
|
16
|
+
option: Platform.readFileSync.Option
|
|
17
|
+
): Platform.readFileSync.Result;
|
|
16
18
|
writeFileSync(option: Platform.writeFileSync.Option): void;
|
|
17
19
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
getImageInfo(img_path: string):
|
|
21
|
+
| {
|
|
22
|
+
width: number;
|
|
23
|
+
height: number;
|
|
24
|
+
}
|
|
25
|
+
| Promise<{
|
|
26
|
+
width: number;
|
|
27
|
+
height: number;
|
|
28
|
+
}>;
|
|
24
29
|
|
|
25
30
|
// timer & async
|
|
26
31
|
getTime(): number; // in Utc
|
|
@@ -33,8 +38,6 @@ export interface Platform<WidgetFactory = any> {
|
|
|
33
38
|
}
|
|
34
39
|
|
|
35
40
|
export declare namespace Platform {
|
|
36
|
-
|
|
37
|
-
|
|
38
41
|
export interface AudioPlayer {
|
|
39
42
|
onPrepared?: (success: boolean) => void | undefined;
|
|
40
43
|
onCompleted?: () => void | undefined;
|
|
@@ -43,7 +46,7 @@ export declare namespace Platform {
|
|
|
43
46
|
stop(): void;
|
|
44
47
|
release(): void;
|
|
45
48
|
getMediaInfo(): MediaInfo;
|
|
46
|
-
setSource({ path }: { path: string }): void;
|
|
49
|
+
setSource({ path }: { path: string }): void; //TODO path? file?
|
|
47
50
|
}
|
|
48
51
|
|
|
49
52
|
export interface MediaInfo {
|
|
@@ -154,5 +157,4 @@ export declare namespace Platform {
|
|
|
154
157
|
}
|
|
155
158
|
}
|
|
156
159
|
|
|
157
|
-
|
|
158
|
-
export default Platform;
|
|
160
|
+
export default Platform;
|
|
@@ -146,7 +146,7 @@ export class Animation<P extends Profile.PropsType = unknown> {
|
|
|
146
146
|
if (typeof props[key] === "number") {
|
|
147
147
|
if (_former_props[key] == undefined) _former_props[key] = 0;
|
|
148
148
|
res[key] =
|
|
149
|
-
_former_props[key] + wraped_prog * (props[key] - _former_props[key]);
|
|
149
|
+
_former_props[key] + wraped_prog * ((props[key] as any) - _former_props[key]);
|
|
150
150
|
} else if (typeof props[key] === "boolean") {
|
|
151
151
|
if (_former_props[key] == undefined) _former_props[key] = false;
|
|
152
152
|
res[key] = wraped_prog === 1 ? props[key] : _former_props[key];
|
package/src/script/index.ts
CHANGED
|
@@ -36,6 +36,18 @@ export class Script {
|
|
|
36
36
|
private accessor _nextRunPosition: [path: string, index: number] | null =
|
|
37
37
|
null;
|
|
38
38
|
|
|
39
|
+
public get nextRunPosition() {
|
|
40
|
+
return this._nextRunPosition;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* 当前正在执行的命令内容
|
|
45
|
+
*/
|
|
46
|
+
private _currentRawCommand: string = "-";
|
|
47
|
+
public get currentRawCommand() {
|
|
48
|
+
return this._currentRawCommand;
|
|
49
|
+
}
|
|
50
|
+
|
|
39
51
|
// Script Run
|
|
40
52
|
|
|
41
53
|
/**
|
|
@@ -61,6 +73,7 @@ export class Script {
|
|
|
61
73
|
// remove comment
|
|
62
74
|
|
|
63
75
|
rawCommand = removeComment(rawCommand);
|
|
76
|
+
this._currentRawCommand = rawCommand.trim();
|
|
64
77
|
|
|
65
78
|
if (rawCommand.trim().length && !rawCommand.trim().startsWith("#")) {
|
|
66
79
|
if (rawCommand.trim().startsWith("*")) {
|
package/src/storage/index.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { HZEngineCore, Platform } from "../index.js";
|
|
|
4
4
|
import Path from "../utils/path.js";
|
|
5
5
|
// import { isFileSync } from "./fs.js";
|
|
6
6
|
|
|
7
|
-
export class Storage{
|
|
7
|
+
export class Storage {
|
|
8
8
|
constructor(private _core: HZEngineCore) {}
|
|
9
9
|
|
|
10
10
|
projectRoot: string | null = null;
|
|
@@ -354,53 +354,55 @@ export class Storage{
|
|
|
354
354
|
if (!this._core.platform.readdirSync({ path: scriptDir }))
|
|
355
355
|
throw "项目文件夹中script文件夹不存在";
|
|
356
356
|
|
|
357
|
-
|
|
358
|
-
/**
|
|
357
|
+
/**
|
|
359
358
|
* 1. 预加载所有的label并检查冲突
|
|
360
359
|
* 2. 记录所有脚本文件的行数
|
|
361
360
|
*/
|
|
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
|
-
|
|
361
|
+
const preloadHzs = (path: string) => {
|
|
362
|
+
// let fd = this._core.platform.openSync({ path });
|
|
363
|
+
// if (fd < 0) throw "Fd<0";
|
|
364
|
+
// let size = this._core.platform.statSync({ path })!.size;
|
|
365
|
+
// let arrbuf = new ArrayBuffer(size);
|
|
366
|
+
// this._core.platform.readSync({ fd, buffer: arrbuf });
|
|
367
|
+
// let buffer = Buffer.from(arrbuf);
|
|
368
|
+
// let contentStr = buffer.toString();
|
|
369
|
+
let contentStr = this._core.platform.readFileSync({
|
|
370
|
+
path,
|
|
371
|
+
options: { encoding: "utf8" },
|
|
372
|
+
}) as string;
|
|
373
|
+
let contentLines = contentStr.split("\n");
|
|
374
|
+
let totalLines = contentLines.length;
|
|
375
|
+
hzsInfoMap[path] = { totalLines };
|
|
376
|
+
for (let i = 0; i < totalLines; ++i) {
|
|
377
|
+
let line = contentLines[i].trim();
|
|
378
|
+
if (line.startsWith("*")) {
|
|
379
|
+
let len = line.length,
|
|
380
|
+
p = 1,
|
|
381
|
+
q;
|
|
382
|
+
while (p < len && line.charAt(p) === " ") ++p;
|
|
383
|
+
if (p === len)
|
|
384
|
+
throw `Lost Label Name at file(${path}) line(${i + 1})`;
|
|
385
|
+
q = p;
|
|
386
|
+
while (q < len && line.charAt(q) !== " ") ++q;
|
|
387
|
+
// [p, q)
|
|
388
|
+
let label = line.slice(p, q);
|
|
389
|
+
|
|
390
|
+
if (labelMap[label]) {
|
|
391
|
+
throw `Label name "${label}" conflict : \
|
|
390
392
|
at [${labelMap[label][0]}(line ${labelMap[label][1]})] \
|
|
391
393
|
[${path}(line ${i + 1})]`;
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
labelMap[label] = [path, i];
|
|
395
|
-
}
|
|
396
394
|
}
|
|
395
|
+
|
|
396
|
+
labelMap[label] = [path, i];
|
|
397
397
|
}
|
|
398
|
+
}
|
|
399
|
+
};
|
|
398
400
|
|
|
399
401
|
// 遍历所有hzs文件
|
|
400
402
|
const traverseScript = (path: string) => {
|
|
401
403
|
let dirs = this._core.platform.readdirSync({ path });
|
|
402
404
|
// console.log(dirs);
|
|
403
|
-
|
|
405
|
+
|
|
404
406
|
for (let dir of dirs!) {
|
|
405
407
|
let subpath = Path.join(path, dir);
|
|
406
408
|
if (this._core.platform.isFileSync({ path: subpath })) {
|
|
@@ -413,10 +415,8 @@ export class Storage{
|
|
|
413
415
|
traverseScript(subpath);
|
|
414
416
|
}
|
|
415
417
|
}
|
|
416
|
-
}
|
|
418
|
+
};
|
|
417
419
|
traverseScript(scriptDir);
|
|
418
|
-
|
|
419
|
-
|
|
420
420
|
}
|
|
421
421
|
/**
|
|
422
422
|
* 预加载资源
|
|
@@ -448,7 +448,7 @@ export class Storage{
|
|
|
448
448
|
const traverseImage = (path: string) => {
|
|
449
449
|
let dirs = this._core.platform.readdirSync({ path });
|
|
450
450
|
// console.log(dirs);
|
|
451
|
-
|
|
451
|
+
|
|
452
452
|
for (let dir of dirs!) {
|
|
453
453
|
let subpath = Path.join(path, dir);
|
|
454
454
|
if (this._core.platform.isFileSync({ path: subpath })) {
|
|
@@ -461,10 +461,9 @@ export class Storage{
|
|
|
461
461
|
traverseImage(subpath);
|
|
462
462
|
}
|
|
463
463
|
}
|
|
464
|
-
}
|
|
464
|
+
};
|
|
465
465
|
traverseImage(imageDir);
|
|
466
466
|
|
|
467
|
-
|
|
468
467
|
// console.log(
|
|
469
468
|
// `Preloaded image: ${JSON.stringify(this.preloadedData.image.nameMap)}`
|
|
470
469
|
// );
|
|
@@ -479,10 +478,12 @@ export class Storage{
|
|
|
479
478
|
this.preloadedData.animation.profileMap;
|
|
480
479
|
|
|
481
480
|
let animationDir = Path.join(this.projectRoot!, "animation");
|
|
482
|
-
if (!this._core.platform.readdirSync({ path: animationDir }))
|
|
483
|
-
throw "项目文件夹中animation文件夹不存在";
|
|
481
|
+
if (!this._core.platform.readdirSync({ path: animationDir })) {
|
|
482
|
+
// throw "项目文件夹中animation文件夹不存在";
|
|
483
|
+
console.log("Warning: 项目文件夹中animation文件夹不存在");
|
|
484
|
+
return; // allow project without animation folder
|
|
485
|
+
}
|
|
484
486
|
|
|
485
|
-
|
|
486
487
|
function preloadAnimation(path: string) {
|
|
487
488
|
let raw_name = Path.parse(path).name;
|
|
488
489
|
let name_key = raw_name.trim().replace(/ +/, "_");
|
|
@@ -506,9 +507,8 @@ export class Storage{
|
|
|
506
507
|
traverseAnimation(subpath);
|
|
507
508
|
}
|
|
508
509
|
}
|
|
509
|
-
}
|
|
510
|
+
};
|
|
510
511
|
traverseAnimation(animationDir);
|
|
511
|
-
|
|
512
512
|
}
|
|
513
513
|
// Decorator Field
|
|
514
514
|
// _archiveStateSetterRegisteredList: Set<string> = new Set();
|
package/tsconfig.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
|
|
12
12
|
|
|
13
13
|
/* Language and Environment */
|
|
14
|
-
"target": "
|
|
14
|
+
"target": "ES2022", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
|
|
15
15
|
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
|
|
16
16
|
// "jsx": "preserve", /* Specify what JSX code is generated. */
|
|
17
17
|
// "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
|
|
@@ -1,134 +1,137 @@
|
|
|
1
|
-
export interface Platform<WidgetFactory = any> {
|
|
2
|
-
name: string;
|
|
3
|
-
getScreenSize(): [width: number, height: number];
|
|
4
|
-
createUILayer({ z_index }: {
|
|
5
|
-
z_index: number;
|
|
6
|
-
}): WidgetFactory;
|
|
7
|
-
deleteUILayer(widgetFactory: WidgetFactory): void;
|
|
8
|
-
isFileSync({ path }: {
|
|
9
|
-
path: string;
|
|
10
|
-
}): boolean;
|
|
11
|
-
readdirSync(option: Platform.readdirSync.Option): Platform.readdirSync.Result;
|
|
12
|
-
statSync(option: Platform.statSync.Option): Platform.statSync.Result;
|
|
13
|
-
readFileSync(option: Platform.readFileSync.Option): Platform.readFileSync.Result;
|
|
14
|
-
writeFileSync(option: Platform.writeFileSync.Option): void;
|
|
15
|
-
getImageInfo(img_path: string): {
|
|
16
|
-
width: number;
|
|
17
|
-
height: number;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
1
|
+
export interface Platform<WidgetFactory = any> {
|
|
2
|
+
name: string;
|
|
3
|
+
getScreenSize(): [width: number, height: number];
|
|
4
|
+
createUILayer({ z_index }: {
|
|
5
|
+
z_index: number;
|
|
6
|
+
}): WidgetFactory;
|
|
7
|
+
deleteUILayer(widgetFactory: WidgetFactory): void;
|
|
8
|
+
isFileSync({ path }: {
|
|
9
|
+
path: string;
|
|
10
|
+
}): boolean;
|
|
11
|
+
readdirSync(option: Platform.readdirSync.Option): Platform.readdirSync.Result;
|
|
12
|
+
statSync(option: Platform.statSync.Option): Platform.statSync.Result;
|
|
13
|
+
readFileSync(option: Platform.readFileSync.Option): Platform.readFileSync.Result;
|
|
14
|
+
writeFileSync(option: Platform.writeFileSync.Option): void;
|
|
15
|
+
getImageInfo(img_path: string): {
|
|
16
|
+
width: number;
|
|
17
|
+
height: number;
|
|
18
|
+
} | Promise<{
|
|
19
|
+
width: number;
|
|
20
|
+
height: number;
|
|
21
|
+
}>;
|
|
22
|
+
getTime(): number;
|
|
23
|
+
createAudioPlayer(): Platform.AudioPlayer;
|
|
24
|
+
releaseAudioPlayer(audio_player: Platform.AudioPlayer): void;
|
|
25
|
+
setFrameInterval(callback: () => void): void;
|
|
26
|
+
}
|
|
27
|
+
export declare namespace Platform {
|
|
28
|
+
interface AudioPlayer {
|
|
29
|
+
onPrepared?: (success: boolean) => void | undefined;
|
|
30
|
+
onCompleted?: () => void | undefined;
|
|
31
|
+
prepare(): void;
|
|
32
|
+
start(): void;
|
|
33
|
+
stop(): void;
|
|
34
|
+
release(): void;
|
|
35
|
+
getMediaInfo(): MediaInfo;
|
|
36
|
+
setSource({ path }: {
|
|
37
|
+
path: string;
|
|
38
|
+
}): void;
|
|
39
|
+
}
|
|
40
|
+
interface MediaInfo {
|
|
41
|
+
title: string | undefined;
|
|
42
|
+
artist: string | undefined;
|
|
43
|
+
duration: number;
|
|
44
|
+
}
|
|
45
|
+
namespace readdirSync {
|
|
46
|
+
interface Option {
|
|
47
|
+
/**
|
|
48
|
+
* @zh 目录路径
|
|
49
|
+
* @en Directory path
|
|
50
|
+
*/
|
|
51
|
+
path: string;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* @zh 如果返回 `undefined` 则目录不存在,否则返回文件名数组
|
|
55
|
+
* @en If `undefined` is returned, the directory does not exist, otherwise an array of filenames is returned
|
|
56
|
+
*/
|
|
57
|
+
type Result = Array<string> | undefined;
|
|
58
|
+
}
|
|
59
|
+
namespace statSync {
|
|
60
|
+
interface Option {
|
|
61
|
+
/**
|
|
62
|
+
* @zh 路径
|
|
63
|
+
* @en path
|
|
64
|
+
*/
|
|
65
|
+
path: string;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* @zh 如果返回 `undefined` 则目标文件不存在,否则返回文件信息对象
|
|
69
|
+
* @en If `undefined` is returned, the target file does not exist, otherwise the file information object is returned
|
|
70
|
+
*/
|
|
71
|
+
type Result = FSStat | undefined;
|
|
72
|
+
/**
|
|
73
|
+
* @output
|
|
74
|
+
*/
|
|
75
|
+
interface FSStat {
|
|
76
|
+
/**
|
|
77
|
+
* @zh 文件大小(单位为字节)
|
|
78
|
+
* @en The size of the file in bytes
|
|
79
|
+
*/
|
|
80
|
+
size: number;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
namespace readFileSync {
|
|
84
|
+
interface Option {
|
|
85
|
+
/**
|
|
86
|
+
* @zh 文件路径
|
|
87
|
+
* @en path
|
|
88
|
+
*/
|
|
89
|
+
path: string;
|
|
90
|
+
/**
|
|
91
|
+
* @zh 其他选项
|
|
92
|
+
* @en Other Options
|
|
93
|
+
*/
|
|
94
|
+
options?: Options;
|
|
95
|
+
}
|
|
96
|
+
interface Options {
|
|
97
|
+
/**
|
|
98
|
+
* @zh 当指定了编码方式之后,API 返回结果为 `string`
|
|
99
|
+
* @en When the encoding method is specified, the API returns `string` as the result
|
|
100
|
+
*/
|
|
101
|
+
encoding?: string;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* @zh 文件内容。如果返回 `undefined`,则表明读取文件失败
|
|
105
|
+
* @en File content. If `undefined` is returned, the file failed to be read
|
|
106
|
+
*/
|
|
107
|
+
type Result = ArrayBuffer | string | undefined;
|
|
108
|
+
}
|
|
109
|
+
namespace writeFileSync {
|
|
110
|
+
interface Option {
|
|
111
|
+
/**
|
|
112
|
+
* @zh 文件路径或者文件句柄
|
|
113
|
+
* @en File path or file descriptor
|
|
114
|
+
*/
|
|
115
|
+
path: string | number;
|
|
116
|
+
/**
|
|
117
|
+
* @zh 写入目标文件的数据
|
|
118
|
+
* @en Data to be written to the target file
|
|
119
|
+
*/
|
|
120
|
+
data: ArrayBuffer | string | DataView;
|
|
121
|
+
/**
|
|
122
|
+
* @zh 其他选项
|
|
123
|
+
* @en Other Options
|
|
124
|
+
*/
|
|
125
|
+
options?: Options;
|
|
126
|
+
}
|
|
127
|
+
interface Options {
|
|
128
|
+
/**
|
|
129
|
+
* @zh 如果数据格式为 `string`,需要指定编码方式
|
|
130
|
+
* @en If the `data` format is `string`, you need to specify the encoding method
|
|
131
|
+
* @defaultValue utf8
|
|
132
|
+
*/
|
|
133
|
+
encoding?: string;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
export default Platform;
|