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,140 +1,140 @@
|
|
|
1
|
-
export function menu_statement(core) {
|
|
2
|
-
// menu statement start
|
|
3
|
-
core.script.use((ctx, next) => {
|
|
4
|
-
if (ctx.rawtext.trim().split(" ")[0] !== "menu")
|
|
5
|
-
return next();
|
|
6
|
-
let menu_data = ctx.startStatement("menu");
|
|
7
|
-
// Block the game
|
|
8
|
-
core.system.block();
|
|
9
|
-
let router = core.ui.getRouter("menu");
|
|
10
|
-
if (!router) {
|
|
11
|
-
core.ui.addRouter("menu", "ct");
|
|
12
|
-
router = core.ui.getRouter("menu");
|
|
13
|
-
}
|
|
14
|
-
let menu_view_prop = buildMenuViewProp(menu_data);
|
|
15
|
-
if (!router.length) {
|
|
16
|
-
router.push("menu", menu_view_prop);
|
|
17
|
-
}
|
|
18
|
-
else {
|
|
19
|
-
router.update(menu_view_prop);
|
|
20
|
-
}
|
|
21
|
-
// the view contains many buttons, when the button is clicked,
|
|
22
|
-
// it will call core.script.jump() to jump to the next line of the @label statement
|
|
23
|
-
// then hide the menu
|
|
24
|
-
// so the script will continue to execute the next line of the @label statement
|
|
25
|
-
// when a @label is appended again, it represents the command between the @label and the next @label
|
|
26
|
-
// is executed completely, so jump to the next line of "end menu"
|
|
27
|
-
});
|
|
28
|
-
// menu statement close
|
|
29
|
-
core.script.use((ctx, next) => {
|
|
30
|
-
if (ctx.rawtext.trim().split(/ +/).join(" ") !== "end menu")
|
|
31
|
-
return next();
|
|
32
|
-
ctx.endStatement("menu");
|
|
33
|
-
});
|
|
34
|
-
// menu internal label (start with @)
|
|
35
|
-
// syntax: @"{label_name}" [enable={js_expression}]
|
|
36
|
-
core.script.use((ctx, next) => {
|
|
37
|
-
if (!ctx.rawtext.trim().split(" ")[0].startsWith("@"))
|
|
38
|
-
return next();
|
|
39
|
-
let label_name = ctx.slicedArgs[1].str;
|
|
40
|
-
if (ctx.statementStack.length === 0 ||
|
|
41
|
-
ctx.statementStack[ctx.statementStack.length - 1][0] !== "menu") {
|
|
42
|
-
throw `@${label_name} must in menu statement`;
|
|
43
|
-
}
|
|
44
|
-
let menu_item = ctx.statementStack[ctx.statementStack.length - 1];
|
|
45
|
-
let menu_data = menu_item[2];
|
|
46
|
-
for (let i = 0; i < menu_data.item_list.length; i++) {
|
|
47
|
-
if (menu_data.item_list[i].position[0] === ctx.currentPath &&
|
|
48
|
-
menu_data.item_list[i].position[1] === ctx.currentLineIndex) {
|
|
49
|
-
// the label belongs to this menu statement
|
|
50
|
-
// so jump to the "end menu" statement
|
|
51
|
-
// the script will continue from the "end menu" statement
|
|
52
|
-
// get the end menu statement position
|
|
53
|
-
let end_menu_position = [
|
|
54
|
-
...menu_data.end_position,
|
|
55
|
-
];
|
|
56
|
-
// jump to "end menu"
|
|
57
|
-
core.script.jump(end_menu_position[0], end_menu_position[1]);
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
// the label does not belong to this menu statement, so throw error
|
|
62
|
-
throw `@${label_name} does not belong to closest menu statement, at file [${ctx.currentPath}] line [${ctx.currentLineIndex + 1}], but belong to [${menu_item[1][0]}] line [${menu_item[1][1] + 1}]`;
|
|
63
|
-
});
|
|
64
|
-
// analyse menu start statement
|
|
65
|
-
core.script.useAnalyseStatement((ctx, next) => {
|
|
66
|
-
if (ctx.rawtext.trim().split(" ")[0] !== "menu")
|
|
67
|
-
return next();
|
|
68
|
-
let data = ctx.startStatement("menu");
|
|
69
|
-
// console.log("[HZEngine] Menu start");
|
|
70
|
-
// the data here is {} at first, so dont read its properties, because the properties are not defined yet
|
|
71
|
-
// we will define the properties here
|
|
72
|
-
data.start_position = [
|
|
73
|
-
ctx.currentPath,
|
|
74
|
-
ctx.currentLineIndex,
|
|
75
|
-
];
|
|
76
|
-
data.item_list = [];
|
|
77
|
-
});
|
|
78
|
-
// analyse menu label (start with @)
|
|
79
|
-
core.script.useAnalyseStatement((ctx, next) => {
|
|
80
|
-
if (!ctx.rawtext.trim().split(" ")[0].startsWith("@"))
|
|
81
|
-
return next();
|
|
82
|
-
if (ctx.statementStack.length === 0 ||
|
|
83
|
-
ctx.statementStack[ctx.statementStack.length - 1][0] !== "menu") {
|
|
84
|
-
throw `@${ctx.slicedArgs[1]} must in menu statement`;
|
|
85
|
-
}
|
|
86
|
-
// console.log("[HZEngine] Menu label: " + ctx.slicedArgs[1].str);
|
|
87
|
-
let menu_stack_item = ctx.statementStack[ctx.statementStack.length - 1];
|
|
88
|
-
// parse the enable js expression (syntax: enable={js_expression})
|
|
89
|
-
// get the js_expression and put it in the menu data
|
|
90
|
-
let enable_js_expression = undefined;
|
|
91
|
-
if (ctx.slicedArgs.length > 2) {
|
|
92
|
-
enable_js_expression = ctx.slicedArgs[2].str;
|
|
93
|
-
if (!enable_js_expression.startsWith("enable=")) {
|
|
94
|
-
throw `enable js expression must start with "enable="`;
|
|
95
|
-
}
|
|
96
|
-
enable_js_expression = enable_js_expression.slice(7);
|
|
97
|
-
if (enable_js_expression.startsWith("{") &&
|
|
98
|
-
enable_js_expression.endsWith("}")) {
|
|
99
|
-
enable_js_expression = enable_js_expression.slice(1, -1);
|
|
100
|
-
}
|
|
101
|
-
else {
|
|
102
|
-
enable_js_expression = enable_js_expression.trim();
|
|
103
|
-
}
|
|
104
|
-
if (enable_js_expression.length > 0) {
|
|
105
|
-
enable_js_expression = `(${enable_js_expression})`;
|
|
106
|
-
}
|
|
107
|
-
else {
|
|
108
|
-
throw `enable js expression must not be empty`;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
menu_stack_item[2].item_list.push({
|
|
112
|
-
text: ctx.slicedArgs[1].str,
|
|
113
|
-
position: [ctx.currentPath, ctx.currentLineIndex],
|
|
114
|
-
enable_js_expression,
|
|
115
|
-
});
|
|
116
|
-
});
|
|
117
|
-
// analyse menu end statement
|
|
118
|
-
core.script.useAnalyseStatement((ctx, next) => {
|
|
119
|
-
if (ctx.rawtext.trim().split(/ +/).join(" ") !== "end menu")
|
|
120
|
-
return next();
|
|
121
|
-
// console.log("[HZEngine] Menu analyse end");
|
|
122
|
-
let data = ctx.endStatement("menu");
|
|
123
|
-
// the data here is {} at first, so dont read its properties, because the properties are not defined yet
|
|
124
|
-
// we will define the properties here
|
|
125
|
-
data.end_position = [ctx.currentPath, ctx.currentLineIndex];
|
|
126
|
-
// set and save the menu data
|
|
127
|
-
ctx.setStatementData(data, [
|
|
128
|
-
data.start_position[0],
|
|
129
|
-
data.start_position[1],
|
|
130
|
-
]);
|
|
131
|
-
});
|
|
132
|
-
function buildMenuViewProp(menu_data) {
|
|
133
|
-
// parse menu item string
|
|
134
|
-
let parsed_item_list = [];
|
|
135
|
-
for (let item of menu_data.item_list) {
|
|
136
|
-
parsed_item_list.push(
|
|
137
|
-
}
|
|
138
|
-
return { itemList: parsed_item_list };
|
|
139
|
-
}
|
|
140
|
-
}
|
|
1
|
+
export function menu_statement(core) {
|
|
2
|
+
// menu statement start
|
|
3
|
+
core.script.use((ctx, next) => {
|
|
4
|
+
if (ctx.rawtext.trim().split(" ")[0] !== "menu")
|
|
5
|
+
return next();
|
|
6
|
+
let menu_data = ctx.startStatement("menu");
|
|
7
|
+
// Block the game
|
|
8
|
+
core.system.block();
|
|
9
|
+
let router = core.ui.getRouter("menu");
|
|
10
|
+
if (!router) {
|
|
11
|
+
core.ui.addRouter("menu", "ct");
|
|
12
|
+
router = core.ui.getRouter("menu");
|
|
13
|
+
}
|
|
14
|
+
let menu_view_prop = buildMenuViewProp(menu_data);
|
|
15
|
+
if (!router.length) {
|
|
16
|
+
router.push("menu", menu_view_prop);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
router.update(menu_view_prop);
|
|
20
|
+
}
|
|
21
|
+
// the view contains many buttons, when the button is clicked,
|
|
22
|
+
// it will call core.script.jump() to jump to the next line of the @label statement
|
|
23
|
+
// then hide the menu
|
|
24
|
+
// so the script will continue to execute the next line of the @label statement
|
|
25
|
+
// when a @label is appended again, it represents the command between the @label and the next @label
|
|
26
|
+
// is executed completely, so jump to the next line of "end menu"
|
|
27
|
+
});
|
|
28
|
+
// menu statement close
|
|
29
|
+
core.script.use((ctx, next) => {
|
|
30
|
+
if (ctx.rawtext.trim().split(/ +/).join(" ") !== "end menu")
|
|
31
|
+
return next();
|
|
32
|
+
ctx.endStatement("menu");
|
|
33
|
+
});
|
|
34
|
+
// menu internal label (start with @)
|
|
35
|
+
// syntax: @"{label_name}" [enable={js_expression}]
|
|
36
|
+
core.script.use((ctx, next) => {
|
|
37
|
+
if (!ctx.rawtext.trim().split(" ")[0].startsWith("@"))
|
|
38
|
+
return next();
|
|
39
|
+
let label_name = ctx.slicedArgs[1].str;
|
|
40
|
+
if (ctx.statementStack.length === 0 ||
|
|
41
|
+
ctx.statementStack[ctx.statementStack.length - 1][0] !== "menu") {
|
|
42
|
+
throw `@${label_name} must in menu statement`;
|
|
43
|
+
}
|
|
44
|
+
let menu_item = ctx.statementStack[ctx.statementStack.length - 1];
|
|
45
|
+
let menu_data = menu_item[2];
|
|
46
|
+
for (let i = 0; i < menu_data.item_list.length; i++) {
|
|
47
|
+
if (menu_data.item_list[i].position[0] === ctx.currentPath &&
|
|
48
|
+
menu_data.item_list[i].position[1] === ctx.currentLineIndex) {
|
|
49
|
+
// the label belongs to this menu statement
|
|
50
|
+
// so jump to the "end menu" statement
|
|
51
|
+
// the script will continue from the "end menu" statement
|
|
52
|
+
// get the end menu statement position
|
|
53
|
+
let end_menu_position = [
|
|
54
|
+
...menu_data.end_position,
|
|
55
|
+
];
|
|
56
|
+
// jump to "end menu"
|
|
57
|
+
core.script.jump(end_menu_position[0], end_menu_position[1]);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
// the label does not belong to this menu statement, so throw error
|
|
62
|
+
throw `@${label_name} does not belong to closest menu statement, at file [${ctx.currentPath}] line [${ctx.currentLineIndex + 1}], but belong to [${menu_item[1][0]}] line [${menu_item[1][1] + 1}]`;
|
|
63
|
+
});
|
|
64
|
+
// analyse menu start statement
|
|
65
|
+
core.script.useAnalyseStatement((ctx, next) => {
|
|
66
|
+
if (ctx.rawtext.trim().split(" ")[0] !== "menu")
|
|
67
|
+
return next();
|
|
68
|
+
let data = ctx.startStatement("menu");
|
|
69
|
+
// console.log("[HZEngine] Menu start");
|
|
70
|
+
// the data here is {} at first, so dont read its properties, because the properties are not defined yet
|
|
71
|
+
// we will define the properties here
|
|
72
|
+
data.start_position = [
|
|
73
|
+
ctx.currentPath,
|
|
74
|
+
ctx.currentLineIndex,
|
|
75
|
+
];
|
|
76
|
+
data.item_list = [];
|
|
77
|
+
});
|
|
78
|
+
// analyse menu label (start with @)
|
|
79
|
+
core.script.useAnalyseStatement((ctx, next) => {
|
|
80
|
+
if (!ctx.rawtext.trim().split(" ")[0].startsWith("@"))
|
|
81
|
+
return next();
|
|
82
|
+
if (ctx.statementStack.length === 0 ||
|
|
83
|
+
ctx.statementStack[ctx.statementStack.length - 1][0] !== "menu") {
|
|
84
|
+
throw `@${ctx.slicedArgs[1]} must in menu statement`;
|
|
85
|
+
}
|
|
86
|
+
// console.log("[HZEngine] Menu label: " + ctx.slicedArgs[1].str);
|
|
87
|
+
let menu_stack_item = ctx.statementStack[ctx.statementStack.length - 1];
|
|
88
|
+
// parse the enable js expression (syntax: enable={js_expression})
|
|
89
|
+
// get the js_expression and put it in the menu data
|
|
90
|
+
let enable_js_expression = undefined;
|
|
91
|
+
if (ctx.slicedArgs.length > 2) {
|
|
92
|
+
enable_js_expression = ctx.slicedArgs[2].str;
|
|
93
|
+
if (!enable_js_expression.startsWith("enable=")) {
|
|
94
|
+
throw `enable js expression must start with "enable="`;
|
|
95
|
+
}
|
|
96
|
+
enable_js_expression = enable_js_expression.slice(7);
|
|
97
|
+
if (enable_js_expression.startsWith("{") &&
|
|
98
|
+
enable_js_expression.endsWith("}")) {
|
|
99
|
+
enable_js_expression = enable_js_expression.slice(1, -1);
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
enable_js_expression = enable_js_expression.trim();
|
|
103
|
+
}
|
|
104
|
+
if (enable_js_expression.length > 0) {
|
|
105
|
+
enable_js_expression = `(${enable_js_expression})`;
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
throw `enable js expression must not be empty`;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
menu_stack_item[2].item_list.push({
|
|
112
|
+
text: ctx.slicedArgs[1].str,
|
|
113
|
+
position: [ctx.currentPath, ctx.currentLineIndex],
|
|
114
|
+
enable_js_expression,
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
// analyse menu end statement
|
|
118
|
+
core.script.useAnalyseStatement((ctx, next) => {
|
|
119
|
+
if (ctx.rawtext.trim().split(/ +/).join(" ") !== "end menu")
|
|
120
|
+
return next();
|
|
121
|
+
// console.log("[HZEngine] Menu analyse end");
|
|
122
|
+
let data = ctx.endStatement("menu");
|
|
123
|
+
// the data here is {} at first, so dont read its properties, because the properties are not defined yet
|
|
124
|
+
// we will define the properties here
|
|
125
|
+
data.end_position = [ctx.currentPath, ctx.currentLineIndex];
|
|
126
|
+
// set and save the menu data
|
|
127
|
+
ctx.setStatementData(data, [
|
|
128
|
+
data.start_position[0],
|
|
129
|
+
data.start_position[1],
|
|
130
|
+
]);
|
|
131
|
+
});
|
|
132
|
+
function buildMenuViewProp(menu_data) {
|
|
133
|
+
// parse menu item string
|
|
134
|
+
let parsed_item_list = [];
|
|
135
|
+
for (let item of menu_data.item_list) {
|
|
136
|
+
parsed_item_list.push({ ...item, text: core.script.parseString(item.text) });
|
|
137
|
+
}
|
|
138
|
+
return { itemList: parsed_item_list };
|
|
139
|
+
}
|
|
140
|
+
}
|