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,159 @@
1
+ /**
2
+ * 将一行字符串切割为(str,quoted)[]的形式
3
+ * @param str
4
+ * @returns
5
+ */
6
+ export function splitStr2Objs(str: string) {
7
+ // console.log(`splitStr2Objs: ${str}`);
8
+
9
+ let res: { str: string; isQuoted?: boolean; isSquared?: boolean, isRounded?: boolean }[] = [];
10
+ let len = str.length;
11
+ let p = 0;
12
+ while (p < len) {
13
+ while (p < len && str[p] === " ") ++p; // find first not space
14
+ if (p === len) return res;
15
+ if (str[p] === '"') {
16
+ // find next `"`
17
+ let q = p + 1;
18
+ while (q < len && str[q] !== '"') {
19
+ if (str[q] === "\\") q += 2;
20
+ else ++q;
21
+ }
22
+ if (q >= len) throw "Quote not completed";
23
+ let resstr = str.slice(p + 1, q);
24
+ // console.log(`Transformed[${res.length}]:\n${transformStr(resstr)}`);
25
+ let transformedStr: string = "error";
26
+ try {
27
+ transformedStr = transformStr(resstr);
28
+ } catch (e) {
29
+ throw "该字符串中的转义字符有错误:" + resstr;
30
+ }
31
+ res.push({ str: transformedStr!, isQuoted: true });
32
+ p = q + 1;
33
+ } else if (str[p] === "[") {
34
+ // find next `]`
35
+ let q = p + 1;
36
+ while (q < len && str[q] !== "]") {
37
+ // if (str[q] === "\\") q += 2;
38
+ // else ++q;
39
+ ++q;
40
+ }
41
+ if (q >= len) throw "square brackets not completed";
42
+ let resstr = str.slice(p + 1, q);
43
+ res.push({ str: resstr, isSquared: true });
44
+ p = q + 1;
45
+ } else if (str[p] === "(") {
46
+ // find next `)`
47
+ let q = p + 1;
48
+ while (q < len && str[q] !== ")") {
49
+ // if (str[q] === "\\") q += 2;
50
+ // else ++q;
51
+ ++q;
52
+ }
53
+ if (q >= len) throw "round brackets not completed";
54
+ let resstr = str.slice(p + 1, q);
55
+ res.push({ str: resstr, isRounded: true });
56
+ p = q + 1;
57
+ }
58
+ else {
59
+ let q = p + 1;
60
+ while (q < len && str[q] !== " " && str[q] !== '"' && str[q] !== "(" && str[q] !== "[") ++q; // find first space/quote after this
61
+ let resstr = str.slice(p, q);
62
+ // console.log(transformStr(resstr));
63
+ res.push({ str: resstr, isQuoted: false });
64
+ p = q;
65
+ }
66
+ }
67
+ return res;
68
+ }
69
+
70
+ export function mergeObjs2Str(
71
+ objs: { str: string; isQuoted?: boolean; isSquared?: boolean, isRounded?: boolean }[]
72
+ ) {
73
+ return objs
74
+ .map((obj) =>
75
+ obj.isQuoted ? `"${obj.str}"` : obj.isSquared ? `[${obj.str}]` : obj.isRounded ? `(${obj.str})` : obj.str
76
+ )
77
+ .join(" ");
78
+ }
79
+
80
+ export function splitStr2Strs(str: string) {
81
+ return splitStr2Objs(str).map((obj) =>
82
+ obj.isQuoted ? `"${obj.str}"` : obj.str
83
+ );
84
+ }
85
+
86
+ /**
87
+ * 转义一遍字符串,使其中\n等变成对应字符(可能报错)
88
+ * @param str
89
+ * @returns
90
+ */
91
+ export function transformStr(str: string) {
92
+ return JSON.parse(`"${str}"`);
93
+ }
94
+
95
+ // 翻译hzengine script插值字符串
96
+ // 语法:"...[expression]..."
97
+ // 如果希望在字符串中显示`[`,请使用两个`[`,如`"[[正常显示而不被当作表达式的文字]]"`
98
+ export function parseInterpolatedStr(str: string): ParsedInterpolationItem[] {
99
+ let len = str.length;
100
+ let p = 0;
101
+ let expr_record: [l: number, r: number][] = [];
102
+ while (p < len) {
103
+ // 寻找第一个`[`
104
+ while (p < len && str[p] !== "[") ++p;
105
+ if (p >= len) break;
106
+ // 判断是否是两个`[`
107
+ if (str[p] === "[" && str[p + 1] === "[") {
108
+ p += 2;
109
+ continue;
110
+ }
111
+ // 寻找第一个`]`
112
+ let q = p + 1;
113
+ while (q < len && str[q] !== "]") {
114
+ ++q;
115
+ // 判断是否是两个`]`
116
+ while (q < len && str[q] === "]" && str[q + 1] === "]") {
117
+ q += 2;
118
+ }
119
+ }
120
+ if (q >= len) {
121
+ // 没有找到`]`,报错
122
+ throw `Interpolated string lose closing bracket: ${str}`;
123
+ }
124
+ expr_record.push([p, q]);
125
+ p = q + 1;
126
+ }
127
+ let left = 0,
128
+ right = len;
129
+ let res: ParsedInterpolationItem[] = [];
130
+ for (let i = 0; i < expr_record.length; ++i) {
131
+ let [l, r] = expr_record[i];
132
+ if (l > left) res.push({ str: str.slice(left, l), isExpression: false });
133
+ res.push({ str: str.slice(l + 1, r), isExpression: true });
134
+ left = r + 1;
135
+ }
136
+ if (left < right)
137
+ res.push({ str: str.slice(left, right), isExpression: false });
138
+ return res;
139
+ }
140
+
141
+ export function removeComment(str: string) {
142
+ let quoteNotClosed = false;
143
+ let len = str.length;
144
+ for (let i = 0; i < len; ++i) {
145
+ if (quoteNotClosed && str[i] === `\\`) {
146
+ ++i;
147
+ } else if (str[i] === `"`) {
148
+ quoteNotClosed = !quoteNotClosed;
149
+ } else if (str[i] === "#" && !quoteNotClosed) {
150
+ return str.slice(0, i);
151
+ }
152
+ }
153
+ return str;
154
+ }
155
+
156
+ type ParsedInterpolationItem = {
157
+ str: string;
158
+ isExpression: boolean;
159
+ };
@@ -0,0 +1,473 @@
1
+ import { HZEngineCore, Platform, Storage } from "../index.js";
2
+ import { Async } from "../async/index.js";
3
+
4
+ /**
5
+ * 存档属性装饰器
6
+ * @param store_key 保存数据到存档数据对象的key
7
+ * @returns
8
+ */
9
+ export function Save<
10
+ PlatformType extends Platform,
11
+ This extends { _core: HZEngineCore },
12
+ Value extends Storage.Saveable<Value>
13
+ >(store_key: string) {
14
+ return function (
15
+ target: ClassAccessorDecoratorTarget<This, Value>,
16
+ context: ClassAccessorDecoratorContext<This, Value>
17
+ ) {
18
+ context.addInitializer(function () {
19
+ Async.nextTick(() => {
20
+ const core = this._core;
21
+ core.on("initArchiveData", () => {
22
+ core.storage.setSaveableData(
23
+ core.storage.archiveData,
24
+ true,
25
+ target.get.call(this),
26
+ ...store_key.split(".")
27
+ );
28
+ });
29
+ core.on("beforeSaveArchive", () => {
30
+ core.storage.setSaveableData(
31
+ core.storage.archiveData,
32
+ false,
33
+ target.get.call(this),
34
+ ...store_key.split(".")
35
+ );
36
+ });
37
+
38
+ core.on("afterLoadArchive", () => {
39
+ let dataInArchive = core.storage.getSaveableData(
40
+ core.storage.archiveData,
41
+ false,
42
+ ...store_key.split(".")
43
+ ) as Value;
44
+ this._core.debug.log(
45
+ `Load Data from Archive, store_key: ${store_key}, dataInArchive: ${JSON.stringify(
46
+ dataInArchive
47
+ )}`
48
+ );
49
+ target.set.call(this, dataInArchive);
50
+ });
51
+ });
52
+ });
53
+ if (context.kind !== "accessor") {
54
+ throw new Error("ArchiveStateAccessor只能用于accessor属性");
55
+ }
56
+ return {
57
+ get() {
58
+ target = target as ClassAccessorDecoratorTarget<This, Value>;
59
+ return archiveStateGetter<PlatformType, This, Value>(this, store_key, target.get);
60
+ },
61
+ set(value) {
62
+ target = target as ClassAccessorDecoratorTarget<This, Value>;
63
+ archiveStateSetter<PlatformType, This, Value>(this, store_key, target.set, value);
64
+ },
65
+ } as ClassAccessorDecoratorResult<This, Value>;
66
+ };
67
+ }
68
+
69
+ /**
70
+ * 存档属性装饰器
71
+ * @param store_key 保存数据到存档数据对象的key
72
+ * @returns
73
+ */
74
+ export function CustomSave<
75
+ PlatformType extends Platform,
76
+ This extends { _core: HZEngineCore },
77
+ Value,
78
+ SerializedValue extends Storage.Saveable<SerializedValue>
79
+ >(
80
+ store_key: string,
81
+ serializer: (this: This, value: Value) => SerializedValue,
82
+ deserializer: (this: This, value: SerializedValue) => Value
83
+ ) {
84
+ return (
85
+ target: ClassAccessorDecoratorTarget<This, Value>,
86
+ context: ClassAccessorDecoratorContext<This, Value>
87
+ ) => {
88
+ if (context.kind !== "accessor") {
89
+ throw new Error("ArchiveStateAccessor只能用于accessor属性");
90
+ }
91
+ context.addInitializer(function () {
92
+ Async.nextTick(() => {
93
+ const core = this._core;
94
+ core.on("initArchiveData", () => {
95
+ core.storage.setSaveableData(
96
+ core.storage.archiveData,
97
+ true,
98
+ serializer.call(this, target.get.call(this)),
99
+ ...store_key.split(".")
100
+ );
101
+ });
102
+ core.on("beforeSaveArchive", () => {
103
+ core.storage.setSaveableData(
104
+ core.storage.archiveData,
105
+ false,
106
+ serializer.call(this, target.get.call(this)),
107
+ ...store_key.split(".")
108
+ );
109
+ });
110
+
111
+ core.on("afterLoadArchive", () => {
112
+ let dataInArchive = core.storage.getSaveableData(
113
+ core.storage.archiveData,
114
+ false,
115
+ ...store_key.split(".")
116
+ ) as SerializedValue;
117
+ this._core.debug.log(
118
+ `Load Data from Archive, store_key: ${store_key}, dataInArchive: ${JSON.stringify(
119
+ dataInArchive
120
+ )}`
121
+ );
122
+ target.set.call(this, deserializer.call(this, dataInArchive));
123
+ });
124
+ });
125
+ });
126
+ return {
127
+ get() {
128
+ target = target as ClassAccessorDecoratorTarget<This, Value>;
129
+ return archiveStateGetterWithSerializer<PlatformType, This, Value, SerializedValue>(
130
+ this,
131
+ store_key,
132
+ target.get,
133
+ serializer
134
+ );
135
+ },
136
+ set(value) {
137
+ target = target as ClassAccessorDecoratorTarget<This, Value>;
138
+ archiveStateSetterWithDeserializer<PlatformType, This, Value, SerializedValue>(
139
+ this,
140
+ store_key,
141
+ target.set,
142
+ value,
143
+ deserializer
144
+ );
145
+ },
146
+ } as ClassAccessorDecoratorResult<This, Value>;
147
+ };
148
+ }
149
+
150
+ export function SaveGetter<
151
+ PlatformType extends Platform,
152
+ This extends { _core: HZEngineCore<PlatformType> },
153
+ Value extends Storage.Saveable<Value>
154
+ >(store_key: string) {
155
+ return (
156
+ target: ClassGetterDecoratorTarget<PlatformType, This, Value>,
157
+ context: ClassGetterDecoratorContext<This, Value>
158
+ ) => {
159
+ context.addInitializer(function () {
160
+ Async.nextTick(() => {
161
+ const core = this._core;
162
+ core.on("initArchiveData", () => {
163
+ core.storage.setSaveableData(
164
+ core.storage.archiveData,
165
+ true,
166
+ target.call(this),
167
+ ...store_key.split(".")
168
+ );
169
+ });
170
+ core.on("beforeSaveArchive", () => {
171
+ core.storage.setSaveableData(
172
+ core.storage.archiveData,
173
+ false,
174
+ target.call(this),
175
+ ...store_key.split(".")
176
+ );
177
+ });
178
+ });
179
+ });
180
+ if (context.kind !== "getter") {
181
+ throw new Error("ArchiveStateGetter只能用于getter属性");
182
+ }
183
+ return function (this: This) {
184
+ let val = archiveStateGetter<PlatformType, This, Value>(
185
+ this,
186
+ store_key,
187
+ target as ClassGetterDecoratorTarget<PlatformType, This, Value>
188
+ );
189
+ return val;
190
+ };
191
+ };
192
+ }
193
+
194
+ export function CustomSaveGetter<
195
+ PlatformType extends Platform,
196
+ This extends { _core: HZEngineCore<PlatformType> },
197
+ Value,
198
+ SerializedValue extends Storage.Saveable<SerializedValue>
199
+ >(
200
+ store_key: string,
201
+ serializer: (this: This, value: Value) => SerializedValue
202
+ ) {
203
+ return (
204
+ target: ClassGetterDecoratorTarget<PlatformType, This, Value>,
205
+ context: ClassGetterDecoratorContext<This, Value>
206
+ ) => {
207
+ if (context.kind !== "getter") {
208
+ throw new Error("ArchiveStateGetter只能用于getter属性");
209
+ }
210
+ context.addInitializer(function () {
211
+ Async.nextTick(() => {
212
+ const core = this._core;
213
+ core.on("initArchiveData", () => {
214
+ core.storage.setSaveableData(
215
+ core.storage.archiveData,
216
+ true,
217
+ serializer.call(this, target.call(this)),
218
+ ...store_key.split(".")
219
+ );
220
+ });
221
+ core.on("beforeSaveArchive", () => {
222
+ core.storage.setSaveableData(
223
+ core.storage.archiveData,
224
+ false,
225
+ serializer.call(this, target.call(this)),
226
+ ...store_key.split(".")
227
+ );
228
+ });
229
+ });
230
+ });
231
+ return function (this: This) {
232
+ let val = archiveStateGetterWithSerializer<PlatformType, This, Value, SerializedValue>(
233
+ this,
234
+ store_key,
235
+ target as ClassGetterDecoratorTarget<PlatformType, This, Value>,
236
+ serializer
237
+ );
238
+ return val;
239
+ };
240
+ };
241
+ }
242
+
243
+ /**
244
+ * 存档属性装饰器
245
+ * @param store_key 保存数据到存档数据对象的key
246
+ * @returns
247
+ */
248
+ export function SaveSetter<
249
+ PlatformType extends Platform,
250
+ This extends { _core: HZEngineCore<PlatformType> },
251
+ Value extends Storage.Saveable<Value>
252
+ >(store_key: string) {
253
+ return (
254
+ target: ClassSetterDecoratorTarget<PlatformType, This, Value>,
255
+ context: ClassSetterDecoratorContext<This, Value>
256
+ ) => {
257
+ if (context.kind !== "setter") {
258
+ throw new Error("ArchiveStateSetter只能用于setter属性");
259
+ }
260
+ context.addInitializer(function () {
261
+ Async.nextTick(() => {
262
+ let core = this._core;
263
+ core.on("afterLoadArchive", () => {
264
+ let dataInArchive = core.storage.getSaveableData(
265
+ core.storage.archiveData,
266
+ false,
267
+ ...store_key.split(".")
268
+ ) as Value;
269
+ this._core.debug.log(
270
+ `Load Data from Archive, store_key: ${store_key}, dataInArchive: ${JSON.stringify(
271
+ dataInArchive
272
+ )}`
273
+ );
274
+ target.call(this, dataInArchive);
275
+ });
276
+ });
277
+ });
278
+ return function (this: This, value: Value) {
279
+ archiveStateSetter<PlatformType, This, Value>(
280
+ this,
281
+ store_key,
282
+ target as ClassSetterDecoratorTarget< PlatformType, This, Value>,
283
+ value
284
+ );
285
+ };
286
+ };
287
+ }
288
+
289
+ export function CustomSaveSetter<
290
+ PlatformType extends Platform,
291
+ This extends { _core: HZEngineCore<PlatformType> },
292
+ Value,
293
+ SerializedValue extends Storage.Saveable<SerializedValue>
294
+ >(
295
+ store_key: string,
296
+ deserializer: (this: This, value: SerializedValue) => Value
297
+ ) {
298
+ return (
299
+ target: ClassSetterDecoratorTarget<PlatformType, This, Value>,
300
+ context: ClassSetterDecoratorContext<This, Value>
301
+ ) => {
302
+ if (context.kind !== "setter") {
303
+ throw new Error("ArchiveStateSetter只能用于setter属性");
304
+ }
305
+ context.addInitializer(function () {
306
+ Async.nextTick(() => {
307
+ let core = this._core;
308
+ core.on("afterLoadArchive", () => {
309
+ let dataInArchive = core.storage.getSaveableData(
310
+ core.storage.archiveData,
311
+ false,
312
+ ...store_key.split(".")
313
+ ) as SerializedValue;
314
+ this._core.debug.log(
315
+ `Load Data from Archive, store_key: ${store_key}, dataInArchive: ${JSON.stringify(
316
+ dataInArchive
317
+ )}`
318
+ );
319
+ target.call(this, deserializer.call(this, dataInArchive));
320
+ });
321
+ });
322
+ });
323
+ return function (this: This, value: Value) {
324
+ archiveStateSetterWithDeserializer<PlatformType, This, Value, SerializedValue>(
325
+ this,
326
+ store_key,
327
+ target as ClassSetterDecoratorTarget<PlatformType, This, Value>,
328
+ value,
329
+ deserializer
330
+ );
331
+ };
332
+ };
333
+ }
334
+
335
+ /**
336
+ * 存档属性装饰器
337
+ * @param store_key 保存数据到存档数据对象的key
338
+ * @returns
339
+ */
340
+ function archiveStateGetter<
341
+ PlatformType extends Platform,
342
+ This extends { _core: HZEngineCore<PlatformType> },
343
+ Value extends Storage.Saveable<Value>
344
+ >(_this: This, store_key: string, old_getter: (this: This) => Value) {
345
+ const core = _this._core;
346
+ // if (!core.storage._archiveStateGetterRegisteredList.has(store_key)) {
347
+ // core.storage._archiveStateGetterRegisteredList.add(store_key);
348
+ // core.on("initArchiveData", () => {
349
+ // core.storage.setSaveableData(
350
+ // core.storage.archiveData,
351
+ // true,
352
+ // old_getter.call(_this),
353
+ // ...store_key.split(".")
354
+ // );
355
+ // });
356
+ // core.on("beforeSaveArchive", () => {
357
+ // core.storage.setSaveableData(
358
+ // core.storage.archiveData,
359
+ // false,
360
+ // old_getter.call(_this),
361
+ // ...store_key.split(".")
362
+ // );
363
+ // });
364
+ // }
365
+ let val = old_getter.call(_this);
366
+ // console.log(`getval: ${val}`);
367
+ return val;
368
+ }
369
+
370
+ /**
371
+ * 存档属性装饰器
372
+ * @param store_key 保存数据到存档数据对象的key
373
+ * @returns
374
+ */
375
+ function archiveStateGetterWithSerializer<
376
+ PlatformType extends Platform,
377
+ This extends { _core: HZEngineCore<PlatformType> },
378
+ Value,
379
+ SerializedValue extends Storage.Saveable<SerializedValue>
380
+ >(
381
+ _this: This,
382
+ store_key: string,
383
+ old_getter: (this: This) => Value,
384
+ serializer: (this: This, value: Value) => SerializedValue
385
+ ) {
386
+ const core = _this._core;
387
+ // if (!core.storage._archiveStateGetterRegisteredList.has(store_key)) {
388
+ // core.storage._archiveStateGetterRegisteredList.add(store_key);
389
+ // core.on("initArchiveData", () => {
390
+ // core.storage.setSaveableData(
391
+ // core.storage.archiveData,
392
+ // true,
393
+ // serializer.call(_this, old_getter.call(_this)),
394
+ // ...store_key.split(".")
395
+ // );
396
+ // });
397
+ // core.on("beforeSaveArchive", () => {
398
+ // core.storage.setSaveableData(
399
+ // core.storage.archiveData,
400
+ // false,
401
+ // serializer.call(_this, old_getter.call(_this)),
402
+ // ...store_key.split(".")
403
+ // );
404
+ // });
405
+ // }
406
+ let val = old_getter.call(_this);
407
+ // console.log(`getval: ${val}`);
408
+ return val;
409
+ }
410
+
411
+ function archiveStateSetter<
412
+ PlatformType extends Platform,
413
+ This extends { _core: HZEngineCore<PlatformType> },
414
+ Value extends Storage.Saveable<Value>
415
+ >(
416
+ _this: This,
417
+ store_key: string,
418
+ old_setter: (this: This, value: Value) => void,
419
+ val: Value
420
+ ) {
421
+ // const core = _this._core;
422
+ // if (!core.storage._archiveStateSetterRegisteredList.has(store_key)) {
423
+ // core.storage._archiveStateSetterRegisteredList.add(store_key);
424
+ // core.on("afterLoadArchive", () => {
425
+ // let dataInArchive = core.storage.getSaveableData(
426
+ // core.storage.archiveData,
427
+ // false,
428
+ // ...store_key.split(".")
429
+ // ) as Value;
430
+ // console.log(`Load Data from Archive, store_key: ${store_key}`);
431
+ // old_setter.call(_this, dataInArchive);
432
+ // });
433
+ // }
434
+ old_setter.call(_this, val);
435
+ // console.log(`setval: ${val}`);
436
+ }
437
+
438
+ function archiveStateSetterWithDeserializer<
439
+ PlatformType extends Platform,
440
+ This extends { _core: HZEngineCore<PlatformType> },
441
+ Value,
442
+ SerializedValue extends Storage.Saveable<SerializedValue>
443
+ >(
444
+ _this: This,
445
+ store_key: string,
446
+ old_setter: (this: This, value: Value) => void,
447
+ val: Value,
448
+ deserializer: (this: This, value: SerializedValue) => Value
449
+ ) {
450
+ // const core = _this._core;
451
+ // if (!core.storage._archiveStateSetterRegisteredList.has(store_key)) {
452
+ // core.storage._archiveStateSetterRegisteredList.add(store_key);
453
+ // core.on("afterLoadArchive", () => {
454
+ // let dataInArchive = core.storage.getSaveableData(
455
+ // core.storage.archiveData,
456
+ // false,
457
+ // ...store_key.split(".")
458
+ // ) as SerializedValue;
459
+ // console.log(`Load Data from Archive, store_key: ${store_key}`);
460
+ // old_setter.call(_this, deserializer.call(_this, dataInArchive));
461
+ // });
462
+ // }
463
+ old_setter.call(_this, val);
464
+ // console.log(`setval: ${val}`);
465
+ }
466
+
467
+ type ClassGetterDecoratorTarget<PlatformType extends Platform, This extends { _core: HZEngineCore<PlatformType> }, Value> = (
468
+ this: This
469
+ ) => Value;
470
+ type ClassSetterDecoratorTarget<PlatformType extends Platform, This extends { _core: HZEngineCore<PlatformType> }, Value> = (
471
+ this: This,
472
+ value: Value
473
+ ) => void;