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.
Files changed (103) hide show
  1. package/dist/async/index.js +162 -0
  2. package/dist/async/zeppos_timer.js +58 -0
  3. package/dist/audio/index.js +260 -0
  4. package/dist/config/index.js +57 -0
  5. package/dist/debug/index.js +8 -0
  6. package/dist/index.js +103 -0
  7. package/dist/platform/index.js +1 -0
  8. package/dist/plugins/basic_command/$.js +8 -0
  9. package/dist/plugins/basic_command/audio.js +40 -0
  10. package/dist/plugins/basic_command/basic.js +124 -0
  11. package/dist/plugins/basic_command/character.js +112 -0
  12. package/dist/plugins/basic_command/conditional.js +260 -0
  13. package/dist/plugins/basic_command/config.js +22 -0
  14. package/dist/plugins/basic_command/decorator.js +24 -0
  15. package/dist/plugins/basic_command/eval.js +67 -0
  16. package/dist/plugins/basic_command/img.js +249 -0
  17. package/dist/plugins/basic_command/index.js +22 -0
  18. package/dist/plugins/basic_command/menu.js +140 -0
  19. package/dist/plugins/global_gesture/index.js +25 -0
  20. package/dist/plugins/transform/animation.js +440 -0
  21. package/dist/plugins/transform/commands.js +38 -0
  22. package/dist/plugins/transform/example_profiles.js +32 -0
  23. package/dist/plugins/transform/hz_anime.js +211 -0
  24. package/dist/plugins/transform/index.js +93 -0
  25. package/dist/script/index.js +537 -0
  26. package/dist/script/readscript.js +15 -0
  27. package/dist/script/strtools.js +157 -0
  28. package/dist/storage/decorator.js +260 -0
  29. package/dist/storage/fs.js +96 -0
  30. package/dist/storage/index.js +442 -0
  31. package/dist/system/index.js +144 -0
  32. package/dist/ui/index.js +535 -0
  33. package/dist/utils/path.js +289 -0
  34. package/license.txt +202 -0
  35. package/package.json +26 -0
  36. package/src/async/index.ts +124 -0
  37. package/src/async/zeppos_timer.js +65 -0
  38. package/src/audio/index.ts +224 -0
  39. package/src/config/index.ts +80 -0
  40. package/src/debug/index.ts +11 -0
  41. package/src/index.ts +122 -0
  42. package/src/platform/index.ts +158 -0
  43. package/src/plugins/basic_command/$.ts +11 -0
  44. package/src/plugins/basic_command/audio.ts +53 -0
  45. package/src/plugins/basic_command/basic.ts +145 -0
  46. package/src/plugins/basic_command/character.ts +144 -0
  47. package/src/plugins/basic_command/conditional.ts +349 -0
  48. package/src/plugins/basic_command/config.ts +29 -0
  49. package/src/plugins/basic_command/decorator.ts +29 -0
  50. package/src/plugins/basic_command/eval.ts +88 -0
  51. package/src/plugins/basic_command/img.ts +317 -0
  52. package/src/plugins/basic_command/index.ts +24 -0
  53. package/src/plugins/basic_command/menu.ts +178 -0
  54. package/src/plugins/global_gesture/index.ts +29 -0
  55. package/src/plugins/transform/animation.ts +542 -0
  56. package/src/plugins/transform/commands.ts +53 -0
  57. package/src/plugins/transform/example_profiles.ts +36 -0
  58. package/src/plugins/transform/hz_anime.ts +214 -0
  59. package/src/plugins/transform/index.ts +141 -0
  60. package/src/plugins/transform/readme.md +1 -0
  61. package/src/script/index.ts +623 -0
  62. package/src/script/readscript.ts +17 -0
  63. package/src/script/strtools.ts +159 -0
  64. package/src/storage/decorator.ts +473 -0
  65. package/src/storage/fs.ts +104 -0
  66. package/src/storage/index.ts +541 -0
  67. package/src/system/index.ts +95 -0
  68. package/src/ui/index.ts +699 -0
  69. package/src/utils/path.js +338 -0
  70. package/tsconfig.json +111 -0
  71. package/types/async/index.d.ts +24 -0
  72. package/types/async/zeppos_timer.d.ts +14 -0
  73. package/types/audio/index.d.ts +64 -0
  74. package/types/config/index.d.ts +9 -0
  75. package/types/debug/index.d.ts +6 -0
  76. package/types/index.d.ts +41 -0
  77. package/types/platform/index.d.ts +134 -0
  78. package/types/plugins/basic_command/$.d.ts +2 -0
  79. package/types/plugins/basic_command/audio.d.ts +2 -0
  80. package/types/plugins/basic_command/basic.d.ts +3 -0
  81. package/types/plugins/basic_command/character.d.ts +2 -0
  82. package/types/plugins/basic_command/conditional.d.ts +2 -0
  83. package/types/plugins/basic_command/config.d.ts +2 -0
  84. package/types/plugins/basic_command/decorator.d.ts +2 -0
  85. package/types/plugins/basic_command/eval.d.ts +2 -0
  86. package/types/plugins/basic_command/img.d.ts +2 -0
  87. package/types/plugins/basic_command/index.d.ts +2 -0
  88. package/types/plugins/basic_command/menu.d.ts +2 -0
  89. package/types/plugins/global_gesture/index.d.ts +2 -0
  90. package/types/plugins/transform/animation.d.ts +131 -0
  91. package/types/plugins/transform/commands.d.ts +7 -0
  92. package/types/plugins/transform/example_profiles.d.ts +2 -0
  93. package/types/plugins/transform/hz_anime.d.ts +51 -0
  94. package/types/plugins/transform/index.d.ts +13 -0
  95. package/types/script/index.d.ts +123 -0
  96. package/types/script/readscript.d.ts +2 -0
  97. package/types/script/strtools.d.ts +31 -0
  98. package/types/storage/decorator.d.ts +41 -0
  99. package/types/storage/fs.d.ts +1 -0
  100. package/types/storage/index.d.ts +86 -0
  101. package/types/system/index.d.ts +35 -0
  102. package/types/ui/index.d.ts +167 -0
  103. package/types/utils/path.d.ts +84 -0
@@ -0,0 +1,157 @@
1
+ /**
2
+ * 将一行字符串切割为(str,quoted)[]的形式
3
+ * @param str
4
+ * @returns
5
+ */
6
+ export function splitStr2Objs(str) {
7
+ // console.log(`splitStr2Objs: ${str}`);
8
+ let res = [];
9
+ let len = str.length;
10
+ let p = 0;
11
+ while (p < len) {
12
+ while (p < len && str[p] === " ")
13
+ ++p; // find first not space
14
+ if (p === len)
15
+ return res;
16
+ if (str[p] === '"') {
17
+ // find next `"`
18
+ let q = p + 1;
19
+ while (q < len && str[q] !== '"') {
20
+ if (str[q] === "\\")
21
+ q += 2;
22
+ else
23
+ ++q;
24
+ }
25
+ if (q >= len)
26
+ throw "Quote not completed";
27
+ let resstr = str.slice(p + 1, q);
28
+ // console.log(`Transformed[${res.length}]:\n${transformStr(resstr)}`);
29
+ let transformedStr = "error";
30
+ try {
31
+ transformedStr = transformStr(resstr);
32
+ }
33
+ catch (e) {
34
+ throw "该字符串中的转义字符有错误:" + resstr;
35
+ }
36
+ res.push({ str: transformedStr, isQuoted: true });
37
+ p = q + 1;
38
+ }
39
+ else if (str[p] === "[") {
40
+ // find next `]`
41
+ let q = p + 1;
42
+ while (q < len && str[q] !== "]") {
43
+ // if (str[q] === "\\") q += 2;
44
+ // else ++q;
45
+ ++q;
46
+ }
47
+ if (q >= len)
48
+ throw "square brackets not completed";
49
+ let resstr = str.slice(p + 1, q);
50
+ res.push({ str: resstr, isSquared: true });
51
+ p = q + 1;
52
+ }
53
+ else if (str[p] === "(") {
54
+ // find next `)`
55
+ let q = p + 1;
56
+ while (q < len && str[q] !== ")") {
57
+ // if (str[q] === "\\") q += 2;
58
+ // else ++q;
59
+ ++q;
60
+ }
61
+ if (q >= len)
62
+ throw "round brackets not completed";
63
+ let resstr = str.slice(p + 1, q);
64
+ res.push({ str: resstr, isRounded: true });
65
+ p = q + 1;
66
+ }
67
+ else {
68
+ let q = p + 1;
69
+ while (q < len && str[q] !== " " && str[q] !== '"' && str[q] !== "(" && str[q] !== "[")
70
+ ++q; // find first space/quote after this
71
+ let resstr = str.slice(p, q);
72
+ // console.log(transformStr(resstr));
73
+ res.push({ str: resstr, isQuoted: false });
74
+ p = q;
75
+ }
76
+ }
77
+ return res;
78
+ }
79
+ export function mergeObjs2Str(objs) {
80
+ return objs
81
+ .map((obj) => obj.isQuoted ? `"${obj.str}"` : obj.isSquared ? `[${obj.str}]` : obj.isRounded ? `(${obj.str})` : obj.str)
82
+ .join(" ");
83
+ }
84
+ export function splitStr2Strs(str) {
85
+ return splitStr2Objs(str).map((obj) => obj.isQuoted ? `"${obj.str}"` : obj.str);
86
+ }
87
+ /**
88
+ * 转义一遍字符串,使其中\n等变成对应字符(可能报错)
89
+ * @param str
90
+ * @returns
91
+ */
92
+ export function transformStr(str) {
93
+ return JSON.parse(`"${str}"`);
94
+ }
95
+ // 翻译hzengine script插值字符串
96
+ // 语法:"...[expression]..."
97
+ // 如果希望在字符串中显示`[`,请使用两个`[`,如`"[[正常显示而不被当作表达式的文字]]"`
98
+ export function parseInterpolatedStr(str) {
99
+ let len = str.length;
100
+ let p = 0;
101
+ let expr_record = [];
102
+ while (p < len) {
103
+ // 寻找第一个`[`
104
+ while (p < len && str[p] !== "[")
105
+ ++p;
106
+ if (p >= len)
107
+ break;
108
+ // 判断是否是两个`[`
109
+ if (str[p] === "[" && str[p + 1] === "[") {
110
+ p += 2;
111
+ continue;
112
+ }
113
+ // 寻找第一个`]`
114
+ let q = p + 1;
115
+ while (q < len && str[q] !== "]") {
116
+ ++q;
117
+ // 判断是否是两个`]`
118
+ while (q < len && str[q] === "]" && str[q + 1] === "]") {
119
+ q += 2;
120
+ }
121
+ }
122
+ if (q >= len) {
123
+ // 没有找到`]`,报错
124
+ throw `Interpolated string lose closing bracket: ${str}`;
125
+ }
126
+ expr_record.push([p, q]);
127
+ p = q + 1;
128
+ }
129
+ let left = 0, right = len;
130
+ let res = [];
131
+ for (let i = 0; i < expr_record.length; ++i) {
132
+ let [l, r] = expr_record[i];
133
+ if (l > left)
134
+ res.push({ str: str.slice(left, l), isExpression: false });
135
+ res.push({ str: str.slice(l + 1, r), isExpression: true });
136
+ left = r + 1;
137
+ }
138
+ if (left < right)
139
+ res.push({ str: str.slice(left, right), isExpression: false });
140
+ return res;
141
+ }
142
+ export function removeComment(str) {
143
+ let quoteNotClosed = false;
144
+ let len = str.length;
145
+ for (let i = 0; i < len; ++i) {
146
+ if (quoteNotClosed && str[i] === `\\`) {
147
+ ++i;
148
+ }
149
+ else if (str[i] === `"`) {
150
+ quoteNotClosed = !quoteNotClosed;
151
+ }
152
+ else if (str[i] === "#" && !quoteNotClosed) {
153
+ return str.slice(0, i);
154
+ }
155
+ }
156
+ return str;
157
+ }
@@ -0,0 +1,260 @@
1
+ import { Async } from "../async/index.js";
2
+ /**
3
+ * 存档属性装饰器
4
+ * @param store_key 保存数据到存档数据对象的key
5
+ * @returns
6
+ */
7
+ export function Save(store_key) {
8
+ return function (target, context) {
9
+ context.addInitializer(function () {
10
+ Async.nextTick(() => {
11
+ const core = this._core;
12
+ core.on("initArchiveData", () => {
13
+ core.storage.setSaveableData(core.storage.archiveData, true, target.get.call(this), ...store_key.split("."));
14
+ });
15
+ core.on("beforeSaveArchive", () => {
16
+ core.storage.setSaveableData(core.storage.archiveData, false, target.get.call(this), ...store_key.split("."));
17
+ });
18
+ core.on("afterLoadArchive", () => {
19
+ let dataInArchive = core.storage.getSaveableData(core.storage.archiveData, false, ...store_key.split("."));
20
+ this._core.debug.log(`Load Data from Archive, store_key: ${store_key}, dataInArchive: ${JSON.stringify(dataInArchive)}`);
21
+ target.set.call(this, dataInArchive);
22
+ });
23
+ });
24
+ });
25
+ if (context.kind !== "accessor") {
26
+ throw new Error("ArchiveStateAccessor只能用于accessor属性");
27
+ }
28
+ return {
29
+ get() {
30
+ target = target;
31
+ return archiveStateGetter(this, store_key, target.get);
32
+ },
33
+ set(value) {
34
+ target = target;
35
+ archiveStateSetter(this, store_key, target.set, value);
36
+ },
37
+ };
38
+ };
39
+ }
40
+ /**
41
+ * 存档属性装饰器
42
+ * @param store_key 保存数据到存档数据对象的key
43
+ * @returns
44
+ */
45
+ export function CustomSave(store_key, serializer, deserializer) {
46
+ return (target, context) => {
47
+ if (context.kind !== "accessor") {
48
+ throw new Error("ArchiveStateAccessor只能用于accessor属性");
49
+ }
50
+ context.addInitializer(function () {
51
+ Async.nextTick(() => {
52
+ const core = this._core;
53
+ core.on("initArchiveData", () => {
54
+ core.storage.setSaveableData(core.storage.archiveData, true, serializer.call(this, target.get.call(this)), ...store_key.split("."));
55
+ });
56
+ core.on("beforeSaveArchive", () => {
57
+ core.storage.setSaveableData(core.storage.archiveData, false, serializer.call(this, target.get.call(this)), ...store_key.split("."));
58
+ });
59
+ core.on("afterLoadArchive", () => {
60
+ let dataInArchive = core.storage.getSaveableData(core.storage.archiveData, false, ...store_key.split("."));
61
+ this._core.debug.log(`Load Data from Archive, store_key: ${store_key}, dataInArchive: ${JSON.stringify(dataInArchive)}`);
62
+ target.set.call(this, deserializer.call(this, dataInArchive));
63
+ });
64
+ });
65
+ });
66
+ return {
67
+ get() {
68
+ target = target;
69
+ return archiveStateGetterWithSerializer(this, store_key, target.get, serializer);
70
+ },
71
+ set(value) {
72
+ target = target;
73
+ archiveStateSetterWithDeserializer(this, store_key, target.set, value, deserializer);
74
+ },
75
+ };
76
+ };
77
+ }
78
+ export function SaveGetter(store_key) {
79
+ return (target, context) => {
80
+ context.addInitializer(function () {
81
+ Async.nextTick(() => {
82
+ const core = this._core;
83
+ core.on("initArchiveData", () => {
84
+ core.storage.setSaveableData(core.storage.archiveData, true, target.call(this), ...store_key.split("."));
85
+ });
86
+ core.on("beforeSaveArchive", () => {
87
+ core.storage.setSaveableData(core.storage.archiveData, false, target.call(this), ...store_key.split("."));
88
+ });
89
+ });
90
+ });
91
+ if (context.kind !== "getter") {
92
+ throw new Error("ArchiveStateGetter只能用于getter属性");
93
+ }
94
+ return function () {
95
+ let val = archiveStateGetter(this, store_key, target);
96
+ return val;
97
+ };
98
+ };
99
+ }
100
+ export function CustomSaveGetter(store_key, serializer) {
101
+ return (target, context) => {
102
+ if (context.kind !== "getter") {
103
+ throw new Error("ArchiveStateGetter只能用于getter属性");
104
+ }
105
+ context.addInitializer(function () {
106
+ Async.nextTick(() => {
107
+ const core = this._core;
108
+ core.on("initArchiveData", () => {
109
+ core.storage.setSaveableData(core.storage.archiveData, true, serializer.call(this, target.call(this)), ...store_key.split("."));
110
+ });
111
+ core.on("beforeSaveArchive", () => {
112
+ core.storage.setSaveableData(core.storage.archiveData, false, serializer.call(this, target.call(this)), ...store_key.split("."));
113
+ });
114
+ });
115
+ });
116
+ return function () {
117
+ let val = archiveStateGetterWithSerializer(this, store_key, target, serializer);
118
+ return val;
119
+ };
120
+ };
121
+ }
122
+ /**
123
+ * 存档属性装饰器
124
+ * @param store_key 保存数据到存档数据对象的key
125
+ * @returns
126
+ */
127
+ export function SaveSetter(store_key) {
128
+ return (target, context) => {
129
+ if (context.kind !== "setter") {
130
+ throw new Error("ArchiveStateSetter只能用于setter属性");
131
+ }
132
+ context.addInitializer(function () {
133
+ Async.nextTick(() => {
134
+ let core = this._core;
135
+ core.on("afterLoadArchive", () => {
136
+ let dataInArchive = core.storage.getSaveableData(core.storage.archiveData, false, ...store_key.split("."));
137
+ this._core.debug.log(`Load Data from Archive, store_key: ${store_key}, dataInArchive: ${JSON.stringify(dataInArchive)}`);
138
+ target.call(this, dataInArchive);
139
+ });
140
+ });
141
+ });
142
+ return function (value) {
143
+ archiveStateSetter(this, store_key, target, value);
144
+ };
145
+ };
146
+ }
147
+ export function CustomSaveSetter(store_key, deserializer) {
148
+ return (target, context) => {
149
+ if (context.kind !== "setter") {
150
+ throw new Error("ArchiveStateSetter只能用于setter属性");
151
+ }
152
+ context.addInitializer(function () {
153
+ Async.nextTick(() => {
154
+ let core = this._core;
155
+ core.on("afterLoadArchive", () => {
156
+ let dataInArchive = core.storage.getSaveableData(core.storage.archiveData, false, ...store_key.split("."));
157
+ this._core.debug.log(`Load Data from Archive, store_key: ${store_key}, dataInArchive: ${JSON.stringify(dataInArchive)}`);
158
+ target.call(this, deserializer.call(this, dataInArchive));
159
+ });
160
+ });
161
+ });
162
+ return function (value) {
163
+ archiveStateSetterWithDeserializer(this, store_key, target, value, deserializer);
164
+ };
165
+ };
166
+ }
167
+ /**
168
+ * 存档属性装饰器
169
+ * @param store_key 保存数据到存档数据对象的key
170
+ * @returns
171
+ */
172
+ function archiveStateGetter(_this, store_key, old_getter) {
173
+ const core = _this._core;
174
+ // if (!core.storage._archiveStateGetterRegisteredList.has(store_key)) {
175
+ // core.storage._archiveStateGetterRegisteredList.add(store_key);
176
+ // core.on("initArchiveData", () => {
177
+ // core.storage.setSaveableData(
178
+ // core.storage.archiveData,
179
+ // true,
180
+ // old_getter.call(_this),
181
+ // ...store_key.split(".")
182
+ // );
183
+ // });
184
+ // core.on("beforeSaveArchive", () => {
185
+ // core.storage.setSaveableData(
186
+ // core.storage.archiveData,
187
+ // false,
188
+ // old_getter.call(_this),
189
+ // ...store_key.split(".")
190
+ // );
191
+ // });
192
+ // }
193
+ let val = old_getter.call(_this);
194
+ // console.log(`getval: ${val}`);
195
+ return val;
196
+ }
197
+ /**
198
+ * 存档属性装饰器
199
+ * @param store_key 保存数据到存档数据对象的key
200
+ * @returns
201
+ */
202
+ function archiveStateGetterWithSerializer(_this, store_key, old_getter, serializer) {
203
+ const core = _this._core;
204
+ // if (!core.storage._archiveStateGetterRegisteredList.has(store_key)) {
205
+ // core.storage._archiveStateGetterRegisteredList.add(store_key);
206
+ // core.on("initArchiveData", () => {
207
+ // core.storage.setSaveableData(
208
+ // core.storage.archiveData,
209
+ // true,
210
+ // serializer.call(_this, old_getter.call(_this)),
211
+ // ...store_key.split(".")
212
+ // );
213
+ // });
214
+ // core.on("beforeSaveArchive", () => {
215
+ // core.storage.setSaveableData(
216
+ // core.storage.archiveData,
217
+ // false,
218
+ // serializer.call(_this, old_getter.call(_this)),
219
+ // ...store_key.split(".")
220
+ // );
221
+ // });
222
+ // }
223
+ let val = old_getter.call(_this);
224
+ // console.log(`getval: ${val}`);
225
+ return val;
226
+ }
227
+ function archiveStateSetter(_this, store_key, old_setter, val) {
228
+ // const core = _this._core;
229
+ // if (!core.storage._archiveStateSetterRegisteredList.has(store_key)) {
230
+ // core.storage._archiveStateSetterRegisteredList.add(store_key);
231
+ // core.on("afterLoadArchive", () => {
232
+ // let dataInArchive = core.storage.getSaveableData(
233
+ // core.storage.archiveData,
234
+ // false,
235
+ // ...store_key.split(".")
236
+ // ) as Value;
237
+ // console.log(`Load Data from Archive, store_key: ${store_key}`);
238
+ // old_setter.call(_this, dataInArchive);
239
+ // });
240
+ // }
241
+ old_setter.call(_this, val);
242
+ // console.log(`setval: ${val}`);
243
+ }
244
+ function archiveStateSetterWithDeserializer(_this, store_key, old_setter, val, deserializer) {
245
+ // const core = _this._core;
246
+ // if (!core.storage._archiveStateSetterRegisteredList.has(store_key)) {
247
+ // core.storage._archiveStateSetterRegisteredList.add(store_key);
248
+ // core.on("afterLoadArchive", () => {
249
+ // let dataInArchive = core.storage.getSaveableData(
250
+ // core.storage.archiveData,
251
+ // false,
252
+ // ...store_key.split(".")
253
+ // ) as SerializedValue;
254
+ // console.log(`Load Data from Archive, store_key: ${store_key}`);
255
+ // old_setter.call(_this, deserializer.call(_this, dataInArchive));
256
+ // });
257
+ // }
258
+ old_setter.call(_this, val);
259
+ // console.log(`setval: ${val}`);
260
+ }
@@ -0,0 +1,96 @@
1
+ // import * as hmApp from "@zos/app";
2
+ // import * as hmFS from "@zos/fs";
3
+ // import Path ;
4
+ // function getAppDir(appId = (hmApp.getPackageInfo() as any).appId) {
5
+ // let str = appId.toString(16);
6
+ // switch (str.length) {
7
+ // case 1:
8
+ // return `0000000${str}`.toUpperCase();
9
+ // case 2:
10
+ // return `000000${str}`.toUpperCase();
11
+ // case 3:
12
+ // return `00000${str}`.toUpperCase();
13
+ // case 4:
14
+ // return `0000${str}`.toUpperCase();
15
+ // case 5:
16
+ // return `000${str}`.toUpperCase();
17
+ // case 6:
18
+ // return `00${str}`.toUpperCase();
19
+ // case 7:
20
+ // return `0${str}`.toUpperCase();
21
+ // case 8:
22
+ // return `${str}`.toUpperCase();
23
+ // }
24
+ // }
25
+ export {};
26
+ // function readdirAssetsSync(option: { path: string }): string[] | undefined {
27
+ // return hmFS.readdirSync({
28
+ // path: fromDataToAssetsPath(option.path),
29
+ // });
30
+ // }
31
+ // export function isFileSync(option: { path: string }) {
32
+ // let code = hmFS.openSync({ path: option.path });
33
+ // if (code >= 0) {
34
+ // hmFS.closeSync({ fd: code });
35
+ // return true;
36
+ // } else {
37
+ // return false;
38
+ // }
39
+ // }
40
+ // function isFileAssetsSync(option: { path: string }) {
41
+ // // console.log("path=" + option.path);
42
+ // let code = hmFS.openAssetsSync({ path: option.path });
43
+ // if (code >= 0) {
44
+ // hmFS.closeSync({ fd: code });
45
+ // return true;
46
+ // } else {
47
+ // return false;
48
+ // }
49
+ // }
50
+ // /**
51
+ // * 将基于assets的文件路径转换为基于data的文件路径
52
+ // */
53
+ // function fromDataToAssetsPath(path: string) {
54
+ // return Path.join(`../../${getAppDir()}/assets`, path);
55
+ // }
56
+ // function writeFileAssetsSync(opt: {
57
+ // path: string;
58
+ // data: string | ArrayBuffer | DataView;
59
+ // options?: hmFS.writeFileSync.Options;
60
+ // }) {
61
+ // // console.log("write path="+opt.path);
62
+ // let fd = hmFS.openAssetsSync({
63
+ // path: opt.path,
64
+ // flag: hmFS.O_WRONLY | hmFS.O_CREAT,
65
+ // });
66
+ // if (fd < 0) throw "Open Assets File Failed code=" + fd;
67
+ // let buf = opt.data;
68
+ // if (buf instanceof DataView) {
69
+ // buf = buf.buffer; // TODO maybe error
70
+ // }
71
+ // if (typeof buf === "string") buf = Buffer.from(buf).buffer;
72
+ // let res = hmFS.writeSync({
73
+ // fd,
74
+ // buffer: buf,
75
+ // });
76
+ // hmFS.closeSync({ fd });
77
+ // return res;
78
+ // }
79
+ // function readFileAssetsSync(opt: {
80
+ // path: string;
81
+ // options?: hmFS.readFileSync.Options;
82
+ // }) {
83
+ // // console.log("read path="+opt.path);
84
+ // let fd = hmFS.openAssetsSync({ path: opt.path, flag: hmFS.O_RDONLY });
85
+ // if (fd < 0) throw "Open Assets File Failed code=" + fd;
86
+ // let size = hmFS.statAssetsSync({ path: opt.path })!.size;
87
+ // let arrbuf = new ArrayBuffer(size);
88
+ // let res = hmFS.readSync({ fd, buffer: arrbuf });
89
+ // console.log("read size=" + res);
90
+ // hmFS.closeSync({ fd });
91
+ // if (opt.options && typeof opt.options.encoding === "string") {
92
+ // return Buffer.from(arrbuf).toString(opt.options.encoding);
93
+ // } else {
94
+ // return arrbuf;
95
+ // }
96
+ // }