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/dist/audio/index.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
get _channels() {
|
|
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
|
-
this.
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
this._audioPlayer
|
|
114
|
-
this.
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
this.
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
this._audioPlayer.stop();
|
|
143
|
-
this.
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
this.
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
this.
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
this._nowIndex =
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
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 = {}));
|
package/dist/config/index.js
CHANGED
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
export class Config {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
_core
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
if (!
|
|
10
|
-
_core.storage.setSaveableData(_core.storage.globalData, true,
|
|
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
|
+
};
|