sonolus-next-rush-engine 0.1.0

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.
@@ -0,0 +1,360 @@
1
+ /**
2
+ * Simple cursor-based binary writer.
3
+ * @module
4
+ */
5
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
6
+ if (kind === "m") throw new TypeError("Private method is not writable");
7
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
8
+ 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");
9
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
10
+ };
11
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
12
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
13
+ 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");
14
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
15
+ };
16
+ var _BinaryWriter_data, _BinaryWriter_view, _BinaryWriter_maxCursor, _BinaryWriter_cursor;
17
+ /**
18
+ * Simple cursor-based binary writer.
19
+ *
20
+ * On initialization, the writer creates a buffer with a default size of 256 bytes.
21
+ * The buffer will grow automatically as needed, but you can use {@link ensureSize} to reduce the number of resizing.
22
+ */
23
+ export class BinaryWriter {
24
+ /**
25
+ * Create a new BinaryWriter instance.
26
+ * @param initialSize - The initial size of the buffer. The buffer will grow automatically as needed, but this parameter can help reduce the number of resizing.
27
+ * @returns A new BinaryWriter instance.
28
+ */
29
+ constructor(initialSize = 256) {
30
+ _BinaryWriter_data.set(this, void 0);
31
+ _BinaryWriter_view.set(this, void 0);
32
+ _BinaryWriter_maxCursor.set(this, void 0);
33
+ _BinaryWriter_cursor.set(this, void 0);
34
+ __classPrivateFieldSet(this, _BinaryWriter_data, new Uint8Array(initialSize), "f");
35
+ __classPrivateFieldSet(this, _BinaryWriter_view, new DataView(__classPrivateFieldGet(this, _BinaryWriter_data, "f").buffer), "f");
36
+ __classPrivateFieldSet(this, _BinaryWriter_cursor, 0, "f");
37
+ __classPrivateFieldSet(this, _BinaryWriter_maxCursor, 0, "f");
38
+ }
39
+ /**
40
+ * Returns the current cursor position.
41
+ */
42
+ get cursor() {
43
+ return __classPrivateFieldGet(this, _BinaryWriter_cursor, "f");
44
+ }
45
+ /**
46
+ * Seek to a specific offset in the buffer.
47
+ */
48
+ seek(offset) {
49
+ this.preWrite(offset - __classPrivateFieldGet(this, _BinaryWriter_cursor, "f"));
50
+ __classPrivateFieldSet(this, _BinaryWriter_cursor, offset, "f");
51
+ this.postWrite(0);
52
+ }
53
+ /**
54
+ * Write a single byte to the buffer.
55
+ * @param value - The byte to write.
56
+ */
57
+ writeUInt8(value) {
58
+ this.preWrite(1);
59
+ __classPrivateFieldGet(this, _BinaryWriter_view, "f").setUint8(__classPrivateFieldGet(this, _BinaryWriter_cursor, "f"), value);
60
+ this.postWrite(1);
61
+ }
62
+ /**
63
+ * Write a single signed byte to the buffer.
64
+ * @param value - The byte to write.
65
+ */
66
+ writeInt8(value) {
67
+ this.preWrite(1);
68
+ __classPrivateFieldGet(this, _BinaryWriter_data, "f")[__classPrivateFieldGet(this, _BinaryWriter_cursor, "f")] = value;
69
+ this.postWrite(1);
70
+ }
71
+ /**
72
+ * Write a number to the buffer.
73
+ *
74
+ * > [!NOTE]
75
+ * > In most cases, you should use the `write[Type][Endian]` method instead.
76
+ *
77
+ * @param value - The number to write.
78
+ * @param kind - The type of number to write.
79
+ * @param endian - The endianness to write the number in.
80
+ */
81
+ write(value, kind, endian = 'le') {
82
+ switch (kind) {
83
+ case 'u8':
84
+ this.writeUInt8(value);
85
+ break;
86
+ case 'i8':
87
+ this.writeInt8(value);
88
+ break;
89
+ case 'u32':
90
+ endian === 'le' ? this.writeUInt32LE(value) : this.writeUInt32BE(value);
91
+ break;
92
+ case 'u16':
93
+ endian === 'le' ? this.writeUInt16LE(value) : this.writeUInt16BE(value);
94
+ break;
95
+ case 'i32':
96
+ endian === 'le' ? this.writeInt32LE(value) : this.writeInt32BE(value);
97
+ break;
98
+ case 'i16':
99
+ endian === 'le' ? this.writeInt16LE(value) : this.writeInt16BE(value);
100
+ break;
101
+ case 'f32':
102
+ endian === 'le' ? this.writeFloat32LE(value) : this.writeFloat32BE(value);
103
+ break;
104
+ case 'f64':
105
+ endian === 'le' ? this.writeFloat64LE(value) : this.writeFloat64BE(value);
106
+ break;
107
+ default:
108
+ kind;
109
+ throw new Error(`Unknown kind: ${kind}`);
110
+ }
111
+ }
112
+ /**
113
+ * Write a 32-bit unsigned integer to the buffer in little-endian format.
114
+ * @param value - The number to write.
115
+ */
116
+ writeUInt32LE(value) {
117
+ this.preWrite(4);
118
+ __classPrivateFieldGet(this, _BinaryWriter_view, "f").setUint32(__classPrivateFieldGet(this, _BinaryWriter_cursor, "f"), value, true);
119
+ this.postWrite(4);
120
+ }
121
+ /**
122
+ * Write a 32-bit unsigned integer to the buffer in big-endian format.
123
+ * @param value - The number to write.
124
+ */
125
+ writeUInt32BE(value) {
126
+ this.preWrite(4);
127
+ __classPrivateFieldGet(this, _BinaryWriter_view, "f").setUint32(__classPrivateFieldGet(this, _BinaryWriter_cursor, "f"), value, false);
128
+ this.postWrite(4);
129
+ }
130
+ /**
131
+ * Write a 16-bit unsigned integer to the buffer in little-endian format.
132
+ * @param value - The number to write.
133
+ */
134
+ writeUInt16LE(value) {
135
+ this.preWrite(2);
136
+ __classPrivateFieldGet(this, _BinaryWriter_view, "f").setUint16(__classPrivateFieldGet(this, _BinaryWriter_cursor, "f"), value, true);
137
+ this.postWrite(2);
138
+ }
139
+ /**
140
+ * Write a 16-bit unsigned integer to the buffer in big-endian format.
141
+ * @param value - The number to write.
142
+ */
143
+ writeUInt16BE(value) {
144
+ this.preWrite(2);
145
+ __classPrivateFieldGet(this, _BinaryWriter_view, "f").setUint16(__classPrivateFieldGet(this, _BinaryWriter_cursor, "f"), value, false);
146
+ this.postWrite(2);
147
+ }
148
+ /**
149
+ * Write a signed 32-bit integer to the buffer in little-endian format.
150
+ * @param value - The number to write.
151
+ */
152
+ writeInt32LE(value) {
153
+ this.preWrite(4);
154
+ __classPrivateFieldGet(this, _BinaryWriter_view, "f").setInt32(__classPrivateFieldGet(this, _BinaryWriter_cursor, "f"), value, true);
155
+ this.postWrite(4);
156
+ }
157
+ /**
158
+ * Write a signed 32-bit integer to the buffer in big-endian format.
159
+ * @param value - The number to write.
160
+ */
161
+ writeInt32BE(value) {
162
+ this.preWrite(4);
163
+ __classPrivateFieldGet(this, _BinaryWriter_view, "f").setInt32(__classPrivateFieldGet(this, _BinaryWriter_cursor, "f"), value, false);
164
+ this.postWrite(4);
165
+ }
166
+ /**
167
+ * Write a signed 16-bit integer to the buffer in little-endian format.
168
+ * @param value - The number to write.
169
+ */
170
+ writeInt16LE(value) {
171
+ this.preWrite(2);
172
+ __classPrivateFieldGet(this, _BinaryWriter_view, "f").setInt16(__classPrivateFieldGet(this, _BinaryWriter_cursor, "f"), value, true);
173
+ this.postWrite(2);
174
+ }
175
+ /**
176
+ * Write a signed 16-bit integer to the buffer in big-endian format.
177
+ * @param value - The number to write.
178
+ */
179
+ writeInt16BE(value) {
180
+ this.preWrite(2);
181
+ __classPrivateFieldGet(this, _BinaryWriter_view, "f").setInt16(__classPrivateFieldGet(this, _BinaryWriter_cursor, "f"), value, false);
182
+ this.postWrite(2);
183
+ }
184
+ /**
185
+ * Write a 64-bit unsigned integer to the buffer in little-endian format.
186
+ * @param value - The number to write.
187
+ */
188
+ writeUInt64LE(value) {
189
+ this.preWrite(8);
190
+ __classPrivateFieldGet(this, _BinaryWriter_view, "f").setBigUint64(__classPrivateFieldGet(this, _BinaryWriter_cursor, "f"), value, true);
191
+ this.postWrite(8);
192
+ }
193
+ /**
194
+ * Write a 64-bit unsigned integer to the buffer in big-endian format.
195
+ * @param value - The number to write.
196
+ */
197
+ writeUInt64BE(value) {
198
+ this.preWrite(8);
199
+ __classPrivateFieldGet(this, _BinaryWriter_view, "f").setBigUint64(__classPrivateFieldGet(this, _BinaryWriter_cursor, "f"), value, false);
200
+ this.postWrite(8);
201
+ }
202
+ /**
203
+ * Write a 64-bit signed integer to the buffer in little-endian format.
204
+ * @param value - The number to write.
205
+ */
206
+ writeInt64LE(value) {
207
+ this.preWrite(8);
208
+ __classPrivateFieldGet(this, _BinaryWriter_view, "f").setBigInt64(__classPrivateFieldGet(this, _BinaryWriter_cursor, "f"), value, true);
209
+ this.postWrite(8);
210
+ }
211
+ /**
212
+ * Write a 64-bit signed integer to the buffer in big-endian format.
213
+ * @param value - The number to write.
214
+ */
215
+ writeInt64BE(value) {
216
+ this.preWrite(8);
217
+ __classPrivateFieldGet(this, _BinaryWriter_view, "f").setBigInt64(__classPrivateFieldGet(this, _BinaryWriter_cursor, "f"), value, false);
218
+ this.postWrite(8);
219
+ }
220
+ /**
221
+ * Write a 32-bit floating point number (f32, float) to the buffer in little-endian format.
222
+ * @param value - The number to write.
223
+ */
224
+ writeFloat32LE(value) {
225
+ this.preWrite(4);
226
+ __classPrivateFieldGet(this, _BinaryWriter_view, "f").setFloat32(__classPrivateFieldGet(this, _BinaryWriter_cursor, "f"), value, true);
227
+ this.postWrite(4);
228
+ }
229
+ /**
230
+ * Write a 64-bit floating point number (f64, double) to the buffer in little-endian format.
231
+ * @param value - The number to write.
232
+ */
233
+ writeFloat64LE(value) {
234
+ this.preWrite(8);
235
+ __classPrivateFieldGet(this, _BinaryWriter_view, "f").setFloat64(__classPrivateFieldGet(this, _BinaryWriter_cursor, "f"), value, true);
236
+ this.postWrite(8);
237
+ }
238
+ /**
239
+ * Write a 32-bit floating point number (f32, float) to the buffer in big-endian format.
240
+ * @param value - The number to write.
241
+ */
242
+ writeFloat32BE(value) {
243
+ this.preWrite(4);
244
+ __classPrivateFieldGet(this, _BinaryWriter_view, "f").setFloat32(__classPrivateFieldGet(this, _BinaryWriter_cursor, "f"), value, false);
245
+ this.postWrite(4);
246
+ }
247
+ /**
248
+ * Write a 64-bit floating point number (f64, double) to the buffer in big-endian format.
249
+ * @param value - The number to write.
250
+ */
251
+ writeFloat64BE(value) {
252
+ this.preWrite(8);
253
+ __classPrivateFieldGet(this, _BinaryWriter_view, "f").setFloat64(__classPrivateFieldGet(this, _BinaryWriter_cursor, "f"), value, false);
254
+ this.postWrite(8);
255
+ }
256
+ /** Alias for `writeFloat32LE` */
257
+ writeFloat32(value) {
258
+ this.writeFloat32LE(value);
259
+ }
260
+ /** Alias for `writeFloat64LE` */
261
+ writeFloat64(value) {
262
+ this.writeFloat64LE(value);
263
+ }
264
+ /**
265
+ * Write a null-terminated string to the buffer.
266
+ *
267
+ * @param value - The string to write.
268
+ */
269
+ writeString(value) {
270
+ const encoder = new TextEncoder();
271
+ const bytes = encoder.encode(value);
272
+ this.preWrite(bytes.length + 1);
273
+ for (let i = 0; i < bytes.length; i++) {
274
+ __classPrivateFieldGet(this, _BinaryWriter_data, "f")[__classPrivateFieldGet(this, _BinaryWriter_cursor, "f") + i] = bytes[i];
275
+ }
276
+ __classPrivateFieldGet(this, _BinaryWriter_data, "f")[__classPrivateFieldGet(this, _BinaryWriter_cursor, "f") + bytes.length] = 0;
277
+ this.postWrite(bytes.length + 1);
278
+ }
279
+ /**
280
+ * Write a buffer to the buffer.
281
+ *
282
+ * @param value - The buffer to write.
283
+ */
284
+ writeBytes(value) {
285
+ this.preWrite(value.length);
286
+ __classPrivateFieldGet(this, _BinaryWriter_data, "f").set(value, __classPrivateFieldGet(this, _BinaryWriter_cursor, "f"));
287
+ this.postWrite(value.length);
288
+ }
289
+ /**
290
+ * Write a string to the buffer, without null-terminating it.
291
+ *
292
+ * @param value - The string to write.
293
+ */
294
+ writeChars(value) {
295
+ const encoder = new TextEncoder();
296
+ const bytes = encoder.encode(value);
297
+ this.preWrite(bytes.length);
298
+ for (let i = 0; i < bytes.length; i++) {
299
+ __classPrivateFieldGet(this, _BinaryWriter_data, "f")[__classPrivateFieldGet(this, _BinaryWriter_cursor, "f") + i] = bytes[i];
300
+ }
301
+ this.postWrite(bytes.length);
302
+ }
303
+ /**
304
+ * Save the buffer as a Uint8Array.
305
+ * @returns The buffer as a Uint8Array.
306
+ */
307
+ toUint8Array() {
308
+ return Uint8Array.from(__classPrivateFieldGet(this, _BinaryWriter_data, "f").slice(0, __classPrivateFieldGet(this, _BinaryWriter_maxCursor, "f")));
309
+ }
310
+ /**
311
+ * Increase the buffer size to the specified size if the buffer is too small.
312
+ * @param size - The size to increase the buffer to.
313
+ * @returns The new buffer size.
314
+ */
315
+ ensureSize(size) {
316
+ if (__classPrivateFieldGet(this, _BinaryWriter_data, "f").byteLength < size) {
317
+ this.extendBuffer(size);
318
+ }
319
+ return __classPrivateFieldGet(this, _BinaryWriter_data, "f").byteLength;
320
+ }
321
+ /** Get the current length of the buffer. */
322
+ get length() {
323
+ return __classPrivateFieldGet(this, _BinaryWriter_maxCursor, "f");
324
+ }
325
+ /** Get the current capacity of the buffer. */
326
+ get capacity() {
327
+ return __classPrivateFieldGet(this, _BinaryWriter_data, "f").byteLength;
328
+ }
329
+ /** Allocate more space in the buffer, if needed. */
330
+ preWrite(size) {
331
+ if (__classPrivateFieldGet(this, _BinaryWriter_cursor, "f") + size > __classPrivateFieldGet(this, _BinaryWriter_data, "f").byteLength) {
332
+ let newSize;
333
+ if (__classPrivateFieldGet(this, _BinaryWriter_data, "f").byteLength >= 2048) {
334
+ newSize = __classPrivateFieldGet(this, _BinaryWriter_data, "f").byteLength + 2048;
335
+ }
336
+ else {
337
+ newSize = __classPrivateFieldGet(this, _BinaryWriter_data, "f").byteLength * 2;
338
+ }
339
+ if (__classPrivateFieldGet(this, _BinaryWriter_cursor, "f") + size > newSize) {
340
+ newSize = __classPrivateFieldGet(this, _BinaryWriter_cursor, "f") + size;
341
+ }
342
+ this.extendBuffer(newSize);
343
+ }
344
+ }
345
+ /** Allocate more space in the buffer. */
346
+ extendBuffer(length) {
347
+ const newData = new Uint8Array(length);
348
+ newData.set(__classPrivateFieldGet(this, _BinaryWriter_data, "f"));
349
+ __classPrivateFieldSet(this, _BinaryWriter_data, newData, "f");
350
+ __classPrivateFieldSet(this, _BinaryWriter_view, new DataView(newData.buffer), "f");
351
+ }
352
+ /** Update the cursor after writing to the buffer. */
353
+ postWrite(size) {
354
+ __classPrivateFieldSet(this, _BinaryWriter_cursor, __classPrivateFieldGet(this, _BinaryWriter_cursor, "f") + size, "f");
355
+ if (__classPrivateFieldGet(this, _BinaryWriter_cursor, "f") > __classPrivateFieldGet(this, _BinaryWriter_maxCursor, "f")) {
356
+ __classPrivateFieldSet(this, _BinaryWriter_maxCursor, __classPrivateFieldGet(this, _BinaryWriter_cursor, "f"), "f");
357
+ }
358
+ }
359
+ }
360
+ _BinaryWriter_data = new WeakMap(), _BinaryWriter_view = new WeakMap(), _BinaryWriter_maxCursor = new WeakMap(), _BinaryWriter_cursor = new WeakMap();
@@ -0,0 +1,109 @@
1
+ declare const FlickType: readonly ["none", "up", "left", "right", "down", "down_left", "down_right"];
2
+ type FlickType = (typeof FlickType)[number];
3
+ declare const StepType: readonly ["visible", "hidden", "ignored"];
4
+ type StepType = (typeof StepType)[number];
5
+ declare const EaseType: readonly ["linear", "easeIn", "easeOut", "easeInOut", "easeOutIn"];
6
+ export type EaseType = (typeof EaseType)[number];
7
+ export interface Score {
8
+ metadata: {
9
+ title: string;
10
+ author: string;
11
+ artist: string;
12
+ musicFile: string;
13
+ musicOffset: number;
14
+ jacketFile: string;
15
+ };
16
+ events: {
17
+ timeSignatures: {
18
+ measure: number;
19
+ numerator: number;
20
+ denominator: number;
21
+ }[];
22
+ bpmChanges: {
23
+ tick: number;
24
+ bpm: number;
25
+ }[];
26
+ hispeedChanges: {
27
+ tick: number;
28
+ speed: number;
29
+ layer: number;
30
+ skip?: number;
31
+ ease?: number;
32
+ hideNotes?: boolean;
33
+ }[];
34
+ skills: number[];
35
+ fever: {
36
+ start: number;
37
+ end: number;
38
+ };
39
+ };
40
+ taps: {
41
+ tick: number;
42
+ lane: number;
43
+ width: number;
44
+ flickType: FlickType;
45
+ flags: {
46
+ critical: boolean;
47
+ friction: boolean;
48
+ dummy?: boolean;
49
+ };
50
+ layer: number;
51
+ }[];
52
+ holds: {
53
+ flags: {
54
+ startHidden: boolean;
55
+ endHidden: boolean;
56
+ guide: boolean;
57
+ dummy?: boolean;
58
+ };
59
+ start: {
60
+ tick: number;
61
+ lane: number;
62
+ width: number;
63
+ flags: {
64
+ critical: boolean;
65
+ friction: boolean;
66
+ };
67
+ layer: number;
68
+ ease: EaseType;
69
+ };
70
+ fadeType: number;
71
+ guideColor: number;
72
+ steps: {
73
+ tick: number;
74
+ lane: number;
75
+ width: number;
76
+ type: StepType;
77
+ ease: EaseType;
78
+ layer: number;
79
+ }[];
80
+ end: {
81
+ tick: number;
82
+ lane: number;
83
+ width: number;
84
+ flickType: FlickType;
85
+ flags: {
86
+ critical: boolean;
87
+ friction: boolean;
88
+ };
89
+ layer: number;
90
+ };
91
+ }[];
92
+ damages: {
93
+ tick: number;
94
+ lane: number;
95
+ width: number;
96
+ flickType: FlickType;
97
+ flags: {
98
+ critical: boolean;
99
+ friction: boolean;
100
+ dummy?: boolean;
101
+ };
102
+ layer: number;
103
+ }[];
104
+ numLayers: number;
105
+ }
106
+ /** Detect MMWS Type */
107
+ export declare const detectMMWSType: (mmws: Uint8Array) => string;
108
+ export declare const analyze: (mmws: Uint8Array) => Score;
109
+ export {};