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.
@@ -1,260 +1,249 @@
1
- var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
2
- function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
3
- var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
4
- var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
5
- var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
6
- var _, done = false;
7
- for (var i = decorators.length - 1; i >= 0; i--) {
8
- var context = {};
9
- for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
10
- for (var p in contextIn.access) context.access[p] = contextIn.access[p];
11
- context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
12
- var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
13
- if (kind === "accessor") {
14
- if (result === void 0) continue;
15
- if (result === null || typeof result !== "object") throw new TypeError("Object expected");
16
- if (_ = accept(result.get)) descriptor.get = _;
17
- if (_ = accept(result.set)) descriptor.set = _;
18
- if (_ = accept(result.init)) initializers.unshift(_);
19
- }
20
- else if (_ = accept(result)) {
21
- if (kind === "field") initializers.unshift(_);
22
- else descriptor[key] = _;
23
- }
24
- }
25
- if (target) Object.defineProperty(target, contextIn.name, descriptor);
26
- done = true;
27
- };
28
- var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
29
- var useValue = arguments.length > 2;
30
- for (var i = 0; i < initializers.length; i++) {
31
- value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
32
- }
33
- return useValue ? value : void 0;
34
- };
35
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
36
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
37
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
38
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
39
- };
40
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
41
- if (kind === "m") throw new TypeError("Private method is not writable");
42
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
43
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
44
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
45
- };
46
- // / <reference path="./zos_media.d.ts" />
47
- // import { create, id } from "@zos/media";
48
- import { CustomSave } from "../storage/decorator.js";
49
- let Audio = (() => {
50
- var _a, _Audio__channels_accessor_storage;
51
- let __channels_decorators;
52
- let __channels_initializers = [];
53
- let __channels_extraInitializers = [];
54
- return _a = class Audio {
55
- // static _hmPlayer = create(id.PLAYER);
56
- constructor(_core) {
57
- this._core = _core;
58
- _Audio__channels_accessor_storage.set(this, __runInitializers(this, __channels_initializers, {}));
59
- __runInitializers(this, __channels_extraInitializers);
60
- this._core = _core;
61
- this._channels["audio"] = new _a.Channel(this);
62
- }
63
- get _channels() { return __classPrivateFieldGet(this, _Audio__channels_accessor_storage, "f"); }
64
- set _channels(value) { __classPrivateFieldSet(this, _Audio__channels_accessor_storage, value, "f"); }
65
- get channels() {
66
- return this._channels;
67
- }
68
- createChannel(name) {
69
- // TODO support more audio channels
70
- if (Object.getOwnPropertyNames(this._channels).length > 0)
71
- throw "Can't create more than one audio channel on ZeppOS";
72
- if (this._channels[name])
73
- throw "Channel Already Exist";
74
- return (this._channels[name] = new _a.Channel(this));
75
- }
76
- },
77
- _Audio__channels_accessor_storage = new WeakMap(),
78
- (() => {
79
- const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
80
- __channels_decorators = [CustomSave("audio.channels", function (channels) {
81
- let res = {};
82
- for (let key in channels) {
83
- res[key] = channels[key].serialize();
84
- }
85
- return res;
86
- }, function (serialized) {
87
- // clear exist channels
88
- for (let key in this._channels) {
89
- this._channels[key].stop();
90
- this._channels[key].onRelease();
91
- }
92
- let res = {};
93
- for (let key in serialized) {
94
- res[key] = Audio.Channel.deserialize(this, serialized[key]);
95
- }
96
- return res;
97
- })];
98
- __esDecorate(_a, null, __channels_decorators, { kind: "accessor", name: "_channels", static: false, private: false, access: { has: obj => "_channels" in obj, get: obj => obj._channels, set: (obj, value) => { obj._channels = value; } }, metadata: _metadata }, __channels_initializers, __channels_extraInitializers);
99
- if (_metadata) Object.defineProperty(_a, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
100
- })(),
101
- _a;
102
- })();
103
- export { Audio };
104
- (function (Audio) {
105
- class Channel {
106
- constructor(_audio) {
107
- this._audio = _audio;
108
- this.mode = Channel.Mode.PlayInOrder;
109
- this.status = Channel.Status.Stopped;
110
- this._playbackList = [];
111
- this._nowIndex = null;
112
- this.currentInfo = null;
113
- this._audioPlayer = _audio._core.platform.createAudioPlayer();
114
- this._audioPlayer.onPrepared = (success) => {
115
- this._onPrepared(success);
116
- };
117
- this._audioPlayer.onCompleted = () => {
118
- this._onCompleted();
119
- };
120
- // Audio._hmPlayer.addEventListener(Audio._hmPlayer.event.PREPARE, (res) =>
121
- // this._onPrepared(res)
122
- // );
123
- // Audio._hmPlayer.addEventListener(Audio._hmPlayer.event.COMPLETE, () => {
124
- // this._onCompleted();
125
- // });
126
- }
127
- onRelease() {
128
- this._audioPlayer.release(); // TODO
129
- this._audio._core.platform.releaseAudioPlayer(this._audioPlayer);
130
- }
131
- push(item) {
132
- this._playbackList.push(item);
133
- }
134
- play() {
135
- if (this.status !== Channel.Status.Stopped)
136
- return;
137
- this._playNext();
138
- }
139
- pause() {
140
- if (this.status !== Channel.Status.Playing)
141
- return;
142
- this._audioPlayer.stop();
143
- this.status = Channel.Status.Stopped;
144
- }
145
- /**
146
- * 停止并清空队列
147
- */
148
- stop() {
149
- if (this.status !== Channel.Status.Playing)
150
- return;
151
- this._audio._core.debug.log("audio channel stop");
152
- this._audioPlayer.stop();
153
- this._playbackList = [];
154
- this.currentInfo = null;
155
- this._nowIndex = null;
156
- this.status = Channel.Status.Stopped;
157
- }
158
- serialize() {
159
- return {
160
- mode: this.mode,
161
- status: this.status,
162
- playbackList: this._playbackList,
163
- nowIndex: this._nowIndex,
164
- };
165
- }
166
- static deserialize(audio, data) {
167
- let channel = new Channel(audio);
168
- channel.mode = data.mode;
169
- channel.status = data.status;
170
- channel._playbackList = data.playbackList;
171
- channel._nowIndex = data.nowIndex;
172
- if (channel.status === Channel.Status.Playing)
173
- channel._playNext();
174
- return channel;
175
- }
176
- _onPrepared(result) {
177
- var _a, _b;
178
- if (result) {
179
- let mediaInfo = this._audioPlayer.getMediaInfo();
180
- this.currentInfo = {
181
- // placeholder
182
- artist: (_a = mediaInfo.artist) !== null && _a !== void 0 ? _a : "未知",
183
- title: (_b = mediaInfo.title) !== null && _b !== void 0 ? _b : "未知",
184
- duration: mediaInfo.duration,
185
- };
186
- console.log("=== prepare succeed ===");
187
- this._audioPlayer.start();
188
- }
189
- else {
190
- console.log("=== prepare fail ===");
191
- this.status = Channel.Status.Error;
192
- this._audioPlayer.release();
193
- }
194
- }
195
- _onCompleted() {
196
- // update playback list
197
- if (this.mode === Channel.Mode.PlayInOrder) {
198
- this._playbackList.shift();
199
- if (this._playbackList.length > 0)
200
- this._nowIndex = 0;
201
- else
202
- this._nowIndex = null;
203
- }
204
- else if (this.mode === Channel.Mode.PlayInOrderRepeat) {
205
- if (this._playbackList.length > 0) {
206
- if (this._nowIndex === null)
207
- this._nowIndex = 0;
208
- this._nowIndex = (this._nowIndex + 1) % this._playbackList.length;
209
- }
210
- else
211
- this._nowIndex = null;
212
- }
213
- this._playNext();
214
- }
215
- /**
216
- * Play the next item in the playback list. If there are no items in the
217
- * playback list, set the channel status to Stopped and return.
218
- * @private
219
- */
220
- _playNext() {
221
- if (this._playbackList.length === 0) {
222
- this._nowIndex = null;
223
- this.status = Channel.Status.Stopped;
224
- return;
225
- }
226
- if (this.mode === Channel.Mode.PlayInOrder) {
227
- if (this._nowIndex === null)
228
- this._nowIndex = 0;
229
- // otherwise onCompleted will set _nowIndex to next index
230
- }
231
- else if (this.mode === Channel.Mode.PlayInOrderRepeat) {
232
- if (this._nowIndex === null)
233
- this._nowIndex = 0;
234
- // otherwise onCompleted will set _nowIndex to next index
235
- }
236
- // Audio._hmPlayer.setSource(Audio._hmPlayer.source.FILE, {
237
- // file: this._playbackList[this._nowIndex!].path,
238
- // });
239
- this._audioPlayer.setSource({
240
- path: this._playbackList[this._nowIndex].path,
241
- });
242
- this._audioPlayer.prepare();
243
- this.status = Channel.Status.Playing;
244
- }
245
- }
246
- Audio.Channel = Channel;
247
- (function (Channel) {
248
- let Mode;
249
- (function (Mode) {
250
- Mode[Mode["PlayInOrder"] = 0] = "PlayInOrder";
251
- Mode[Mode["PlayInOrderRepeat"] = 1] = "PlayInOrderRepeat";
252
- })(Mode = Channel.Mode || (Channel.Mode = {}));
253
- let Status;
254
- (function (Status) {
255
- Status[Status["Stopped"] = 0] = "Stopped";
256
- Status[Status["Playing"] = 1] = "Playing";
257
- Status[Status["Error"] = 2] = "Error";
258
- })(Status = Channel.Status || (Channel.Status = {}));
259
- })(Channel = Audio.Channel || (Audio.Channel = {}));
260
- })(Audio || (Audio = {}));
1
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
2
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
3
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
4
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
5
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
6
+ var _, done = false;
7
+ for (var i = decorators.length - 1; i >= 0; i--) {
8
+ var context = {};
9
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
10
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
11
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
12
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
13
+ if (kind === "accessor") {
14
+ if (result === void 0) continue;
15
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
16
+ if (_ = accept(result.get)) descriptor.get = _;
17
+ if (_ = accept(result.set)) descriptor.set = _;
18
+ if (_ = accept(result.init)) initializers.unshift(_);
19
+ }
20
+ else if (_ = accept(result)) {
21
+ if (kind === "field") initializers.unshift(_);
22
+ else descriptor[key] = _;
23
+ }
24
+ }
25
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
26
+ done = true;
27
+ };
28
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
29
+ var useValue = arguments.length > 2;
30
+ for (var i = 0; i < initializers.length; i++) {
31
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
32
+ }
33
+ return useValue ? value : void 0;
34
+ };
35
+ // / <reference path="./zos_media.d.ts" />
36
+ // import { create, id } from "@zos/media";
37
+ import { CustomSave } from "../storage/decorator.js";
38
+ let Audio = (() => {
39
+ let __channels_decorators;
40
+ let __channels_initializers = [];
41
+ let __channels_extraInitializers = [];
42
+ return class Audio {
43
+ static {
44
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
45
+ __channels_decorators = [CustomSave("audio.channels", function (channels) {
46
+ let res = {};
47
+ for (let key in channels) {
48
+ res[key] = channels[key].serialize();
49
+ }
50
+ return res;
51
+ }, function (serialized) {
52
+ // clear exist channels
53
+ for (let key in this._channels) {
54
+ this._channels[key].stop();
55
+ this._channels[key].onRelease();
56
+ }
57
+ let res = {};
58
+ for (let key in serialized) {
59
+ res[key] = Audio.Channel.deserialize(this, serialized[key]);
60
+ }
61
+ return res;
62
+ })];
63
+ __esDecorate(this, null, __channels_decorators, { kind: "accessor", name: "_channels", static: false, private: false, access: { has: obj => "_channels" in obj, get: obj => obj._channels, set: (obj, value) => { obj._channels = value; } }, metadata: _metadata }, __channels_initializers, __channels_extraInitializers);
64
+ if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
65
+ }
66
+ _core;
67
+ // static _hmPlayer = create(id.PLAYER);
68
+ constructor(_core) {
69
+ __runInitializers(this, __channels_extraInitializers);
70
+ this._core = _core;
71
+ this._channels["audio"] = new Audio.Channel(this);
72
+ }
73
+ #_channels_accessor_storage = __runInitializers(this, __channels_initializers, {});
74
+ get _channels() { return this.#_channels_accessor_storage; }
75
+ set _channels(value) { this.#_channels_accessor_storage = value; }
76
+ get channels() {
77
+ return this._channels;
78
+ }
79
+ createChannel(name) {
80
+ // TODO support more audio channels
81
+ if (Object.getOwnPropertyNames(this._channels).length > 0)
82
+ throw "Can't create more than one audio channel on ZeppOS";
83
+ if (this._channels[name])
84
+ throw "Channel Already Exist";
85
+ return (this._channels[name] = new Audio.Channel(this));
86
+ }
87
+ };
88
+ })();
89
+ export { Audio };
90
+ (function (Audio) {
91
+ class Channel {
92
+ _audio;
93
+ // platform specific
94
+ // universal
95
+ _audioPlayer;
96
+ constructor(_audio) {
97
+ this._audio = _audio;
98
+ this._audioPlayer = _audio._core.platform.createAudioPlayer();
99
+ this._audioPlayer.onPrepared = (success) => {
100
+ this._onPrepared(success);
101
+ };
102
+ this._audioPlayer.onCompleted = () => {
103
+ this._onCompleted();
104
+ };
105
+ // Audio._hmPlayer.addEventListener(Audio._hmPlayer.event.PREPARE, (res) =>
106
+ // this._onPrepared(res)
107
+ // );
108
+ // Audio._hmPlayer.addEventListener(Audio._hmPlayer.event.COMPLETE, () => {
109
+ // this._onCompleted();
110
+ // });
111
+ }
112
+ onRelease() {
113
+ this._audioPlayer.release(); // TODO
114
+ this._audio._core.platform.releaseAudioPlayer(this._audioPlayer);
115
+ }
116
+ mode = Channel.Mode.PlayInOrder;
117
+ status = Channel.Status.Stopped;
118
+ _playbackList = [];
119
+ _nowIndex = null;
120
+ currentInfo = null;
121
+ push(item) {
122
+ this._playbackList.push(item);
123
+ }
124
+ play() {
125
+ if (this.status !== Channel.Status.Stopped)
126
+ return;
127
+ this._playNext();
128
+ }
129
+ pause() {
130
+ if (this.status !== Channel.Status.Playing)
131
+ return;
132
+ this._audioPlayer.stop();
133
+ this.status = Channel.Status.Stopped;
134
+ }
135
+ /**
136
+ * 停止并清空队列
137
+ */
138
+ stop() {
139
+ if (this.status !== Channel.Status.Playing)
140
+ return;
141
+ this._audio._core.debug.log("audio channel stop");
142
+ this._audioPlayer.stop();
143
+ this._playbackList = [];
144
+ this.currentInfo = null;
145
+ this._nowIndex = null;
146
+ this.status = Channel.Status.Stopped;
147
+ }
148
+ serialize() {
149
+ return {
150
+ mode: this.mode,
151
+ status: this.status,
152
+ playbackList: this._playbackList,
153
+ nowIndex: this._nowIndex,
154
+ };
155
+ }
156
+ static deserialize(audio, data) {
157
+ let channel = new Channel(audio);
158
+ channel.mode = data.mode;
159
+ channel.status = data.status;
160
+ channel._playbackList = data.playbackList;
161
+ channel._nowIndex = data.nowIndex;
162
+ if (channel.status === Channel.Status.Playing)
163
+ channel._playNext();
164
+ return channel;
165
+ }
166
+ _onPrepared(result) {
167
+ if (result) {
168
+ let mediaInfo = this._audioPlayer.getMediaInfo();
169
+ this.currentInfo = {
170
+ // placeholder
171
+ artist: mediaInfo.artist ?? "未知",
172
+ title: mediaInfo.title ?? "未知",
173
+ duration: mediaInfo.duration,
174
+ };
175
+ console.log("=== prepare succeed ===");
176
+ this._audioPlayer.start();
177
+ }
178
+ else {
179
+ console.log("=== prepare fail ===");
180
+ this.status = Channel.Status.Error;
181
+ this._audioPlayer.release();
182
+ }
183
+ }
184
+ _onCompleted() {
185
+ // update playback list
186
+ if (this.mode === Channel.Mode.PlayInOrder) {
187
+ this._playbackList.shift();
188
+ if (this._playbackList.length > 0)
189
+ this._nowIndex = 0;
190
+ else
191
+ this._nowIndex = null;
192
+ }
193
+ else if (this.mode === Channel.Mode.PlayInOrderRepeat) {
194
+ if (this._playbackList.length > 0) {
195
+ if (this._nowIndex === null)
196
+ this._nowIndex = 0;
197
+ this._nowIndex = (this._nowIndex + 1) % this._playbackList.length;
198
+ }
199
+ else
200
+ this._nowIndex = null;
201
+ }
202
+ this._playNext();
203
+ }
204
+ /**
205
+ * Play the next item in the playback list. If there are no items in the
206
+ * playback list, set the channel status to Stopped and return.
207
+ * @private
208
+ */
209
+ _playNext() {
210
+ if (this._playbackList.length === 0) {
211
+ this._nowIndex = null;
212
+ this.status = Channel.Status.Stopped;
213
+ return;
214
+ }
215
+ if (this.mode === Channel.Mode.PlayInOrder) {
216
+ if (this._nowIndex === null)
217
+ this._nowIndex = 0;
218
+ // otherwise onCompleted will set _nowIndex to next index
219
+ }
220
+ else if (this.mode === Channel.Mode.PlayInOrderRepeat) {
221
+ if (this._nowIndex === null)
222
+ this._nowIndex = 0;
223
+ // otherwise onCompleted will set _nowIndex to next index
224
+ }
225
+ // Audio._hmPlayer.setSource(Audio._hmPlayer.source.FILE, {
226
+ // file: this._playbackList[this._nowIndex!].path,
227
+ // });
228
+ this._audioPlayer.setSource({
229
+ path: this._playbackList[this._nowIndex].path,
230
+ });
231
+ this._audioPlayer.prepare();
232
+ this.status = Channel.Status.Playing;
233
+ }
234
+ }
235
+ Audio.Channel = Channel;
236
+ (function (Channel) {
237
+ let Mode;
238
+ (function (Mode) {
239
+ Mode[Mode["PlayInOrder"] = 0] = "PlayInOrder";
240
+ Mode[Mode["PlayInOrderRepeat"] = 1] = "PlayInOrderRepeat";
241
+ })(Mode = Channel.Mode || (Channel.Mode = {}));
242
+ let Status;
243
+ (function (Status) {
244
+ Status[Status["Stopped"] = 0] = "Stopped";
245
+ Status[Status["Playing"] = 1] = "Playing";
246
+ Status[Status["Error"] = 2] = "Error";
247
+ })(Status = Channel.Status || (Channel.Status = {}));
248
+ })(Channel = Audio.Channel || (Audio.Channel = {}));
249
+ })(Audio || (Audio = {}));
@@ -1,57 +1,57 @@
1
- export class Config {
2
- constructor(_core) {
3
- this._core = _core;
4
- _core.on("initGlobalData", () => {
5
- _core.storage.setSaveableData(_core.storage.globalData, true, Object.assign({}, defaultConfig), "config");
6
- });
7
- _core.on("afterLoadGlobalData", () => {
8
- var _a;
9
- if (!((_a = _core.storage.globalData) === null || _a === void 0 ? void 0 : _a.config)) {
10
- _core.storage.setSaveableData(_core.storage.globalData, true, Object.assign({}, defaultConfig), "config");
11
- }
12
- _core.storage.saveGlobalData();
13
- });
14
- }
15
- getConfig(key) {
16
- let keys = this.normalizeKey(key);
17
- // this._core.debug.log(`getConfig keys = ${JSON.stringify(keys)}`);
18
- if (keys == null)
19
- return;
20
- try {
21
- let res = this._core.storage.getSaveableData(this._core.storage.globalData, false, "config", ...keys);
22
- // this._core.debug.log(`getConfig res = ${JSON.stringify(res)}`);
23
- return res;
24
- }
25
- catch (e) {
26
- // this._core.debug.log(`getConfig error`,e);
27
- return;
28
- }
29
- }
30
- setConfig(key, value) {
31
- let keys = this.normalizeKey(key);
32
- if (keys == null)
33
- return;
34
- this._core.storage.setSaveableData(this._core.storage.globalData, true, value, "config", ...keys);
35
- this._core.storage.saveGlobalData();
36
- }
37
- normalizeKey(key) {
38
- let keys = [];
39
- key.split(".").forEach((key) => {
40
- if (key.trim().length > 0)
41
- keys.push(key);
42
- else
43
- return null;
44
- });
45
- return keys;
46
- }
47
- resetConfig() { }
48
- }
49
- const defaultConfig = {
50
- game: {
51
- autoplay: {
52
- enable: false,
53
- ms_per_char: 150,
54
- extra_delay: 1300,
55
- },
56
- },
57
- };
1
+ export class Config {
2
+ _core;
3
+ constructor(_core) {
4
+ this._core = _core;
5
+ _core.on("initGlobalData", () => {
6
+ _core.storage.setSaveableData(_core.storage.globalData, true, { ...defaultConfig }, "config");
7
+ });
8
+ _core.on("afterLoadGlobalData", () => {
9
+ if (!_core.storage.globalData?.config) {
10
+ _core.storage.setSaveableData(_core.storage.globalData, true, { ...defaultConfig }, "config");
11
+ }
12
+ _core.storage.saveGlobalData();
13
+ });
14
+ }
15
+ getConfig(key) {
16
+ let keys = this.normalizeKey(key);
17
+ // this._core.debug.log(`getConfig keys = ${JSON.stringify(keys)}`);
18
+ if (keys == null)
19
+ return;
20
+ try {
21
+ let res = this._core.storage.getSaveableData(this._core.storage.globalData, false, "config", ...keys);
22
+ // this._core.debug.log(`getConfig res = ${JSON.stringify(res)}`);
23
+ return res;
24
+ }
25
+ catch (e) {
26
+ // this._core.debug.log(`getConfig error`,e);
27
+ return;
28
+ }
29
+ }
30
+ setConfig(key, value) {
31
+ let keys = this.normalizeKey(key);
32
+ if (keys == null)
33
+ return;
34
+ this._core.storage.setSaveableData(this._core.storage.globalData, true, value, "config", ...keys);
35
+ this._core.storage.saveGlobalData();
36
+ }
37
+ normalizeKey(key) {
38
+ let keys = [];
39
+ key.split(".").forEach((key) => {
40
+ if (key.trim().length > 0)
41
+ keys.push(key);
42
+ else
43
+ return null;
44
+ });
45
+ return keys;
46
+ }
47
+ resetConfig() { }
48
+ }
49
+ const defaultConfig = {
50
+ game: {
51
+ autoplay: {
52
+ enable: false,
53
+ ms_per_char: 150,
54
+ extra_delay: 1300,
55
+ },
56
+ },
57
+ };