klaudio 0.11.2 → 0.11.4
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/README.md +96 -96
- package/bin/cli.js +44 -44
- package/package.json +40 -44
- package/src/cache.js +306 -306
- package/src/cli.js +1846 -1821
- package/src/extractor.js +213 -213
- package/src/installer.js +369 -368
- package/src/notify.js +138 -135
- package/src/player.js +488 -488
- package/src/presets.js +87 -87
- package/src/scanner.js +445 -445
- package/src/scumm.js +560 -560
- package/src/tts.js +398 -391
package/src/cli.js
CHANGED
|
@@ -1,1821 +1,1846 @@
|
|
|
1
|
-
import React, { useState, useEffect, useCallback, useRef, useMemo } from "react";
|
|
2
|
-
import { render, Box, Text, useInput, useApp } from "ink";
|
|
3
|
-
import Spinner from "ink-spinner";
|
|
4
|
-
import { PRESETS, EVENTS } from "./presets.js";
|
|
5
|
-
import { KOKORO_PRESET_VOICES, KOKORO_VOICES, KOKORO_DEFAULT_VOICE, isKokoroAvailable } from "./tts.js";
|
|
6
|
-
import { playSoundWithCancel, getWavDuration } from "./player.js";
|
|
7
|
-
import { getAvailableGames, getSystemSounds } from "./scanner.js";
|
|
8
|
-
import { install, uninstall, getExistingSounds, checkHooksOutdated } from "./installer.js";
|
|
9
|
-
import { getVgmstreamPath, findPackedAudioFiles, extractToWav } from "./extractor.js";
|
|
10
|
-
import { extractUnityResource } from "./unity.js";
|
|
11
|
-
import { extractBunFile, isBunFile } from "./scumm.js";
|
|
12
|
-
import { getCachedExtraction, cacheExtraction, categorizeLooseFiles, getCategories, sortFilesByPriority, listCachedGames } from "./cache.js";
|
|
13
|
-
import { basename, dirname } from "node:path";
|
|
14
|
-
import { tmpdir } from "node:os";
|
|
15
|
-
import { join } from "node:path";
|
|
16
|
-
|
|
17
|
-
const MAX_PLAY_SECONDS = 10;
|
|
18
|
-
const ACCENT = "#76C41E"; // Needle green-yellow midpoint
|
|
19
|
-
|
|
20
|
-
/** Truncate a filename: keep first 10 chars + ext (max 4 chars) */
|
|
21
|
-
function shortName(filePath) {
|
|
22
|
-
const name = basename(filePath);
|
|
23
|
-
const dot = name.lastIndexOf(".");
|
|
24
|
-
if (dot <= 0 || name.length <= 18) return name;
|
|
25
|
-
const stem = name.slice(0, dot);
|
|
26
|
-
const ext = name.slice(dot);
|
|
27
|
-
if (stem.length <= 10) return name;
|
|
28
|
-
return stem.slice(0, 10) + "..." + ext;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const h = React.createElement;
|
|
32
|
-
|
|
33
|
-
// ── Custom SelectInput components (bright colors for CMD) ────
|
|
34
|
-
const Indicator = ({ isSelected }) =>
|
|
35
|
-
h(Box, { marginRight: 1 }, isSelected
|
|
36
|
-
? h(Text, { color: ACCENT }, "❯")
|
|
37
|
-
: h(Text, null, " "));
|
|
38
|
-
|
|
39
|
-
const Item = ({ isSelected, label }) =>
|
|
40
|
-
h(Text, { color: isSelected ? ACCENT : undefined, bold: isSelected }, label);
|
|
41
|
-
|
|
42
|
-
// ── Non-wrapping SelectInput (clamps at boundaries) ─────────────
|
|
43
|
-
const SelectInput = ({ items = [], isFocused = true, initialIndex = 0, indicatorComponent = Indicator, itemComponent = Item, limit: customLimit, onSelect, onHighlight }) => {
|
|
44
|
-
const hasLimit = typeof customLimit === "number" && items.length > customLimit;
|
|
45
|
-
const limit = hasLimit ? Math.min(customLimit, items.length) : items.length;
|
|
46
|
-
const [scrollOffset, setScrollOffset] = useState(0);
|
|
47
|
-
const [selectedIndex, setSelectedIndex] = useState(initialIndex ? Math.min(initialIndex, items.length - 1) : 0);
|
|
48
|
-
const previousItems = useRef(items);
|
|
49
|
-
|
|
50
|
-
useEffect(() => {
|
|
51
|
-
const prevValues = previousItems.current.map((i) => i.value);
|
|
52
|
-
const curValues = items.map((i) => i.value);
|
|
53
|
-
if (prevValues.length !== curValues.length || prevValues.some((v, i) => v !== curValues[i])) {
|
|
54
|
-
// Try to keep the currently selected item highlighted
|
|
55
|
-
const prevSelected = previousItems.current[selectedIndex];
|
|
56
|
-
const newIdx = prevSelected ? items.findIndex((i) => i.value === prevSelected.value) : -1;
|
|
57
|
-
if (newIdx >= 0) {
|
|
58
|
-
setSelectedIndex(newIdx);
|
|
59
|
-
setScrollOffset(hasLimit ? Math.max(0, Math.min(newIdx, items.length - limit)) : 0);
|
|
60
|
-
} else {
|
|
61
|
-
// Selected item gone — reset to top
|
|
62
|
-
setScrollOffset(0);
|
|
63
|
-
setSelectedIndex(0);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
previousItems.current = items;
|
|
67
|
-
}, [items]);
|
|
68
|
-
|
|
69
|
-
useInput(useCallback((input, key) => {
|
|
70
|
-
if (input === "k" || key.upArrow) {
|
|
71
|
-
if (selectedIndex <= 0) return; // clamp — don't wrap
|
|
72
|
-
const next = selectedIndex - 1;
|
|
73
|
-
let newOffset = scrollOffset;
|
|
74
|
-
if (hasLimit && next < scrollOffset) newOffset = next;
|
|
75
|
-
setSelectedIndex(next);
|
|
76
|
-
setScrollOffset(newOffset);
|
|
77
|
-
if (typeof onHighlight === "function") onHighlight(items[next]);
|
|
78
|
-
}
|
|
79
|
-
if (input === "j" || key.downArrow) {
|
|
80
|
-
if (selectedIndex >= items.length - 1) return; // clamp — don't wrap
|
|
81
|
-
const next = selectedIndex + 1;
|
|
82
|
-
let newOffset = scrollOffset;
|
|
83
|
-
if (hasLimit && next >= scrollOffset + limit) newOffset = next - limit + 1;
|
|
84
|
-
setSelectedIndex(next);
|
|
85
|
-
setScrollOffset(newOffset);
|
|
86
|
-
if (typeof onHighlight === "function") onHighlight(items[next]);
|
|
87
|
-
}
|
|
88
|
-
if (key.return) {
|
|
89
|
-
if (typeof onSelect === "function") onSelect(items[selectedIndex]);
|
|
90
|
-
}
|
|
91
|
-
}, [hasLimit, limit, scrollOffset, selectedIndex, items, onSelect, onHighlight]), { isActive: isFocused });
|
|
92
|
-
|
|
93
|
-
const visible = hasLimit ? items.slice(scrollOffset, scrollOffset + limit) : items;
|
|
94
|
-
return h(Box, { flexDirection: "column" }, visible.map((item, index) => {
|
|
95
|
-
const isSelected = index + scrollOffset === selectedIndex;
|
|
96
|
-
return h(Box, { key: item.key ?? item.value },
|
|
97
|
-
h(indicatorComponent, { isSelected }),
|
|
98
|
-
h(itemComponent, { ...item, isSelected }));
|
|
99
|
-
}));
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
// ── Screens ─────────────────────────────────────────────────────
|
|
103
|
-
const SCREEN = {
|
|
104
|
-
SCOPE: 0,
|
|
105
|
-
PRESET: 1,
|
|
106
|
-
PREVIEW: 2,
|
|
107
|
-
SCANNING: 3,
|
|
108
|
-
GAME_PICK: 4,
|
|
109
|
-
GAME_SOUNDS: 5,
|
|
110
|
-
EXTRACTING: 6,
|
|
111
|
-
CONFIRM: 7,
|
|
112
|
-
INSTALLING: 8,
|
|
113
|
-
DONE: 9,
|
|
114
|
-
MUSIC_MODE: 10,
|
|
115
|
-
MUSIC_GAME_PICK: 11,
|
|
116
|
-
MUSIC_PLAYING: 12,
|
|
117
|
-
MUSIC_EXTRACTING: 13,
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
const isUninstallMode = process.argv.includes("--uninstall") || process.argv.includes("--remove");
|
|
121
|
-
|
|
122
|
-
// ── Header component ────────────────────────────────────────────
|
|
123
|
-
const Header = () =>
|
|
124
|
-
h(Box, { flexDirection: "column", marginBottom: 1 },
|
|
125
|
-
h(Text, { bold: true, color: ACCENT }, " klaudio"),
|
|
126
|
-
h(Text, { dimColor: true }, isUninstallMode
|
|
127
|
-
? " Remove sound effects from Claude Code"
|
|
128
|
-
: " Add sound effects to your Claude Code sessions"),
|
|
129
|
-
);
|
|
130
|
-
|
|
131
|
-
const NavHint = ({ back = true, extra = "" }) =>
|
|
132
|
-
h(Box, { marginTop: 1 },
|
|
133
|
-
h(Text, { dimColor: true },
|
|
134
|
-
(back ? " esc back" : "") +
|
|
135
|
-
(extra ? (back ? " • " : " ") + extra : "")
|
|
136
|
-
),
|
|
137
|
-
);
|
|
138
|
-
|
|
139
|
-
// ── Screen: Scope ───────────────────────────────────────────────
|
|
140
|
-
const ScopeScreen = ({ onNext, onMusic, onUpdate, tts, onToggleTts, outdatedReasons }) => {
|
|
141
|
-
const isOutdated = outdatedReasons && outdatedReasons.length > 0;
|
|
142
|
-
const items = [
|
|
143
|
-
...(isOutdated ? [{ label: "⬆ Apply updates", value: "_update" }] : []),
|
|
144
|
-
{ label: "Global — Claude Code + Copilot (all projects)", value: "global" },
|
|
145
|
-
{ label: "This project — Claude Code + Copilot (this project only)", value: "project" },
|
|
146
|
-
{ label: "🎵 Play game music while you code", value: "_music" },
|
|
147
|
-
];
|
|
148
|
-
const [sel, setSel] = useState(0);
|
|
149
|
-
const
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
setSel((i) => Math.
|
|
156
|
-
} else if (input === "
|
|
157
|
-
|
|
158
|
-
} else if (
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
h(
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
),
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
const
|
|
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
|
-
h(
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
),
|
|
383
|
-
h(
|
|
384
|
-
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
h(
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
h(
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
?
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
const
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
const
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
//
|
|
570
|
-
const
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
if (
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
}
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
}
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
}
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
:
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
h(
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
),
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
const
|
|
888
|
-
?
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
);
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
)
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
}
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
const
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
if (
|
|
1111
|
-
|
|
1112
|
-
}
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
if (
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
)
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
h(
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
}
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
const
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
});
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
}
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
}
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
}
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
}, []);
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
)
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
)
|
|
1539
|
-
|
|
1540
|
-
}
|
|
1541
|
-
|
|
1542
|
-
if (phase === "
|
|
1543
|
-
return h(Box, { flexDirection: "column" },
|
|
1544
|
-
h(Header, null),
|
|
1545
|
-
h(
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
const
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
const
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
}
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
},
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
},
|
|
1802
|
-
onBack: () => setScreen(SCREEN.
|
|
1803
|
-
});
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
return h(
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
}
|
|
1
|
+
import React, { useState, useEffect, useCallback, useRef, useMemo } from "react";
|
|
2
|
+
import { render, Box, Text, useInput, useApp } from "ink";
|
|
3
|
+
import Spinner from "ink-spinner";
|
|
4
|
+
import { PRESETS, EVENTS } from "./presets.js";
|
|
5
|
+
import { KOKORO_PRESET_VOICES, KOKORO_VOICES, KOKORO_DEFAULT_VOICE, isKokoroAvailable } from "./tts.js";
|
|
6
|
+
import { playSoundWithCancel, getWavDuration } from "./player.js";
|
|
7
|
+
import { getAvailableGames, getSystemSounds } from "./scanner.js";
|
|
8
|
+
import { install, uninstall, getExistingSounds, checkHooksOutdated } from "./installer.js";
|
|
9
|
+
import { getVgmstreamPath, findPackedAudioFiles, extractToWav } from "./extractor.js";
|
|
10
|
+
import { extractUnityResource } from "./unity.js";
|
|
11
|
+
import { extractBunFile, isBunFile } from "./scumm.js";
|
|
12
|
+
import { getCachedExtraction, cacheExtraction, categorizeLooseFiles, getCategories, sortFilesByPriority, listCachedGames } from "./cache.js";
|
|
13
|
+
import { basename, dirname } from "node:path";
|
|
14
|
+
import { tmpdir } from "node:os";
|
|
15
|
+
import { join } from "node:path";
|
|
16
|
+
|
|
17
|
+
const MAX_PLAY_SECONDS = 10;
|
|
18
|
+
const ACCENT = "#76C41E"; // Needle green-yellow midpoint
|
|
19
|
+
|
|
20
|
+
/** Truncate a filename: keep first 10 chars + ext (max 4 chars) */
|
|
21
|
+
function shortName(filePath) {
|
|
22
|
+
const name = basename(filePath);
|
|
23
|
+
const dot = name.lastIndexOf(".");
|
|
24
|
+
if (dot <= 0 || name.length <= 18) return name;
|
|
25
|
+
const stem = name.slice(0, dot);
|
|
26
|
+
const ext = name.slice(dot);
|
|
27
|
+
if (stem.length <= 10) return name;
|
|
28
|
+
return stem.slice(0, 10) + "..." + ext;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const h = React.createElement;
|
|
32
|
+
|
|
33
|
+
// ── Custom SelectInput components (bright colors for CMD) ────
|
|
34
|
+
const Indicator = ({ isSelected }) =>
|
|
35
|
+
h(Box, { marginRight: 1 }, isSelected
|
|
36
|
+
? h(Text, { color: ACCENT }, "❯")
|
|
37
|
+
: h(Text, null, " "));
|
|
38
|
+
|
|
39
|
+
const Item = ({ isSelected, label }) =>
|
|
40
|
+
h(Text, { color: isSelected ? ACCENT : undefined, bold: isSelected }, label);
|
|
41
|
+
|
|
42
|
+
// ── Non-wrapping SelectInput (clamps at boundaries) ─────────────
|
|
43
|
+
const SelectInput = ({ items = [], isFocused = true, initialIndex = 0, indicatorComponent = Indicator, itemComponent = Item, limit: customLimit, onSelect, onHighlight }) => {
|
|
44
|
+
const hasLimit = typeof customLimit === "number" && items.length > customLimit;
|
|
45
|
+
const limit = hasLimit ? Math.min(customLimit, items.length) : items.length;
|
|
46
|
+
const [scrollOffset, setScrollOffset] = useState(0);
|
|
47
|
+
const [selectedIndex, setSelectedIndex] = useState(initialIndex ? Math.min(initialIndex, items.length - 1) : 0);
|
|
48
|
+
const previousItems = useRef(items);
|
|
49
|
+
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
const prevValues = previousItems.current.map((i) => i.value);
|
|
52
|
+
const curValues = items.map((i) => i.value);
|
|
53
|
+
if (prevValues.length !== curValues.length || prevValues.some((v, i) => v !== curValues[i])) {
|
|
54
|
+
// Try to keep the currently selected item highlighted
|
|
55
|
+
const prevSelected = previousItems.current[selectedIndex];
|
|
56
|
+
const newIdx = prevSelected ? items.findIndex((i) => i.value === prevSelected.value) : -1;
|
|
57
|
+
if (newIdx >= 0) {
|
|
58
|
+
setSelectedIndex(newIdx);
|
|
59
|
+
setScrollOffset(hasLimit ? Math.max(0, Math.min(newIdx, items.length - limit)) : 0);
|
|
60
|
+
} else {
|
|
61
|
+
// Selected item gone — reset to top
|
|
62
|
+
setScrollOffset(0);
|
|
63
|
+
setSelectedIndex(0);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
previousItems.current = items;
|
|
67
|
+
}, [items]);
|
|
68
|
+
|
|
69
|
+
useInput(useCallback((input, key) => {
|
|
70
|
+
if (input === "k" || key.upArrow) {
|
|
71
|
+
if (selectedIndex <= 0) return; // clamp — don't wrap
|
|
72
|
+
const next = selectedIndex - 1;
|
|
73
|
+
let newOffset = scrollOffset;
|
|
74
|
+
if (hasLimit && next < scrollOffset) newOffset = next;
|
|
75
|
+
setSelectedIndex(next);
|
|
76
|
+
setScrollOffset(newOffset);
|
|
77
|
+
if (typeof onHighlight === "function") onHighlight(items[next]);
|
|
78
|
+
}
|
|
79
|
+
if (input === "j" || key.downArrow) {
|
|
80
|
+
if (selectedIndex >= items.length - 1) return; // clamp — don't wrap
|
|
81
|
+
const next = selectedIndex + 1;
|
|
82
|
+
let newOffset = scrollOffset;
|
|
83
|
+
if (hasLimit && next >= scrollOffset + limit) newOffset = next - limit + 1;
|
|
84
|
+
setSelectedIndex(next);
|
|
85
|
+
setScrollOffset(newOffset);
|
|
86
|
+
if (typeof onHighlight === "function") onHighlight(items[next]);
|
|
87
|
+
}
|
|
88
|
+
if (key.return) {
|
|
89
|
+
if (typeof onSelect === "function") onSelect(items[selectedIndex]);
|
|
90
|
+
}
|
|
91
|
+
}, [hasLimit, limit, scrollOffset, selectedIndex, items, onSelect, onHighlight]), { isActive: isFocused });
|
|
92
|
+
|
|
93
|
+
const visible = hasLimit ? items.slice(scrollOffset, scrollOffset + limit) : items;
|
|
94
|
+
return h(Box, { flexDirection: "column" }, visible.map((item, index) => {
|
|
95
|
+
const isSelected = index + scrollOffset === selectedIndex;
|
|
96
|
+
return h(Box, { key: item.key ?? item.value },
|
|
97
|
+
h(indicatorComponent, { isSelected }),
|
|
98
|
+
h(itemComponent, { ...item, isSelected }));
|
|
99
|
+
}));
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
// ── Screens ─────────────────────────────────────────────────────
|
|
103
|
+
const SCREEN = {
|
|
104
|
+
SCOPE: 0,
|
|
105
|
+
PRESET: 1,
|
|
106
|
+
PREVIEW: 2,
|
|
107
|
+
SCANNING: 3,
|
|
108
|
+
GAME_PICK: 4,
|
|
109
|
+
GAME_SOUNDS: 5,
|
|
110
|
+
EXTRACTING: 6,
|
|
111
|
+
CONFIRM: 7,
|
|
112
|
+
INSTALLING: 8,
|
|
113
|
+
DONE: 9,
|
|
114
|
+
MUSIC_MODE: 10,
|
|
115
|
+
MUSIC_GAME_PICK: 11,
|
|
116
|
+
MUSIC_PLAYING: 12,
|
|
117
|
+
MUSIC_EXTRACTING: 13,
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
const isUninstallMode = process.argv.includes("--uninstall") || process.argv.includes("--remove");
|
|
121
|
+
|
|
122
|
+
// ── Header component ────────────────────────────────────────────
|
|
123
|
+
const Header = () =>
|
|
124
|
+
h(Box, { flexDirection: "column", marginBottom: 1 },
|
|
125
|
+
h(Text, { bold: true, color: ACCENT }, " klaudio"),
|
|
126
|
+
h(Text, { dimColor: true }, isUninstallMode
|
|
127
|
+
? " Remove sound effects from Claude Code"
|
|
128
|
+
: " Add sound effects to your Claude Code sessions"),
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
const NavHint = ({ back = true, extra = "" }) =>
|
|
132
|
+
h(Box, { marginTop: 1 },
|
|
133
|
+
h(Text, { dimColor: true },
|
|
134
|
+
(back ? " esc back" : "") +
|
|
135
|
+
(extra ? (back ? " • " : " ") + extra : "")
|
|
136
|
+
),
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
// ── Screen: Scope ───────────────────────────────────────────────
|
|
140
|
+
const ScopeScreen = ({ onNext, onMusic, onUpdate, tts, onToggleTts, voice, hasKokoro, onCycleVoice, outdatedReasons }) => {
|
|
141
|
+
const isOutdated = outdatedReasons && outdatedReasons.length > 0;
|
|
142
|
+
const items = [
|
|
143
|
+
...(isOutdated ? [{ label: "⬆ Apply updates", value: "_update" }] : []),
|
|
144
|
+
{ label: "Global — Claude Code + Copilot (all projects)", value: "global" },
|
|
145
|
+
{ label: "This project — Claude Code + Copilot (this project only)", value: "project" },
|
|
146
|
+
{ label: "🎵 Play game music while you code", value: "_music" },
|
|
147
|
+
];
|
|
148
|
+
const [sel, setSel] = useState(0);
|
|
149
|
+
const [previewing, setPreviewing] = useState(false);
|
|
150
|
+
const GAP_AT = (isOutdated ? 1 : 0) + 2; // visual gap before music
|
|
151
|
+
const voiceInfo = hasKokoro ? KOKORO_VOICES.find((v) => v.id === voice) : null;
|
|
152
|
+
|
|
153
|
+
useInput((input, key) => {
|
|
154
|
+
if (input === "k" || key.upArrow) {
|
|
155
|
+
setSel((i) => Math.max(0, i - 1));
|
|
156
|
+
} else if (input === "j" || key.downArrow) {
|
|
157
|
+
setSel((i) => Math.min(items.length - 1, i + 1));
|
|
158
|
+
} else if (input === "t") {
|
|
159
|
+
onToggleTts();
|
|
160
|
+
} else if (input === "v" && tts && hasKokoro) {
|
|
161
|
+
onCycleVoice();
|
|
162
|
+
// Preview the new voice
|
|
163
|
+
setPreviewing(true);
|
|
164
|
+
const nextIdx = (KOKORO_VOICES.findIndex((x) => x.id === voice) + 1) % KOKORO_VOICES.length;
|
|
165
|
+
const nextVoice = KOKORO_VOICES[nextIdx];
|
|
166
|
+
import("../src/tts.js").then(({ speak }) =>
|
|
167
|
+
speak(`Hi, I'm ${nextVoice.name}`, { voice: nextVoice.id })
|
|
168
|
+
).finally(() => setPreviewing(false));
|
|
169
|
+
} else if (key.return) {
|
|
170
|
+
const v = items[sel].value;
|
|
171
|
+
if (v === "_update") onUpdate();
|
|
172
|
+
else if (v === "_music") onMusic();
|
|
173
|
+
else onNext(v);
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
return h(Box, { flexDirection: "column" },
|
|
178
|
+
isOutdated
|
|
179
|
+
? h(Box, { flexDirection: "column", marginLeft: 2, marginBottom: 1 },
|
|
180
|
+
h(Text, { color: "yellow", bold: true }, " Updates available:"),
|
|
181
|
+
...outdatedReasons.map((r, i) =>
|
|
182
|
+
h(Text, { key: i, color: "yellow", dimColor: true, marginLeft: 4 }, `+ ${r}`),
|
|
183
|
+
),
|
|
184
|
+
)
|
|
185
|
+
: null,
|
|
186
|
+
h(Text, { bold: true }, " Where should sounds be installed?"),
|
|
187
|
+
h(Box, { flexDirection: "column", marginLeft: 2 },
|
|
188
|
+
...items.map((item, i) => h(React.Fragment, { key: item.value },
|
|
189
|
+
i === GAP_AT ? h(Text, { dimColor: true }, "\n ...or") : null,
|
|
190
|
+
h(Box, null,
|
|
191
|
+
h(Indicator, { isSelected: i === sel }),
|
|
192
|
+
h(Item, { isSelected: i === sel, label: item.label }),
|
|
193
|
+
),
|
|
194
|
+
)),
|
|
195
|
+
),
|
|
196
|
+
h(Box, { marginTop: 1, marginLeft: 4 },
|
|
197
|
+
h(Text, { color: tts ? "green" : "gray" },
|
|
198
|
+
tts ? "🗣 Voice summary: ON" : "🗣 Voice summary: OFF",
|
|
199
|
+
),
|
|
200
|
+
h(Text, { dimColor: true }, " (t to toggle)"),
|
|
201
|
+
),
|
|
202
|
+
tts && voiceInfo ? h(Box, { marginLeft: 4 },
|
|
203
|
+
h(Text, { color: ACCENT },
|
|
204
|
+
previewing
|
|
205
|
+
? `🎙 Voice: ${voiceInfo.name} (previewing...)`
|
|
206
|
+
: `🎙 Voice: ${voiceInfo.name} (${voiceInfo.gender}, ${voiceInfo.accent})`,
|
|
207
|
+
),
|
|
208
|
+
h(Text, { dimColor: true }, " (v to change & preview)"),
|
|
209
|
+
) : null,
|
|
210
|
+
);
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
// ── Screen: Preset ──────────────────────────────────────────────
|
|
214
|
+
const PresetScreen = ({ existingSounds, outdatedReasons, onNext, onReapply, onBack }) => {
|
|
215
|
+
const hasExisting = existingSounds && Object.values(existingSounds).some(Boolean);
|
|
216
|
+
const isOutdated = outdatedReasons && outdatedReasons.length > 0;
|
|
217
|
+
const items = [
|
|
218
|
+
...(hasExisting ? [{
|
|
219
|
+
label: isOutdated
|
|
220
|
+
? "⬆ Update hooks — new features available for your current sounds"
|
|
221
|
+
: "✓ Re-apply current sounds — update config with current selections",
|
|
222
|
+
value: "_reapply",
|
|
223
|
+
}] : []),
|
|
224
|
+
...Object.entries(PRESETS).map(([id, p]) => ({
|
|
225
|
+
label: `${p.icon} ${p.name} — ${p.description}`,
|
|
226
|
+
value: id,
|
|
227
|
+
})),
|
|
228
|
+
// separator before these
|
|
229
|
+
{ label: "🔔 System sounds — use built-in OS notification sounds", value: "_system" },
|
|
230
|
+
{ label: "🕹️ Scan your games library — find sounds from Steam & Epic Games", value: "_scan" },
|
|
231
|
+
{ label: "📁 Custom files — provide your own sound files", value: "_custom" },
|
|
232
|
+
];
|
|
233
|
+
const GAP_AT = (hasExisting ? 1 : 0) + Object.keys(PRESETS).length; // separator before non-preset options
|
|
234
|
+
const [sel, setSel] = useState(0);
|
|
235
|
+
|
|
236
|
+
useInput((input, key) => {
|
|
237
|
+
if (key.escape) onBack();
|
|
238
|
+
else if (input === "k" || key.upArrow) setSel((i) => Math.max(0, i - 1));
|
|
239
|
+
else if (input === "j" || key.downArrow) setSel((i) => Math.min(items.length - 1, i + 1));
|
|
240
|
+
else if (key.return) {
|
|
241
|
+
if (items[sel].value === "_reapply") onReapply();
|
|
242
|
+
else onNext(items[sel].value);
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
return h(Box, { flexDirection: "column" },
|
|
247
|
+
h(Text, { bold: true }, " Choose a sound preset:"),
|
|
248
|
+
hasExisting
|
|
249
|
+
? h(Box, { flexDirection: "column", marginLeft: 4, marginBottom: 1 },
|
|
250
|
+
h(Text, { dimColor: true }, "Current sounds:"),
|
|
251
|
+
...Object.entries(existingSounds).filter(([_, p]) => p).map(([eid, p]) =>
|
|
252
|
+
h(Text, { key: eid, color: "green", dimColor: true }, ` ✓ ${EVENTS[eid].name}: ${shortName(p)}`),
|
|
253
|
+
),
|
|
254
|
+
isOutdated
|
|
255
|
+
? h(Box, { flexDirection: "column", marginTop: 1 },
|
|
256
|
+
h(Text, { color: "yellow" }, " Updates available:"),
|
|
257
|
+
...outdatedReasons.map((r, i) =>
|
|
258
|
+
h(Text, { key: i, color: "yellow", dimColor: true }, ` + ${r}`),
|
|
259
|
+
),
|
|
260
|
+
)
|
|
261
|
+
: null,
|
|
262
|
+
)
|
|
263
|
+
: null,
|
|
264
|
+
h(Box, { flexDirection: "column", marginLeft: 2 },
|
|
265
|
+
...items.map((item, i) => h(React.Fragment, { key: item.value },
|
|
266
|
+
i === GAP_AT ? h(Text, { dimColor: true }, "\n ...or pick your own") : null,
|
|
267
|
+
h(Box, null,
|
|
268
|
+
h(Indicator, { isSelected: i === sel }),
|
|
269
|
+
h(Item, { isSelected: i === sel, label: item.label }),
|
|
270
|
+
),
|
|
271
|
+
)),
|
|
272
|
+
),
|
|
273
|
+
h(NavHint, { back: true }),
|
|
274
|
+
);
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
// ── Screen: Preview ─────────────────────────────────────────────
|
|
278
|
+
const PreviewScreen = ({ presetId, sounds, onAccept, onBack, onUpdateSound }) => {
|
|
279
|
+
const preset = PRESETS[presetId];
|
|
280
|
+
const eventIds = Object.keys(EVENTS);
|
|
281
|
+
const [currentEvent, setCurrentEvent] = useState(0);
|
|
282
|
+
const [playing, setPlaying] = useState(false);
|
|
283
|
+
const [elapsed, setElapsed] = useState(0);
|
|
284
|
+
const [durations, setDurations] = useState({});
|
|
285
|
+
const cancelRef = React.useRef(null);
|
|
286
|
+
|
|
287
|
+
const eventId = eventIds[currentEvent];
|
|
288
|
+
const eventInfo = EVENTS[eventId];
|
|
289
|
+
const soundFile = sounds[eventId];
|
|
290
|
+
|
|
291
|
+
const stopPlayback = useCallback(() => {
|
|
292
|
+
if (cancelRef.current) { cancelRef.current(); cancelRef.current = null; }
|
|
293
|
+
setPlaying(false);
|
|
294
|
+
setElapsed(0);
|
|
295
|
+
}, []);
|
|
296
|
+
|
|
297
|
+
// Fetch durations for all sound files
|
|
298
|
+
useEffect(() => {
|
|
299
|
+
for (const [eid, path] of Object.entries(sounds)) {
|
|
300
|
+
if (path && !durations[eid]) {
|
|
301
|
+
getWavDuration(path).then((dur) => {
|
|
302
|
+
if (dur != null) setDurations((d) => ({ ...d, [eid]: dur }));
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}, [sounds]);
|
|
307
|
+
|
|
308
|
+
// Auto-play when current event changes (with debounce)
|
|
309
|
+
useEffect(() => {
|
|
310
|
+
if (!soundFile) return;
|
|
311
|
+
stopPlayback();
|
|
312
|
+
const timer = setTimeout(() => {
|
|
313
|
+
setPlaying(true);
|
|
314
|
+
const { promise, cancel } = playSoundWithCancel(soundFile);
|
|
315
|
+
cancelRef.current = cancel;
|
|
316
|
+
promise.catch(() => {}).finally(() => {
|
|
317
|
+
cancelRef.current = null;
|
|
318
|
+
setPlaying(false);
|
|
319
|
+
setElapsed(0);
|
|
320
|
+
});
|
|
321
|
+
}, 150);
|
|
322
|
+
return () => {
|
|
323
|
+
clearTimeout(timer);
|
|
324
|
+
if (cancelRef.current) {
|
|
325
|
+
cancelRef.current();
|
|
326
|
+
cancelRef.current = null;
|
|
327
|
+
}
|
|
328
|
+
};
|
|
329
|
+
}, [currentEvent]);
|
|
330
|
+
|
|
331
|
+
useInput((_, key) => {
|
|
332
|
+
if (key.escape) {
|
|
333
|
+
if (playing) {
|
|
334
|
+
stopPlayback();
|
|
335
|
+
} else {
|
|
336
|
+
onBack();
|
|
337
|
+
}
|
|
338
|
+
} else if (key.leftArrow || key.upArrow) {
|
|
339
|
+
if (currentEvent > 0) {
|
|
340
|
+
stopPlayback();
|
|
341
|
+
setCurrentEvent((i) => i - 1);
|
|
342
|
+
}
|
|
343
|
+
} else if (key.rightArrow || key.downArrow) {
|
|
344
|
+
if (currentEvent < eventIds.length - 1) {
|
|
345
|
+
stopPlayback();
|
|
346
|
+
setCurrentEvent((i) => i + 1);
|
|
347
|
+
}
|
|
348
|
+
} else if (key.return) {
|
|
349
|
+
stopPlayback();
|
|
350
|
+
onAccept(sounds);
|
|
351
|
+
}
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
// Elapsed timer while playing
|
|
355
|
+
useEffect(() => {
|
|
356
|
+
if (!playing) return;
|
|
357
|
+
setElapsed(0);
|
|
358
|
+
const interval = setInterval(() => setElapsed((e) => e + 1), 1000);
|
|
359
|
+
return () => clearInterval(interval);
|
|
360
|
+
}, [playing]);
|
|
361
|
+
|
|
362
|
+
const stepLabel = `(${currentEvent + 1}/${eventIds.length})`;
|
|
363
|
+
const dur = durations[eventId];
|
|
364
|
+
const durLabel = dur != null ? ` (${dur > MAX_PLAY_SECONDS ? MAX_PLAY_SECONDS : dur}s)` : "";
|
|
365
|
+
|
|
366
|
+
return h(Box, { flexDirection: "column" },
|
|
367
|
+
h(Text, { bold: true }, ` ${preset.icon} ${preset.name}`),
|
|
368
|
+
h(Text, { dimColor: true }, ` ${preset.description}`),
|
|
369
|
+
h(Box, { marginTop: 1, flexDirection: "column" },
|
|
370
|
+
...eventIds.map((eid, i) => {
|
|
371
|
+
const d = durations[eid];
|
|
372
|
+
const dStr = d != null ? ` (${d > MAX_PLAY_SECONDS ? MAX_PLAY_SECONDS : d}s)` : "";
|
|
373
|
+
return h(Text, { key: eid, marginLeft: 2,
|
|
374
|
+
color: i === currentEvent ? "#00FFFF" : i < currentEvent ? "green" : "white",
|
|
375
|
+
bold: i === currentEvent,
|
|
376
|
+
},
|
|
377
|
+
i < currentEvent ? " ✓ " : i === currentEvent ? " ▸ " : " ",
|
|
378
|
+
`${EVENTS[eid].name}: `,
|
|
379
|
+
sounds[eid] ? `${basename(sounds[eid])}${dStr}` : "(skipped)",
|
|
380
|
+
);
|
|
381
|
+
}),
|
|
382
|
+
),
|
|
383
|
+
h(Box, { marginTop: 1, flexDirection: "column", borderStyle: "round", borderColor: playing ? "green" : "cyan", paddingX: 2, paddingY: 0, marginLeft: 2, marginRight: 2 },
|
|
384
|
+
h(Text, { bold: true, color: playing ? "green" : "cyan" },
|
|
385
|
+
`${eventInfo.name} ${stepLabel}`,
|
|
386
|
+
),
|
|
387
|
+
h(Text, { dimColor: true },
|
|
388
|
+
soundFile
|
|
389
|
+
? `Sound: ${basename(soundFile)}${durLabel}`
|
|
390
|
+
: "No sound file selected",
|
|
391
|
+
),
|
|
392
|
+
h(Text, { dimColor: true },
|
|
393
|
+
`Triggers: ${eventInfo.description}`,
|
|
394
|
+
),
|
|
395
|
+
playing
|
|
396
|
+
? h(Box, { marginTop: 1 },
|
|
397
|
+
h(Text, { color: "green", bold: true }, h(Spinner, { type: "dots" })),
|
|
398
|
+
h(Text, { color: "green", bold: true }, ` Now playing: ${basename(soundFile)} ${elapsed}s / ${MAX_PLAY_SECONDS}s max`),
|
|
399
|
+
)
|
|
400
|
+
: null,
|
|
401
|
+
),
|
|
402
|
+
h(NavHint, { back: true, extra: "↑↓ switch events • enter accept all" }),
|
|
403
|
+
);
|
|
404
|
+
};
|
|
405
|
+
|
|
406
|
+
// ── Screen: Game Pick (with progressive background scanning) ────
|
|
407
|
+
const GamePickScreen = ({ onNext, onExtract, onBack }) => {
|
|
408
|
+
const [games, setGames] = useState([]);
|
|
409
|
+
const [scanning, setScanning] = useState(true);
|
|
410
|
+
const [scanStatus, setScanStatus] = useState("Discovering game directories...");
|
|
411
|
+
const [filter, setFilter] = useState("");
|
|
412
|
+
|
|
413
|
+
// Start scanning on mount, add games progressively
|
|
414
|
+
useEffect(() => {
|
|
415
|
+
let cancelled = false;
|
|
416
|
+
getAvailableGames(
|
|
417
|
+
(progress) => {
|
|
418
|
+
if (cancelled) return;
|
|
419
|
+
if (progress.phase === "dirs") {
|
|
420
|
+
setScanStatus(`Scanning ${progress.dirs.length} directories...`);
|
|
421
|
+
} else if (progress.phase === "scanning") {
|
|
422
|
+
setScanStatus(`Scanning: ${progress.game}`);
|
|
423
|
+
}
|
|
424
|
+
},
|
|
425
|
+
(game) => {
|
|
426
|
+
if (cancelled) return;
|
|
427
|
+
// Add each game as it's found (only if it has audio or can extract)
|
|
428
|
+
setGames((prev) => {
|
|
429
|
+
if (prev.some((g) => g.name === game.name)) return prev;
|
|
430
|
+
const next = [...prev, game];
|
|
431
|
+
// Sort: playable first, then extractable, then others
|
|
432
|
+
next.sort((a, b) => {
|
|
433
|
+
if (a.hasAudio !== b.hasAudio) return a.hasAudio ? -1 : 1;
|
|
434
|
+
if (a.canExtract !== b.canExtract) return a.canExtract ? -1 : 1;
|
|
435
|
+
return a.name.localeCompare(b.name);
|
|
436
|
+
});
|
|
437
|
+
return next;
|
|
438
|
+
});
|
|
439
|
+
},
|
|
440
|
+
).then(() => {
|
|
441
|
+
if (!cancelled) setScanning(false);
|
|
442
|
+
}).catch(() => {
|
|
443
|
+
if (!cancelled) setScanning(false);
|
|
444
|
+
});
|
|
445
|
+
return () => { cancelled = true; };
|
|
446
|
+
}, []);
|
|
447
|
+
|
|
448
|
+
useInput((input, key) => {
|
|
449
|
+
if (key.escape) {
|
|
450
|
+
if (filter) setFilter("");
|
|
451
|
+
else onBack();
|
|
452
|
+
} else if (key.backspace || key.delete) {
|
|
453
|
+
setFilter((f) => f.slice(0, -1));
|
|
454
|
+
} else if (input && !key.ctrl && !key.meta && input.length === 1 && input.charCodeAt(0) >= 32) {
|
|
455
|
+
setFilter((f) => f + input);
|
|
456
|
+
}
|
|
457
|
+
});
|
|
458
|
+
|
|
459
|
+
const usableGames = games.filter((g) => g.hasAudio || g.canExtract);
|
|
460
|
+
const noAudio = games.filter((g) => !g.hasAudio && !g.canExtract);
|
|
461
|
+
|
|
462
|
+
const allItems = usableGames
|
|
463
|
+
.sort((a, b) => a.name.localeCompare(b.name))
|
|
464
|
+
.map((g) => {
|
|
465
|
+
if (g.hasAudio) {
|
|
466
|
+
return {
|
|
467
|
+
key: `play:${g.name}`,
|
|
468
|
+
label: `${g.name} (${g.fileCount} audio files)`,
|
|
469
|
+
value: `play:${g.name}`,
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
const hasUnity = (g.unityAudioCount || 0) > 0;
|
|
473
|
+
const hasPacked = (g.packedAudioCount || 0) > 0;
|
|
474
|
+
const detail = hasUnity && !hasPacked
|
|
475
|
+
? `${g.unityAudioCount} Unity audio resource(s) — extract`
|
|
476
|
+
: hasPacked && !hasUnity
|
|
477
|
+
? `${g.packedAudioCount} packed — extract with vgmstream`
|
|
478
|
+
: `${g.packedAudioCount} packed + ${g.unityAudioCount} Unity — extract`;
|
|
479
|
+
return {
|
|
480
|
+
key: `extract:${g.name}`,
|
|
481
|
+
label: `${g.name} (${detail})`,
|
|
482
|
+
value: `extract:${g.name}`,
|
|
483
|
+
};
|
|
484
|
+
});
|
|
485
|
+
|
|
486
|
+
const filterLower = filter.toLowerCase();
|
|
487
|
+
const items = filter
|
|
488
|
+
? allItems.filter((i) => i.label.toLowerCase().includes(filterLower))
|
|
489
|
+
: allItems;
|
|
490
|
+
|
|
491
|
+
return h(Box, { flexDirection: "column" },
|
|
492
|
+
scanning
|
|
493
|
+
? h(Box, { marginLeft: 2 },
|
|
494
|
+
h(Text, { color: ACCENT }, h(Spinner, { type: "dots" })),
|
|
495
|
+
h(Text, null, ` ${scanStatus}`),
|
|
496
|
+
games.length > 0
|
|
497
|
+
? h(Text, { color: "green" }, ` (${games.length} found)`)
|
|
498
|
+
: null,
|
|
499
|
+
)
|
|
500
|
+
: h(Text, { bold: true, marginLeft: 2 },
|
|
501
|
+
` Found ${games.length} game(s):`,
|
|
502
|
+
),
|
|
503
|
+
filter
|
|
504
|
+
? h(Box, { marginLeft: 4 },
|
|
505
|
+
h(Text, { color: "yellow" }, "Filter: "),
|
|
506
|
+
h(Text, { bold: true }, filter),
|
|
507
|
+
h(Text, { dimColor: true }, ` (${items.length} match${items.length !== 1 ? "es" : ""})`),
|
|
508
|
+
)
|
|
509
|
+
: items.length > 0
|
|
510
|
+
? h(Text, { dimColor: true, marginLeft: 4 }, "Type to filter... (select a game while scan continues)")
|
|
511
|
+
: null,
|
|
512
|
+
items.length > 0
|
|
513
|
+
? h(Box, { marginLeft: 2 },
|
|
514
|
+
h(SelectInput, { indicatorComponent: Indicator, itemComponent: Item,
|
|
515
|
+
items,
|
|
516
|
+
limit: 15,
|
|
517
|
+
onSelect: (item) => {
|
|
518
|
+
const [type, ...rest] = item.value.split(":");
|
|
519
|
+
const name = rest.join(":");
|
|
520
|
+
if (type === "extract") onExtract(name, games);
|
|
521
|
+
else onNext(name, games);
|
|
522
|
+
},
|
|
523
|
+
}),
|
|
524
|
+
)
|
|
525
|
+
: !scanning
|
|
526
|
+
? h(Text, { color: "yellow", marginLeft: 4 }, "No games with usable audio found.")
|
|
527
|
+
: null,
|
|
528
|
+
noAudio.length > 0 && !filter && !scanning
|
|
529
|
+
? h(Box, { flexDirection: "column", marginTop: 1, marginLeft: 4 },
|
|
530
|
+
h(Text, { dimColor: true },
|
|
531
|
+
`${noAudio.length} game(s) with no extractable audio:`,
|
|
532
|
+
),
|
|
533
|
+
h(Text, { dimColor: true },
|
|
534
|
+
noAudio.map((g) => g.name).join(", "),
|
|
535
|
+
),
|
|
536
|
+
)
|
|
537
|
+
: null,
|
|
538
|
+
h(NavHint, { back: true }),
|
|
539
|
+
);
|
|
540
|
+
};
|
|
541
|
+
|
|
542
|
+
// ── Screen: Game Sound Picker ───────────────────────────────────
|
|
543
|
+
// Three-phase: category pick → file pick → preview/accept/repick
|
|
544
|
+
const CATEGORY_LABELS = {
|
|
545
|
+
all: "All sounds", ambient: "Ambient", music: "Music", sfx: "SFX",
|
|
546
|
+
ui: "UI", voice: "Voice / Dialogue", creature: "Creatures / Animals", other: "Other",
|
|
547
|
+
};
|
|
548
|
+
const CATEGORY_ICONS = {
|
|
549
|
+
voice: "🗣", creature: "🐾", ui: "🖱", sfx: "💥",
|
|
550
|
+
ambient: "🌿", music: "🎵", other: "📦", all: "📂",
|
|
551
|
+
};
|
|
552
|
+
|
|
553
|
+
const FileItem = ({ isSelected, label, usedTag }) =>
|
|
554
|
+
h(Box, null,
|
|
555
|
+
h(Text, { color: isSelected ? ACCENT : undefined, bold: isSelected }, label),
|
|
556
|
+
usedTag ? h(Text, { dimColor: true }, usedTag) : null,
|
|
557
|
+
);
|
|
558
|
+
|
|
559
|
+
const GameSoundsScreen = ({ game, sounds, onSelectSound, onDone, onBack }) => {
|
|
560
|
+
const eventIds = Object.keys(EVENTS);
|
|
561
|
+
const [currentEvent, setCurrentEvent] = useState(0);
|
|
562
|
+
const [playing, setPlaying] = useState(false);
|
|
563
|
+
const [elapsed, setElapsed] = useState(0);
|
|
564
|
+
const [highlightedFile, setHighlightedFile] = useState(null);
|
|
565
|
+
const [fileDurations, setFileDurations] = useState({});
|
|
566
|
+
const [filter, setFilter] = useState("");
|
|
567
|
+
const [activeCategory, setActiveCategory] = useState(null); // null = show category picker
|
|
568
|
+
const [autoPreview, setAutoPreview] = useState(true);
|
|
569
|
+
const [justSelected, setJustSelected] = useState(null); // brief confirmation flash
|
|
570
|
+
const cancelRef = React.useRef(null);
|
|
571
|
+
|
|
572
|
+
// Determine available categories with counts
|
|
573
|
+
const hasCategories = game.files.some((f) => f.category);
|
|
574
|
+
const { categories, counts } = hasCategories
|
|
575
|
+
? getCategories(game.files)
|
|
576
|
+
: { categories: ["all"], counts: {} };
|
|
577
|
+
const meaningfulCats = categories.filter((c) => c !== "all" && (counts[c] || 0) >= 2);
|
|
578
|
+
const showCategoryPicker = meaningfulCats.length >= 2;
|
|
579
|
+
|
|
580
|
+
// Sort files: voice first, then by priority (memoized for stable references)
|
|
581
|
+
const sortedFiles = useMemo(() => hasCategories ? sortFilesByPriority(game.files) : game.files, [game.files, hasCategories]);
|
|
582
|
+
|
|
583
|
+
// Filter files by category (memoized to prevent infinite re-render loops)
|
|
584
|
+
const categoryFiles = useMemo(() => activeCategory && activeCategory !== "all"
|
|
585
|
+
? sortedFiles.filter((f) => f.category === activeCategory)
|
|
586
|
+
: sortedFiles, [sortedFiles, activeCategory]);
|
|
587
|
+
|
|
588
|
+
// Stop current playback helper
|
|
589
|
+
const stopPlayback = useCallback(() => {
|
|
590
|
+
if (cancelRef.current) {
|
|
591
|
+
cancelRef.current();
|
|
592
|
+
cancelRef.current = null;
|
|
593
|
+
}
|
|
594
|
+
setPlaying(false);
|
|
595
|
+
setElapsed(0);
|
|
596
|
+
}, []);
|
|
597
|
+
|
|
598
|
+
// Pre-fetch durations: first 15 on category enter, ±15 around highlighted file
|
|
599
|
+
useEffect(() => {
|
|
600
|
+
const end = Math.min(categoryFiles.length, 15);
|
|
601
|
+
for (let i = 0; i < end; i++) {
|
|
602
|
+
const f = categoryFiles[i];
|
|
603
|
+
if (!fileDurations[f.path]) {
|
|
604
|
+
getWavDuration(f.path).then((dur) => {
|
|
605
|
+
if (dur != null) setFileDurations((d) => ({ ...d, [f.path]: dur }));
|
|
606
|
+
});
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
}, [activeCategory]);
|
|
610
|
+
|
|
611
|
+
useEffect(() => {
|
|
612
|
+
if (!highlightedFile || highlightedFile === "_skip") return;
|
|
613
|
+
const idx = categoryFiles.findIndex((f) => f.path === highlightedFile);
|
|
614
|
+
if (idx < 0) return;
|
|
615
|
+
const start = Math.max(0, idx - 15);
|
|
616
|
+
const end = Math.min(categoryFiles.length, idx + 16);
|
|
617
|
+
for (let i = start; i < end; i++) {
|
|
618
|
+
const f = categoryFiles[i];
|
|
619
|
+
if (!fileDurations[f.path]) {
|
|
620
|
+
getWavDuration(f.path).then((dur) => {
|
|
621
|
+
if (dur != null) setFileDurations((d) => ({ ...d, [f.path]: dur }));
|
|
622
|
+
});
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
}, [highlightedFile, categoryFiles]);
|
|
626
|
+
|
|
627
|
+
// Auto-preview: play sound when highlighted file changes (with debounce)
|
|
628
|
+
useEffect(() => {
|
|
629
|
+
if (!autoPreview || !highlightedFile || highlightedFile === "_skip") {
|
|
630
|
+
return;
|
|
631
|
+
}
|
|
632
|
+
// Cancel previous playback immediately
|
|
633
|
+
if (cancelRef.current) {
|
|
634
|
+
cancelRef.current();
|
|
635
|
+
cancelRef.current = null;
|
|
636
|
+
}
|
|
637
|
+
setPlaying(false);
|
|
638
|
+
setElapsed(0);
|
|
639
|
+
// Debounce: wait 150ms before starting playback so scrubbing doesn't spam
|
|
640
|
+
const timer = setTimeout(() => {
|
|
641
|
+
setPlaying(true);
|
|
642
|
+
setElapsed(0);
|
|
643
|
+
const { promise, cancel } = playSoundWithCancel(highlightedFile);
|
|
644
|
+
cancelRef.current = cancel;
|
|
645
|
+
promise.catch(() => {}).finally(() => {
|
|
646
|
+
cancelRef.current = null;
|
|
647
|
+
setPlaying(false);
|
|
648
|
+
setElapsed(0);
|
|
649
|
+
});
|
|
650
|
+
}, 150);
|
|
651
|
+
return () => {
|
|
652
|
+
clearTimeout(timer);
|
|
653
|
+
if (cancelRef.current) {
|
|
654
|
+
cancelRef.current();
|
|
655
|
+
cancelRef.current = null;
|
|
656
|
+
}
|
|
657
|
+
};
|
|
658
|
+
}, [highlightedFile, autoPreview]);
|
|
659
|
+
|
|
660
|
+
useInput((input, key) => {
|
|
661
|
+
if (key.tab) {
|
|
662
|
+
// Tab cycles through events + Apply tab (if any sounds assigned)
|
|
663
|
+
stopPlayback();
|
|
664
|
+
const hasSounds = Object.values(sounds).some(Boolean);
|
|
665
|
+
const tabCount = hasSounds ? eventIds.length + 1 : eventIds.length;
|
|
666
|
+
setCurrentEvent((i) => (i + 1) % tabCount);
|
|
667
|
+
} else if (key.escape) {
|
|
668
|
+
if (playing) {
|
|
669
|
+
stopPlayback();
|
|
670
|
+
} else if (filter) {
|
|
671
|
+
setFilter("");
|
|
672
|
+
} else if (activeCategory !== null && showCategoryPicker) {
|
|
673
|
+
stopPlayback();
|
|
674
|
+
setActiveCategory(null);
|
|
675
|
+
} else {
|
|
676
|
+
stopPlayback();
|
|
677
|
+
onBack();
|
|
678
|
+
}
|
|
679
|
+
} else if (input === "p" && !key.ctrl && !key.meta) {
|
|
680
|
+
// Toggle auto-preview
|
|
681
|
+
setAutoPreview((prev) => {
|
|
682
|
+
if (prev) stopPlayback();
|
|
683
|
+
return !prev;
|
|
684
|
+
});
|
|
685
|
+
} else if (activeCategory !== null || !showCategoryPicker) {
|
|
686
|
+
if (key.backspace || key.delete) {
|
|
687
|
+
setFilter((f) => f.slice(0, -1));
|
|
688
|
+
} else if (input && input !== "p" && !key.ctrl && !key.meta && input.length === 1 && input.charCodeAt(0) >= 32) {
|
|
689
|
+
setFilter((f) => f + input);
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
});
|
|
693
|
+
|
|
694
|
+
// Elapsed timer while playing
|
|
695
|
+
useEffect(() => {
|
|
696
|
+
if (!playing) return;
|
|
697
|
+
setElapsed(0);
|
|
698
|
+
const interval = setInterval(() => {
|
|
699
|
+
setElapsed((e) => e + 1);
|
|
700
|
+
}, 1000);
|
|
701
|
+
return () => clearInterval(interval);
|
|
702
|
+
}, [playing]);
|
|
703
|
+
|
|
704
|
+
// Parse duration filter: "10s", "<10s", "< 10s", ">5s", "> 5s", "<=10s", ">=5s"
|
|
705
|
+
// (must be before early returns to satisfy React hook rules)
|
|
706
|
+
const durationFilter = useMemo(() => {
|
|
707
|
+
const m = filter.match(/^\s*(<|>|<=|>=)?\s*(\d+(?:\.\d+)?)\s*s\s*$/);
|
|
708
|
+
if (!m) return null;
|
|
709
|
+
const op = m[1] || "<=";
|
|
710
|
+
const val = parseFloat(m[2]);
|
|
711
|
+
return { op, val };
|
|
712
|
+
}, [filter]);
|
|
713
|
+
|
|
714
|
+
const eventId = eventIds[currentEvent];
|
|
715
|
+
const eventInfo = EVENTS[eventId];
|
|
716
|
+
const stepLabel = `(${currentEvent + 1}/${eventIds.length})`;
|
|
717
|
+
|
|
718
|
+
const advance = useCallback((selectedFile, selectedEventId) => {
|
|
719
|
+
stopPlayback();
|
|
720
|
+
// Show confirmation flash
|
|
721
|
+
if (selectedFile) {
|
|
722
|
+
setJustSelected({ file: basename(selectedFile), event: EVENTS[selectedEventId]?.name || selectedEventId });
|
|
723
|
+
}
|
|
724
|
+
const doAdvance = () => {
|
|
725
|
+
setJustSelected(null);
|
|
726
|
+
// Move to next event that hasn't been assigned yet, or wrap around
|
|
727
|
+
const nextUnassigned = eventIds.findIndex((eid, i) => i > currentEvent && !sounds[eid]);
|
|
728
|
+
if (nextUnassigned >= 0) {
|
|
729
|
+
setCurrentEvent(nextUnassigned);
|
|
730
|
+
} else {
|
|
731
|
+
// All done or wrapped — go to next sequential
|
|
732
|
+
setCurrentEvent((i) => Math.min(i + 1, eventIds.length - 1));
|
|
733
|
+
}
|
|
734
|
+
setHighlightedFile(null);
|
|
735
|
+
setActiveCategory(null);
|
|
736
|
+
setFilter("");
|
|
737
|
+
};
|
|
738
|
+
if (selectedFile) {
|
|
739
|
+
setTimeout(doAdvance, 600);
|
|
740
|
+
} else {
|
|
741
|
+
doAdvance();
|
|
742
|
+
}
|
|
743
|
+
}, [currentEvent, eventIds, sounds, stopPlayback]);
|
|
744
|
+
|
|
745
|
+
const nowPlayingFile = playing && highlightedFile && highlightedFile !== "_skip"
|
|
746
|
+
? highlightedFile : null;
|
|
747
|
+
|
|
748
|
+
const hasAnySounds = Object.values(sounds).some(Boolean);
|
|
749
|
+
const allAssigned = eventIds.every((eid) => sounds[eid]);
|
|
750
|
+
// currentEvent can be eventIds.length to mean "Done" tab
|
|
751
|
+
const onDoneTab = currentEvent >= eventIds.length;
|
|
752
|
+
|
|
753
|
+
const headerBox = h(Box, { marginLeft: 2, marginBottom: 1, flexDirection: "column", borderStyle: "round", borderColor: nowPlayingFile ? "green" : ACCENT, paddingX: 2 },
|
|
754
|
+
h(Text, { bold: true, color: nowPlayingFile ? "green" : ACCENT },
|
|
755
|
+
`${game.name}`,
|
|
756
|
+
),
|
|
757
|
+
h(Box, { marginTop: 0, gap: 2, overflowX: "hidden" },
|
|
758
|
+
...eventIds.map((eid, i) => {
|
|
759
|
+
const assigned = sounds[eid];
|
|
760
|
+
const isCurrent = i === currentEvent;
|
|
761
|
+
const truncName = assigned ? basename(assigned).slice(0, 20) : null;
|
|
762
|
+
const prefix = isCurrent ? "▸" : assigned ? "✓" : "·";
|
|
763
|
+
const label = truncName
|
|
764
|
+
? `${prefix} ${EVENTS[eid].name}: ${truncName}`
|
|
765
|
+
: `${prefix} ${EVENTS[eid].name}`;
|
|
766
|
+
return h(Text, {
|
|
767
|
+
key: eid,
|
|
768
|
+
bold: isCurrent,
|
|
769
|
+
color: isCurrent ? ACCENT : assigned ? "green" : "gray",
|
|
770
|
+
}, label);
|
|
771
|
+
}),
|
|
772
|
+
h(Text, {
|
|
773
|
+
key: "_done",
|
|
774
|
+
bold: onDoneTab,
|
|
775
|
+
color: onDoneTab ? ACCENT : hasAnySounds ? "green" : "gray",
|
|
776
|
+
}, onDoneTab ? "▸ ✓ Apply" : hasAnySounds ? "· ✓ Apply" : "· Apply"),
|
|
777
|
+
h(Text, { dimColor: true }, "(tab)"),
|
|
778
|
+
),
|
|
779
|
+
onDoneTab
|
|
780
|
+
? h(Text, { dimColor: true }, "Press enter to apply your sound selections")
|
|
781
|
+
: sounds[eventId]
|
|
782
|
+
? h(Text, { color: "green" }, `✓ ${basename(sounds[eventId])} — ${eventInfo.description}`)
|
|
783
|
+
: h(Text, { dimColor: true }, `${eventInfo.description}`),
|
|
784
|
+
);
|
|
785
|
+
|
|
786
|
+
const nowPlayingBar = h(Box, { marginLeft: 2, height: 1 },
|
|
787
|
+
justSelected
|
|
788
|
+
? h(Text, { color: "green", bold: true }, ` ✓ Selected "${justSelected.file}" for ${justSelected.event}`)
|
|
789
|
+
: nowPlayingFile
|
|
790
|
+
? h(Box, null,
|
|
791
|
+
h(Text, { color: "green", bold: true }, h(Spinner, { type: "dots" })),
|
|
792
|
+
h(Text, { color: "green", bold: true }, ` Now playing: ${basename(nowPlayingFile)} ${elapsed}s / ${MAX_PLAY_SECONDS}s max`),
|
|
793
|
+
)
|
|
794
|
+
: h(Text, { dimColor: true }, " "),
|
|
795
|
+
);
|
|
796
|
+
|
|
797
|
+
// Apply tab: show summary and confirm
|
|
798
|
+
if (onDoneTab) {
|
|
799
|
+
const confirmItems = [
|
|
800
|
+
{ label: "✓ Apply sounds", value: "apply" },
|
|
801
|
+
{ label: "← Back to editing", value: "back" },
|
|
802
|
+
];
|
|
803
|
+
return h(Box, { flexDirection: "column" },
|
|
804
|
+
headerBox,
|
|
805
|
+
h(Box, { flexDirection: "column", marginLeft: 4, marginBottom: 1 },
|
|
806
|
+
...eventIds.map((eid) =>
|
|
807
|
+
h(Text, { key: eid, color: sounds[eid] ? "green" : "gray" },
|
|
808
|
+
sounds[eid] ? ` ✓ ${EVENTS[eid].name}: ${basename(sounds[eid])}` : ` · ${EVENTS[eid].name}: (skipped)`,
|
|
809
|
+
),
|
|
810
|
+
),
|
|
811
|
+
),
|
|
812
|
+
h(Box, { marginLeft: 2 },
|
|
813
|
+
h(SelectInput, { indicatorComponent: Indicator, itemComponent: Item,
|
|
814
|
+
items: confirmItems,
|
|
815
|
+
onSelect: (item) => {
|
|
816
|
+
if (item.value === "apply") {
|
|
817
|
+
stopPlayback();
|
|
818
|
+
onDone();
|
|
819
|
+
} else {
|
|
820
|
+
setCurrentEvent(0);
|
|
821
|
+
}
|
|
822
|
+
},
|
|
823
|
+
}),
|
|
824
|
+
),
|
|
825
|
+
nowPlayingBar,
|
|
826
|
+
h(NavHint, { back: true }),
|
|
827
|
+
);
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
// Phase 0: Category picker
|
|
831
|
+
if (activeCategory === null && showCategoryPicker) {
|
|
832
|
+
const catItems = [
|
|
833
|
+
...meaningfulCats.map((cat) => ({
|
|
834
|
+
label: `${CATEGORY_ICONS[cat] || "📁"} ${CATEGORY_LABELS[cat] || cat} (${counts[cat]} sounds)`,
|
|
835
|
+
value: cat,
|
|
836
|
+
})),
|
|
837
|
+
{ label: `${CATEGORY_ICONS.all} All sounds (${game.files.length})`, value: "all" },
|
|
838
|
+
{ label: "(skip this event)", value: "_skip" },
|
|
839
|
+
];
|
|
840
|
+
|
|
841
|
+
return h(Box, { flexDirection: "column" },
|
|
842
|
+
headerBox,
|
|
843
|
+
h(Text, { bold: true, marginLeft: 4 }, "Pick a category:"),
|
|
844
|
+
h(Box, { marginLeft: 2 },
|
|
845
|
+
h(SelectInput, { indicatorComponent: Indicator, itemComponent: Item,
|
|
846
|
+
items: catItems,
|
|
847
|
+
onSelect: (item) => {
|
|
848
|
+
if (item.value === "_skip") {
|
|
849
|
+
advance();
|
|
850
|
+
} else {
|
|
851
|
+
setActiveCategory(item.value);
|
|
852
|
+
}
|
|
853
|
+
},
|
|
854
|
+
}),
|
|
855
|
+
),
|
|
856
|
+
nowPlayingBar,
|
|
857
|
+
h(NavHint, { back: true }),
|
|
858
|
+
);
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
// Build a reverse map: filePath -> event name(s) it's assigned to
|
|
862
|
+
const assignedToMap = {};
|
|
863
|
+
for (const eid of eventIds) {
|
|
864
|
+
if (sounds[eid]) {
|
|
865
|
+
(assignedToMap[sounds[eid]] ||= []).push(EVENTS[eid].name);
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
// Phase 1: Browse and pick files (auto-preview plays on highlight)
|
|
870
|
+
const filterLower = filter.toLowerCase();
|
|
871
|
+
|
|
872
|
+
const allFileItems = categoryFiles.map((f) => {
|
|
873
|
+
const dur = fileDurations[f.path];
|
|
874
|
+
const durStr = dur != null ? ` (${dur}s${dur > MAX_PLAY_SECONDS ? `, preview ${MAX_PLAY_SECONDS}s` : ""})` : "";
|
|
875
|
+
const catTag = (!activeCategory || activeCategory === "all") && f.category && f.category !== "other"
|
|
876
|
+
? `[${(CATEGORY_LABELS[f.category] || f.category).toUpperCase()}] ` : "";
|
|
877
|
+
const name = f.displayName || f.name;
|
|
878
|
+
const usedFor = assignedToMap[f.path];
|
|
879
|
+
return {
|
|
880
|
+
label: `${catTag}${name}${durStr}`,
|
|
881
|
+
usedTag: usedFor ? ` ← ${usedFor.join(", ")}` : null,
|
|
882
|
+
value: f.path,
|
|
883
|
+
_dur: dur,
|
|
884
|
+
};
|
|
885
|
+
});
|
|
886
|
+
|
|
887
|
+
const filteredFiles = filter
|
|
888
|
+
? durationFilter
|
|
889
|
+
? allFileItems.filter((i) => {
|
|
890
|
+
if (i._dur == null) return false;
|
|
891
|
+
const { op, val } = durationFilter;
|
|
892
|
+
if (op === "<") return i._dur < val;
|
|
893
|
+
if (op === ">") return i._dur > val;
|
|
894
|
+
if (op === "<=") return i._dur <= val;
|
|
895
|
+
if (op === ">=") return i._dur >= val;
|
|
896
|
+
return true;
|
|
897
|
+
})
|
|
898
|
+
: allFileItems.filter((i) => i.label.toLowerCase().includes(filterLower))
|
|
899
|
+
: allFileItems;
|
|
900
|
+
|
|
901
|
+
const fileItems = [
|
|
902
|
+
...filteredFiles,
|
|
903
|
+
...(!filter ? [{ label: "(skip this event)", value: "_skip" }] : []),
|
|
904
|
+
];
|
|
905
|
+
|
|
906
|
+
const catLabel = activeCategory && activeCategory !== "all"
|
|
907
|
+
? `${CATEGORY_ICONS[activeCategory] || ""} ${CATEGORY_LABELS[activeCategory] || activeCategory}`
|
|
908
|
+
: null;
|
|
909
|
+
|
|
910
|
+
return h(Box, { flexDirection: "column" },
|
|
911
|
+
headerBox,
|
|
912
|
+
catLabel
|
|
913
|
+
? h(Text, { bold: true, color: ACCENT, marginLeft: 4 }, catLabel)
|
|
914
|
+
: null,
|
|
915
|
+
h(Box, { marginLeft: 4 },
|
|
916
|
+
h(Text, { color: autoPreview ? "green" : "gray", bold: autoPreview },
|
|
917
|
+
autoPreview ? "♫ Auto-preview ON" : "♫ Auto-preview OFF"
|
|
918
|
+
),
|
|
919
|
+
h(Text, { dimColor: true }, " (p to toggle)"),
|
|
920
|
+
),
|
|
921
|
+
filter
|
|
922
|
+
? h(Box, { marginLeft: 4 },
|
|
923
|
+
h(Text, { color: "yellow" }, durationFilter ? "Duration: " : "Filter: "),
|
|
924
|
+
h(Text, { bold: true }, filter),
|
|
925
|
+
h(Text, { dimColor: true }, ` (${filteredFiles.length} match${filteredFiles.length !== 1 ? "es" : ""})`),
|
|
926
|
+
)
|
|
927
|
+
: categoryFiles.length > 15
|
|
928
|
+
? h(Text, { dimColor: true, marginLeft: 4 }, "Type to filter... (e.g. <10s, >5s)")
|
|
929
|
+
: null,
|
|
930
|
+
fileItems.length > 0
|
|
931
|
+
? h(Box, { marginLeft: 2 },
|
|
932
|
+
h(SelectInput, { indicatorComponent: Indicator, itemComponent: FileItem,
|
|
933
|
+
items: fileItems,
|
|
934
|
+
limit: 15,
|
|
935
|
+
onHighlight: (item) => {
|
|
936
|
+
setHighlightedFile(item.value);
|
|
937
|
+
},
|
|
938
|
+
onSelect: (item) => {
|
|
939
|
+
stopPlayback();
|
|
940
|
+
if (item.value === "_skip") {
|
|
941
|
+
advance(null, null);
|
|
942
|
+
} else {
|
|
943
|
+
onSelectSound(eventId, item.value);
|
|
944
|
+
advance(item.value, eventId);
|
|
945
|
+
}
|
|
946
|
+
},
|
|
947
|
+
}),
|
|
948
|
+
)
|
|
949
|
+
: h(Text, { color: "yellow", marginLeft: 4 }, "No matches."),
|
|
950
|
+
nowPlayingBar,
|
|
951
|
+
h(NavHint, { back: true, extra: "tab switch event" }),
|
|
952
|
+
);
|
|
953
|
+
};
|
|
954
|
+
|
|
955
|
+
// ── Helpers for Music Player ─────────────────────────────────────
|
|
956
|
+
const formatTime = (secs) => {
|
|
957
|
+
const m = Math.floor(secs / 60);
|
|
958
|
+
const s = Math.floor(secs % 60);
|
|
959
|
+
return `${m}:${s.toString().padStart(2, "0")}`;
|
|
960
|
+
};
|
|
961
|
+
|
|
962
|
+
// ── Screen: Music Mode ──────────────────────────────────────────
|
|
963
|
+
const MusicModeScreen = ({ onRandom, onPickGame, onBack }) => {
|
|
964
|
+
useInput((_, key) => { if (key.escape) onBack(); });
|
|
965
|
+
|
|
966
|
+
const items = [
|
|
967
|
+
{ label: "🎲 Shuffle all — play random songs from all cached games", value: "random" },
|
|
968
|
+
{ label: "🎮 Play songs from game — choose a game", value: "game" },
|
|
969
|
+
];
|
|
970
|
+
|
|
971
|
+
return h(Box, { flexDirection: "column" },
|
|
972
|
+
h(Text, { bold: true, marginLeft: 2 }, " 🎵 Music Player"),
|
|
973
|
+
h(Text, { dimColor: true, marginLeft: 2 }, " Play longer game tracks as background music"),
|
|
974
|
+
h(Box, { marginTop: 1, marginLeft: 2 },
|
|
975
|
+
h(SelectInput, { indicatorComponent: Indicator, itemComponent: Item, items,
|
|
976
|
+
onSelect: (item) => {
|
|
977
|
+
if (item.value === "random") onRandom();
|
|
978
|
+
else onPickGame();
|
|
979
|
+
},
|
|
980
|
+
}),
|
|
981
|
+
),
|
|
982
|
+
h(NavHint, { back: true }),
|
|
983
|
+
);
|
|
984
|
+
};
|
|
985
|
+
|
|
986
|
+
// ── Screen: Music Game Pick (scans all installed games) ─────────
|
|
987
|
+
const MusicGamePickScreen = ({ onNext, onExtract, onBack }) => {
|
|
988
|
+
const [games, setGames] = useState([]);
|
|
989
|
+
const [scanning, setScanning] = useState(true);
|
|
990
|
+
const [scanStatus, setScanStatus] = useState("Discovering game directories...");
|
|
991
|
+
|
|
992
|
+
useInput((_, key) => { if (key.escape) onBack(); });
|
|
993
|
+
|
|
994
|
+
useEffect(() => {
|
|
995
|
+
let cancelled = false;
|
|
996
|
+
getAvailableGames(
|
|
997
|
+
(progress) => {
|
|
998
|
+
if (cancelled) return;
|
|
999
|
+
if (progress.phase === "dirs") {
|
|
1000
|
+
setScanStatus(`Scanning ${progress.dirs.length} directories...`);
|
|
1001
|
+
} else if (progress.phase === "scanning") {
|
|
1002
|
+
setScanStatus(`Scanning: ${progress.game}`);
|
|
1003
|
+
}
|
|
1004
|
+
},
|
|
1005
|
+
(game) => {
|
|
1006
|
+
if (cancelled) return;
|
|
1007
|
+
if (!game.hasAudio && !game.canExtract) return; // skip games with no audio
|
|
1008
|
+
setGames((prev) => {
|
|
1009
|
+
if (prev.some((g) => g.name === game.name)) return prev;
|
|
1010
|
+
const next = [...prev, game];
|
|
1011
|
+
next.sort((a, b) => {
|
|
1012
|
+
if (a.hasAudio !== b.hasAudio) return a.hasAudio ? -1 : 1;
|
|
1013
|
+
if (a.canExtract !== b.canExtract) return a.canExtract ? -1 : 1;
|
|
1014
|
+
return a.name.localeCompare(b.name);
|
|
1015
|
+
});
|
|
1016
|
+
return next;
|
|
1017
|
+
});
|
|
1018
|
+
},
|
|
1019
|
+
).then(() => {
|
|
1020
|
+
if (!cancelled) setScanning(false);
|
|
1021
|
+
}).catch(() => {
|
|
1022
|
+
if (!cancelled) setScanning(false);
|
|
1023
|
+
});
|
|
1024
|
+
return () => { cancelled = true; };
|
|
1025
|
+
}, []);
|
|
1026
|
+
|
|
1027
|
+
if (scanning && games.length === 0) {
|
|
1028
|
+
return h(Box, { flexDirection: "column" },
|
|
1029
|
+
h(Box, { marginLeft: 2 },
|
|
1030
|
+
h(Text, { color: ACCENT }, h(Spinner, { type: "dots" })),
|
|
1031
|
+
h(Text, null, ` ${scanStatus}`),
|
|
1032
|
+
),
|
|
1033
|
+
);
|
|
1034
|
+
}
|
|
1035
|
+
|
|
1036
|
+
if (!scanning && games.length === 0) {
|
|
1037
|
+
return h(Box, { flexDirection: "column" },
|
|
1038
|
+
h(Text, { color: "yellow", marginLeft: 2 }, " No games with audio found."),
|
|
1039
|
+
h(NavHint, { back: true }),
|
|
1040
|
+
);
|
|
1041
|
+
}
|
|
1042
|
+
|
|
1043
|
+
const items = games.map((g) => {
|
|
1044
|
+
const info = g.hasAudio ? `${g.fileCount} audio` : g.canExtract ? `${g.packedAudioCount + (g.unityAudioCount || 0)} packed` : "";
|
|
1045
|
+
return { label: `${g.name}${info ? ` (${info})` : ""}`, value: g.name };
|
|
1046
|
+
});
|
|
1047
|
+
|
|
1048
|
+
return h(Box, { flexDirection: "column" },
|
|
1049
|
+
h(Text, { bold: true, marginLeft: 2 }, " Pick a game:"),
|
|
1050
|
+
scanning ? h(Box, { marginLeft: 2 },
|
|
1051
|
+
h(Text, { color: ACCENT }, h(Spinner, { type: "dots" })),
|
|
1052
|
+
h(Text, { dimColor: true }, ` ${scanStatus} (${games.length} games found)`),
|
|
1053
|
+
) : null,
|
|
1054
|
+
h(Box, { marginLeft: 2 },
|
|
1055
|
+
h(SelectInput, { indicatorComponent: Indicator, itemComponent: Item, items, limit: 15,
|
|
1056
|
+
onSelect: (item) => {
|
|
1057
|
+
const game = games.find((g) => g.name === item.value);
|
|
1058
|
+
if (game?.hasAudio) {
|
|
1059
|
+
onNext(game);
|
|
1060
|
+
} else {
|
|
1061
|
+
onExtract(game);
|
|
1062
|
+
}
|
|
1063
|
+
},
|
|
1064
|
+
}),
|
|
1065
|
+
),
|
|
1066
|
+
h(NavHint, { back: true }),
|
|
1067
|
+
);
|
|
1068
|
+
};
|
|
1069
|
+
|
|
1070
|
+
// ── Screen: Music Playing ───────────────────────────────────────
|
|
1071
|
+
const MusicPlayingScreen = ({ files, gameName, shuffle: initialShuffle, onBack }) => {
|
|
1072
|
+
const [track, setTrack] = useState(null); // current track { path, name, displayName, duration }
|
|
1073
|
+
const [loading, setLoading] = useState(true);
|
|
1074
|
+
const [scanProgress, setScanProgress] = useState({ done: 0, total: files.length, found: 0 });
|
|
1075
|
+
const [scanDone, setScanDone] = useState(false);
|
|
1076
|
+
const [playing, setPlaying] = useState(false);
|
|
1077
|
+
const [paused, setPaused] = useState(false);
|
|
1078
|
+
const [elapsed, setElapsed] = useState(0);
|
|
1079
|
+
const [pool, setPool] = useState([]);
|
|
1080
|
+
const cancelRef = useRef(null);
|
|
1081
|
+
const pauseRef = useRef(null);
|
|
1082
|
+
const resumeRef = useRef(null);
|
|
1083
|
+
const versionRef = useRef(0);
|
|
1084
|
+
const poolRef = useRef([]); // ever-growing pool of qualifying tracks
|
|
1085
|
+
|
|
1086
|
+
// Pick a random track from the pool (different from current)
|
|
1087
|
+
const pickRandom = useCallback((currentTrack) => {
|
|
1088
|
+
const p = poolRef.current;
|
|
1089
|
+
if (p.length === 0) return null;
|
|
1090
|
+
if (p.length === 1) return p[0];
|
|
1091
|
+
let pick;
|
|
1092
|
+
do { pick = p[Math.floor(Math.random() * p.length)]; } while (pick === currentTrack && p.length > 1);
|
|
1093
|
+
return pick;
|
|
1094
|
+
}, []);
|
|
1095
|
+
|
|
1096
|
+
// Scan files for duration, pick first random once found, keep scanning in background
|
|
1097
|
+
const startedRef = useRef(false);
|
|
1098
|
+
useEffect(() => {
|
|
1099
|
+
let cancelled = false;
|
|
1100
|
+
(async () => {
|
|
1101
|
+
const BATCH = 20;
|
|
1102
|
+
for (let i = 0; i < files.length; i += BATCH) {
|
|
1103
|
+
if (cancelled) return;
|
|
1104
|
+
const batch = files.slice(i, i + BATCH);
|
|
1105
|
+
const results = await Promise.all(batch.map(async (f) => {
|
|
1106
|
+
const dur = await getWavDuration(f.path);
|
|
1107
|
+
return { ...f, duration: dur };
|
|
1108
|
+
}));
|
|
1109
|
+
for (const r of results) {
|
|
1110
|
+
if (r.duration != null && r.duration >= 30 && r.duration <= 600) {
|
|
1111
|
+
poolRef.current.push(r);
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
const found = poolRef.current.length;
|
|
1115
|
+
setScanProgress({ done: Math.min(i + BATCH, files.length), total: files.length, found });
|
|
1116
|
+
setPool([...poolRef.current]);
|
|
1117
|
+
// Start playing the first time we find a qualifying track
|
|
1118
|
+
if (found >= 1 && !startedRef.current && !cancelled) {
|
|
1119
|
+
startedRef.current = true;
|
|
1120
|
+
setTrack(pickRandom(null));
|
|
1121
|
+
setLoading(false);
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
if (!cancelled) {
|
|
1125
|
+
setScanDone(true);
|
|
1126
|
+
setPool([...poolRef.current]);
|
|
1127
|
+
if (!startedRef.current) {
|
|
1128
|
+
startedRef.current = true;
|
|
1129
|
+
if (poolRef.current.length > 0) {
|
|
1130
|
+
setTrack(pickRandom(null));
|
|
1131
|
+
}
|
|
1132
|
+
setLoading(false);
|
|
1133
|
+
}
|
|
1134
|
+
}
|
|
1135
|
+
})();
|
|
1136
|
+
return () => { cancelled = true; };
|
|
1137
|
+
}, []);
|
|
1138
|
+
|
|
1139
|
+
// Play current track
|
|
1140
|
+
useEffect(() => {
|
|
1141
|
+
if (!track) return;
|
|
1142
|
+
|
|
1143
|
+
const myVersion = ++versionRef.current;
|
|
1144
|
+
const { promise, cancel, pause, resume } = playSoundWithCancel(track.path, { maxSeconds: 0 });
|
|
1145
|
+
cancelRef.current = cancel;
|
|
1146
|
+
pauseRef.current = pause;
|
|
1147
|
+
resumeRef.current = resume;
|
|
1148
|
+
setPlaying(true);
|
|
1149
|
+
setPaused(false);
|
|
1150
|
+
setElapsed(0);
|
|
1151
|
+
|
|
1152
|
+
promise.then(() => {
|
|
1153
|
+
if (versionRef.current === myVersion) {
|
|
1154
|
+
const next = pickRandom(track);
|
|
1155
|
+
if (next) setTrack(next);
|
|
1156
|
+
}
|
|
1157
|
+
}).catch(() => {});
|
|
1158
|
+
|
|
1159
|
+
return () => cancel();
|
|
1160
|
+
}, [track]);
|
|
1161
|
+
|
|
1162
|
+
// Elapsed timer
|
|
1163
|
+
useEffect(() => {
|
|
1164
|
+
if (!playing || paused) return;
|
|
1165
|
+
const interval = setInterval(() => setElapsed((e) => e + 1), 1000);
|
|
1166
|
+
return () => clearInterval(interval);
|
|
1167
|
+
}, [playing, paused]);
|
|
1168
|
+
|
|
1169
|
+
// Controls
|
|
1170
|
+
useInput((input, key) => {
|
|
1171
|
+
if (key.escape) {
|
|
1172
|
+
if (cancelRef.current) cancelRef.current();
|
|
1173
|
+
onBack();
|
|
1174
|
+
} else if (input === "n") {
|
|
1175
|
+
versionRef.current++;
|
|
1176
|
+
if (cancelRef.current) cancelRef.current();
|
|
1177
|
+
const next = pickRandom(track);
|
|
1178
|
+
if (next) setTrack(next);
|
|
1179
|
+
} else if (input === " ") {
|
|
1180
|
+
if (paused) {
|
|
1181
|
+
if (resumeRef.current) resumeRef.current();
|
|
1182
|
+
setPaused(false);
|
|
1183
|
+
} else {
|
|
1184
|
+
if (pauseRef.current) pauseRef.current();
|
|
1185
|
+
setPaused(true);
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
});
|
|
1189
|
+
|
|
1190
|
+
// Loading state
|
|
1191
|
+
if (loading) {
|
|
1192
|
+
return h(Box, { flexDirection: "column" },
|
|
1193
|
+
h(Box, { marginLeft: 2, flexDirection: "column", borderStyle: "round", borderColor: ACCENT, paddingX: 2 },
|
|
1194
|
+
h(Text, { bold: true, color: ACCENT }, `🎵 ${gameName || "Music Player"}`),
|
|
1195
|
+
h(Box, { marginTop: 1 },
|
|
1196
|
+
h(Text, { color: ACCENT }, h(Spinner, { type: "dots" })),
|
|
1197
|
+
h(Text, null, ` Scanning for music tracks... ${scanProgress.found} found (${scanProgress.done}/${scanProgress.total})`),
|
|
1198
|
+
),
|
|
1199
|
+
),
|
|
1200
|
+
h(NavHint, { back: true }),
|
|
1201
|
+
);
|
|
1202
|
+
}
|
|
1203
|
+
|
|
1204
|
+
if (!track) {
|
|
1205
|
+
return h(Box, { flexDirection: "column" },
|
|
1206
|
+
h(Text, { color: "yellow", marginLeft: 2 }, " No tracks between 30s–10min found."),
|
|
1207
|
+
h(Text, { dimColor: true, marginLeft: 2 }, " Try a different game or source."),
|
|
1208
|
+
h(NavHint, { back: true }),
|
|
1209
|
+
);
|
|
1210
|
+
}
|
|
1211
|
+
|
|
1212
|
+
const trackName = track.displayName || track.name || basename(track.path);
|
|
1213
|
+
|
|
1214
|
+
// Build playlist items — highlight currently playing track
|
|
1215
|
+
const playlistItems = pool.map((t) => {
|
|
1216
|
+
const name = t.displayName || t.name || basename(t.path);
|
|
1217
|
+
const durStr = t.duration ? ` (${formatTime(t.duration)})` : "";
|
|
1218
|
+
const isPlaying = t.path === track.path;
|
|
1219
|
+
return {
|
|
1220
|
+
label: `${isPlaying ? "▶ " : " "}${name}${durStr}`,
|
|
1221
|
+
value: t.path,
|
|
1222
|
+
};
|
|
1223
|
+
});
|
|
1224
|
+
|
|
1225
|
+
return h(Box, { flexDirection: "column" },
|
|
1226
|
+
h(Box, { marginLeft: 2, flexDirection: "column", borderStyle: "round", borderColor: paused ? "yellow" : "green", paddingX: 2 },
|
|
1227
|
+
h(Text, { bold: true, color: paused ? "yellow" : "green" }, `🎵 ${gameName || "Music Player"}`),
|
|
1228
|
+
h(Box, { marginTop: 1 },
|
|
1229
|
+
h(Text, { color: paused ? "yellow" : "green", bold: true },
|
|
1230
|
+
paused ? "⏸ " : "▶ ",
|
|
1231
|
+
),
|
|
1232
|
+
h(Text, { bold: true }, trackName),
|
|
1233
|
+
),
|
|
1234
|
+
track.gameName
|
|
1235
|
+
? h(Text, { dimColor: true }, ` ${track.gameName}`)
|
|
1236
|
+
: null,
|
|
1237
|
+
h(Text, { dimColor: true },
|
|
1238
|
+
` ${formatTime(elapsed)} / ${formatTime(track.duration || 0)}`,
|
|
1239
|
+
),
|
|
1240
|
+
),
|
|
1241
|
+
h(Box, { marginTop: 1, marginLeft: 2 },
|
|
1242
|
+
scanDone
|
|
1243
|
+
? h(Text, { dimColor: true }, ` ${pool.length} tracks`)
|
|
1244
|
+
: h(Box, null,
|
|
1245
|
+
h(Text, { color: ACCENT }, h(Spinner, { type: "dots" })),
|
|
1246
|
+
h(Text, { dimColor: true }, ` ${pool.length} tracks (${scanProgress.done}/${scanProgress.total} scanned)`),
|
|
1247
|
+
),
|
|
1248
|
+
),
|
|
1249
|
+
h(Box, { marginLeft: 2 },
|
|
1250
|
+
h(SelectInput, { indicatorComponent: Indicator, itemComponent: Item, items: playlistItems, limit: 12,
|
|
1251
|
+
onSelect: (item) => {
|
|
1252
|
+
const picked = poolRef.current.find((t) => t.path === item.value);
|
|
1253
|
+
if (picked) {
|
|
1254
|
+
versionRef.current++;
|
|
1255
|
+
if (cancelRef.current) cancelRef.current();
|
|
1256
|
+
setTrack(picked);
|
|
1257
|
+
}
|
|
1258
|
+
},
|
|
1259
|
+
}),
|
|
1260
|
+
),
|
|
1261
|
+
h(Box, { marginLeft: 4 },
|
|
1262
|
+
h(Text, { dimColor: true }, "n random space pause esc back"),
|
|
1263
|
+
),
|
|
1264
|
+
);
|
|
1265
|
+
};
|
|
1266
|
+
|
|
1267
|
+
// ── Screen: Extracting ──────────────────────────────────────────
|
|
1268
|
+
const ExtractingScreen = ({ game, onDone, onBack }) => {
|
|
1269
|
+
const [status, setStatus] = useState("Checking cache...");
|
|
1270
|
+
const [extracted, setExtracted] = useState(0);
|
|
1271
|
+
|
|
1272
|
+
useInput((_, key) => { if (key.escape) onBack(); });
|
|
1273
|
+
|
|
1274
|
+
useEffect(() => {
|
|
1275
|
+
let cancelled = false;
|
|
1276
|
+
|
|
1277
|
+
(async () => {
|
|
1278
|
+
try {
|
|
1279
|
+
// Check cache first
|
|
1280
|
+
const cached = await getCachedExtraction(game.name);
|
|
1281
|
+
if (cached && cached.files.length > 0) {
|
|
1282
|
+
setStatus(`Found ${cached.files.length} cached sounds`);
|
|
1283
|
+
if (!cancelled) {
|
|
1284
|
+
onDone({
|
|
1285
|
+
files: cached.files.map((f) => ({
|
|
1286
|
+
path: f.path,
|
|
1287
|
+
name: f.name,
|
|
1288
|
+
displayName: f.displayName,
|
|
1289
|
+
category: f.category,
|
|
1290
|
+
dir: dirname(f.path),
|
|
1291
|
+
})),
|
|
1292
|
+
categories: cached.categories,
|
|
1293
|
+
fromCache: true,
|
|
1294
|
+
});
|
|
1295
|
+
}
|
|
1296
|
+
return;
|
|
1297
|
+
}
|
|
1298
|
+
|
|
1299
|
+
const outputDir = join(tmpdir(), "klaudio-extract", game.name.replace(/[^a-zA-Z0-9]/g, "_"));
|
|
1300
|
+
const allOutputs = [];
|
|
1301
|
+
|
|
1302
|
+
// Unity .resource files — extract FSB5 banks directly (no vgmstream needed for PCM16)
|
|
1303
|
+
const fsbFiles = []; // Vorbis .fsb files that need vgmstream conversion
|
|
1304
|
+
if (game.unityResources && game.unityResources.length > 0) {
|
|
1305
|
+
setStatus(`Extracting Unity audio from ${game.unityResources.length} resource file(s)...`);
|
|
1306
|
+
for (const resPath of game.unityResources) {
|
|
1307
|
+
if (cancelled) return;
|
|
1308
|
+
setStatus(`Extracting: ${basename(resPath)}`);
|
|
1309
|
+
try {
|
|
1310
|
+
const extracted = await extractUnityResource(resPath, outputDir);
|
|
1311
|
+
for (const f of extracted) {
|
|
1312
|
+
if (f.path.endsWith(".wav")) {
|
|
1313
|
+
allOutputs.push(f.path);
|
|
1314
|
+
} else if (f.path.endsWith(".fsb")) {
|
|
1315
|
+
fsbFiles.push({ path: f.path, name: f.name });
|
|
1316
|
+
}
|
|
1317
|
+
}
|
|
1318
|
+
setExtracted(allOutputs.length);
|
|
1319
|
+
} catch { /* skip */ }
|
|
1320
|
+
}
|
|
1321
|
+
}
|
|
1322
|
+
|
|
1323
|
+
// Scan for packed audio files (Wwise/FMOD/BUN)
|
|
1324
|
+
let packedFiles = [];
|
|
1325
|
+
if (allOutputs.length === 0 || !game.unityResources?.length) {
|
|
1326
|
+
setStatus(`Scanning ${game.name} for packed audio...`);
|
|
1327
|
+
packedFiles = await findPackedAudioFiles(game.path, 30);
|
|
1328
|
+
}
|
|
1329
|
+
|
|
1330
|
+
// Extract BUN files natively (SCUMM engine audio)
|
|
1331
|
+
const bunFiles = packedFiles.filter((f) => f.name.toLowerCase().endsWith(".bun"));
|
|
1332
|
+
const nonBunFiles = packedFiles.filter((f) => !f.name.toLowerCase().endsWith(".bun"));
|
|
1333
|
+
|
|
1334
|
+
for (const file of bunFiles) {
|
|
1335
|
+
if (cancelled) return;
|
|
1336
|
+
setStatus(`Extracting SCUMM audio: ${file.name}`);
|
|
1337
|
+
try {
|
|
1338
|
+
const bunOutputs = await extractBunFile(file.path, outputDir, (msg) => {
|
|
1339
|
+
if (!cancelled) setStatus(msg);
|
|
1340
|
+
});
|
|
1341
|
+
allOutputs.push(...bunOutputs);
|
|
1342
|
+
setExtracted(allOutputs.length);
|
|
1343
|
+
} catch { /* skip */ }
|
|
1344
|
+
}
|
|
1345
|
+
|
|
1346
|
+
// Convert extracted .fsb Vorbis files via vgmstream, or handle non-BUN packed audio
|
|
1347
|
+
const needsVgmstream = fsbFiles.length > 0 || nonBunFiles.length > 0;
|
|
1348
|
+
if (needsVgmstream) {
|
|
1349
|
+
// Get vgmstream-cli (downloads if needed)
|
|
1350
|
+
setStatus("Getting vgmstream-cli...");
|
|
1351
|
+
const vgmstream = await getVgmstreamPath((msg) => {
|
|
1352
|
+
if (!cancelled) setStatus(msg);
|
|
1353
|
+
});
|
|
1354
|
+
|
|
1355
|
+
// Convert Unity-extracted .fsb files
|
|
1356
|
+
for (const fsb of fsbFiles) {
|
|
1357
|
+
if (cancelled) return;
|
|
1358
|
+
setStatus(`Converting: ${fsb.name}`);
|
|
1359
|
+
try {
|
|
1360
|
+
const outputs = await extractToWav(fsb.path, outputDir, vgmstream);
|
|
1361
|
+
allOutputs.push(...outputs);
|
|
1362
|
+
setExtracted(allOutputs.length);
|
|
1363
|
+
} catch { /* skip */ }
|
|
1364
|
+
}
|
|
1365
|
+
|
|
1366
|
+
// Convert non-BUN packed audio via vgmstream
|
|
1367
|
+
for (const file of nonBunFiles) {
|
|
1368
|
+
if (cancelled) return;
|
|
1369
|
+
setStatus(`Extracting: ${file.name}`);
|
|
1370
|
+
try {
|
|
1371
|
+
const outputs = await extractToWav(file.path, outputDir, vgmstream);
|
|
1372
|
+
allOutputs.push(...outputs);
|
|
1373
|
+
setExtracted(allOutputs.length);
|
|
1374
|
+
} catch { /* skip */ }
|
|
1375
|
+
}
|
|
1376
|
+
}
|
|
1377
|
+
|
|
1378
|
+
if (allOutputs.length === 0 && fsbFiles.length === 0 && packedFiles.length === 0) {
|
|
1379
|
+
if (!cancelled) onDone({ files: [], error: "No extractable audio files found" });
|
|
1380
|
+
return;
|
|
1381
|
+
}
|
|
1382
|
+
|
|
1383
|
+
if (!cancelled) {
|
|
1384
|
+
// Cache the results with category metadata
|
|
1385
|
+
const rawFiles = allOutputs.map((p) => ({ path: p, name: basename(p) }));
|
|
1386
|
+
setStatus("Caching extracted sounds...");
|
|
1387
|
+
const manifest = await cacheExtraction(game.name, rawFiles, game.path);
|
|
1388
|
+
|
|
1389
|
+
onDone({
|
|
1390
|
+
files: manifest.files.map((f) => ({
|
|
1391
|
+
path: f.path,
|
|
1392
|
+
name: f.name,
|
|
1393
|
+
displayName: f.displayName,
|
|
1394
|
+
category: f.category,
|
|
1395
|
+
dir: dirname(f.path),
|
|
1396
|
+
})),
|
|
1397
|
+
categories: manifest.categories,
|
|
1398
|
+
});
|
|
1399
|
+
}
|
|
1400
|
+
} catch (err) {
|
|
1401
|
+
if (!cancelled) onDone({ files: [], error: err.message });
|
|
1402
|
+
}
|
|
1403
|
+
})();
|
|
1404
|
+
|
|
1405
|
+
return () => { cancelled = true; };
|
|
1406
|
+
}, []);
|
|
1407
|
+
|
|
1408
|
+
return h(Box, { flexDirection: "column" },
|
|
1409
|
+
h(Box, { marginLeft: 2, flexDirection: "column", borderStyle: "round", borderColor: ACCENT, paddingX: 2 },
|
|
1410
|
+
h(Text, { bold: true, color: ACCENT }, `Extracting audio from ${game.name}`),
|
|
1411
|
+
h(Box, { marginTop: 1 },
|
|
1412
|
+
h(Text, { color: ACCENT }, h(Spinner, { type: "dots" })),
|
|
1413
|
+
h(Text, null, ` ${status}`),
|
|
1414
|
+
),
|
|
1415
|
+
extracted > 0
|
|
1416
|
+
? h(Text, { color: "green" }, ` ${extracted} sound(s) extracted so far`)
|
|
1417
|
+
: null,
|
|
1418
|
+
),
|
|
1419
|
+
h(NavHint, { back: true }),
|
|
1420
|
+
);
|
|
1421
|
+
};
|
|
1422
|
+
|
|
1423
|
+
// ── Screen: Confirm ─────────────────────────────────────────────
|
|
1424
|
+
const ConfirmScreen = ({ scope, sounds, tts, voice, hasKokoro, onToggleTts, onCycleVoice, onConfirm, onBack }) => {
|
|
1425
|
+
useInput((input, key) => {
|
|
1426
|
+
if (key.escape) onBack();
|
|
1427
|
+
else if (input === "t") onToggleTts();
|
|
1428
|
+
else if (input === "v" && tts && hasKokoro) onCycleVoice();
|
|
1429
|
+
});
|
|
1430
|
+
|
|
1431
|
+
const items = [
|
|
1432
|
+
{ label: "✓ Yes, install!", value: "yes" },
|
|
1433
|
+
{ label: "✗ No, go back", value: "no" },
|
|
1434
|
+
];
|
|
1435
|
+
|
|
1436
|
+
const soundEntries = Object.entries(sounds).filter(([_, path]) => path);
|
|
1437
|
+
const voiceInfo = hasKokoro ? KOKORO_VOICES.find((v) => v.id === voice) : null;
|
|
1438
|
+
|
|
1439
|
+
return h(Box, { flexDirection: "column" },
|
|
1440
|
+
h(Text, { bold: true, marginLeft: 2 }, " Ready to install:"),
|
|
1441
|
+
h(Box, { marginTop: 1, flexDirection: "column" },
|
|
1442
|
+
h(Text, { marginLeft: 4 }, `Scope: ${scope === "global" ? "Global (Claude Code + Copilot)" : "This project (Claude Code + Copilot)"}`),
|
|
1443
|
+
...soundEntries.map(([eid, path]) =>
|
|
1444
|
+
h(Text, { key: eid, marginLeft: 4 },
|
|
1445
|
+
`${EVENTS[eid].name} → ${shortName(path)}`
|
|
1446
|
+
)
|
|
1447
|
+
),
|
|
1448
|
+
h(Box, { marginLeft: 4, marginTop: 1 },
|
|
1449
|
+
h(Text, { color: tts ? "green" : "gray" },
|
|
1450
|
+
tts ? "🗣 Voice summary: ON" : "🗣 Voice summary: OFF",
|
|
1451
|
+
),
|
|
1452
|
+
h(Text, { dimColor: true }, " (t to toggle — reads a short summary when tasks complete)"),
|
|
1453
|
+
),
|
|
1454
|
+
tts && voiceInfo ? h(Box, { marginLeft: 4 },
|
|
1455
|
+
h(Text, { color: ACCENT },
|
|
1456
|
+
`🎙 Voice: ${voiceInfo.name} (${voiceInfo.gender}, ${voiceInfo.accent})`,
|
|
1457
|
+
),
|
|
1458
|
+
h(Text, { dimColor: true }, " (v to change voice)"),
|
|
1459
|
+
) : null,
|
|
1460
|
+
),
|
|
1461
|
+
h(Box, { marginTop: 1, marginLeft: 2 },
|
|
1462
|
+
h(SelectInput, { indicatorComponent: Indicator, itemComponent: Item, items, onSelect: (item) => {
|
|
1463
|
+
if (item.value === "yes") onConfirm();
|
|
1464
|
+
else onBack();
|
|
1465
|
+
}}),
|
|
1466
|
+
),
|
|
1467
|
+
h(NavHint, { back: true }),
|
|
1468
|
+
);
|
|
1469
|
+
};
|
|
1470
|
+
|
|
1471
|
+
// ── Screen: Installing ──────────────────────────────────────────
|
|
1472
|
+
const InstallingScreen = ({ scope, sounds, tts, voice, onDone }) => {
|
|
1473
|
+
useEffect(() => {
|
|
1474
|
+
const validSounds = {};
|
|
1475
|
+
for (const [eventId, path] of Object.entries(sounds)) {
|
|
1476
|
+
if (path) validSounds[eventId] = path;
|
|
1477
|
+
}
|
|
1478
|
+
install({ scope, sounds: validSounds, tts, voice }).then(onDone).catch((err) => {
|
|
1479
|
+
onDone({ error: err.message });
|
|
1480
|
+
});
|
|
1481
|
+
}, []);
|
|
1482
|
+
|
|
1483
|
+
return h(Box, { marginLeft: 2 },
|
|
1484
|
+
h(Text, { color: ACCENT }, h(Spinner, { type: "dots" })),
|
|
1485
|
+
h(Text, null, " Installing sounds..."),
|
|
1486
|
+
);
|
|
1487
|
+
};
|
|
1488
|
+
|
|
1489
|
+
// ── Screen: Done ────────────────────────────────────────────────
|
|
1490
|
+
const DoneScreen = ({ result }) => {
|
|
1491
|
+
const { exit } = useApp();
|
|
1492
|
+
|
|
1493
|
+
useEffect(() => {
|
|
1494
|
+
// Play the "stop" sound as a demo if it was installed
|
|
1495
|
+
if (result.installedSounds?.stop) {
|
|
1496
|
+
playSoundWithCancel(result.installedSounds.stop).promise.catch(() => {});
|
|
1497
|
+
}
|
|
1498
|
+
const timer = setTimeout(() => exit(), 1500);
|
|
1499
|
+
return () => clearTimeout(timer);
|
|
1500
|
+
}, []);
|
|
1501
|
+
|
|
1502
|
+
if (result.error) {
|
|
1503
|
+
return h(Box, { flexDirection: "column", marginLeft: 2 },
|
|
1504
|
+
h(Text, { color: "red", bold: true }, " ✗ Installation failed:"),
|
|
1505
|
+
h(Text, { color: "red" }, ` ${result.error}`),
|
|
1506
|
+
);
|
|
1507
|
+
}
|
|
1508
|
+
|
|
1509
|
+
return h(Box, { flexDirection: "column", marginLeft: 2 },
|
|
1510
|
+
h(Text, { color: "green", bold: true }, " ✓ Sounds installed!"),
|
|
1511
|
+
h(Box, { marginTop: 1, flexDirection: "column" },
|
|
1512
|
+
h(Text, null, ` Sound files: ${result.soundsDir}`),
|
|
1513
|
+
h(Text, null, ` Config: ${result.settingsFile}`),
|
|
1514
|
+
),
|
|
1515
|
+
h(Box, { marginTop: 1, flexDirection: "column" },
|
|
1516
|
+
h(Text, null, " Your Claude Code sessions will now play sounds for:"),
|
|
1517
|
+
...Object.keys(result.installedSounds).map((eventId) =>
|
|
1518
|
+
h(Text, { key: eventId, color: "green" }, ` • ${EVENTS[eventId].name}`)
|
|
1519
|
+
),
|
|
1520
|
+
),
|
|
1521
|
+
h(Box, { marginTop: 1 },
|
|
1522
|
+
h(Text, { dimColor: true }, " To remove: npx klaudio --uninstall"),
|
|
1523
|
+
),
|
|
1524
|
+
);
|
|
1525
|
+
};
|
|
1526
|
+
|
|
1527
|
+
// ── Uninstall App ───────────────────────────────────────────────
|
|
1528
|
+
const UninstallApp = () => {
|
|
1529
|
+
const { exit } = useApp();
|
|
1530
|
+
const [phase, setPhase] = useState("scope"); // scope | working | done | notfound
|
|
1531
|
+
const [scope, setScope] = useState(null);
|
|
1532
|
+
|
|
1533
|
+
useEffect(() => {
|
|
1534
|
+
if (phase === "working" && scope) {
|
|
1535
|
+
uninstall(scope).then((ok) => {
|
|
1536
|
+
setPhase(ok ? "done" : "notfound");
|
|
1537
|
+
setTimeout(() => exit(), 500);
|
|
1538
|
+
});
|
|
1539
|
+
}
|
|
1540
|
+
}, [phase, scope]);
|
|
1541
|
+
|
|
1542
|
+
if (phase === "scope") {
|
|
1543
|
+
return h(Box, { flexDirection: "column" },
|
|
1544
|
+
h(Header, null),
|
|
1545
|
+
h(ScopeScreen, {
|
|
1546
|
+
onNext: (s) => { setScope(s); setPhase("working"); },
|
|
1547
|
+
}),
|
|
1548
|
+
);
|
|
1549
|
+
}
|
|
1550
|
+
|
|
1551
|
+
if (phase === "working") {
|
|
1552
|
+
return h(Box, { flexDirection: "column" },
|
|
1553
|
+
h(Header, null),
|
|
1554
|
+
h(Box, { marginLeft: 2 },
|
|
1555
|
+
h(Text, { color: ACCENT }, h(Spinner, { type: "dots" })),
|
|
1556
|
+
h(Text, null, " Removing sounds..."),
|
|
1557
|
+
),
|
|
1558
|
+
);
|
|
1559
|
+
}
|
|
1560
|
+
|
|
1561
|
+
if (phase === "done") {
|
|
1562
|
+
return h(Box, { flexDirection: "column" },
|
|
1563
|
+
h(Header, null),
|
|
1564
|
+
h(Text, { color: "green", marginLeft: 2 }, " ✓ Klaudio hooks removed."),
|
|
1565
|
+
);
|
|
1566
|
+
}
|
|
1567
|
+
|
|
1568
|
+
return h(Box, { flexDirection: "column" },
|
|
1569
|
+
h(Header, null),
|
|
1570
|
+
h(Text, { color: "yellow", marginLeft: 2 }, " No Klaudio configuration found."),
|
|
1571
|
+
);
|
|
1572
|
+
};
|
|
1573
|
+
|
|
1574
|
+
// ── Main Install App ────────────────────────────────────────────
|
|
1575
|
+
const InstallApp = () => {
|
|
1576
|
+
const [screen, setScreen] = useState(SCREEN.SCOPE);
|
|
1577
|
+
const [scope, setScope] = useState(null);
|
|
1578
|
+
const [presetId, setPresetId] = useState(null);
|
|
1579
|
+
const [sounds, setSounds] = useState({});
|
|
1580
|
+
const [selectedGame, setSelectedGame] = useState(null);
|
|
1581
|
+
const [installResult, setInstallResult] = useState(null);
|
|
1582
|
+
const [tts, setTts] = useState(true);
|
|
1583
|
+
const [voice, setVoice] = useState(KOKORO_DEFAULT_VOICE);
|
|
1584
|
+
const [hasKokoro, setHasKokoro] = useState(false);
|
|
1585
|
+
const [outdatedReasons, setOutdatedReasons] = useState([]);
|
|
1586
|
+
const [musicFiles, setMusicFiles] = useState([]);
|
|
1587
|
+
const [musicGameName, setMusicGameName] = useState(null);
|
|
1588
|
+
const [musicShuffle, setMusicShuffle] = useState(false);
|
|
1589
|
+
|
|
1590
|
+
useEffect(() => {
|
|
1591
|
+
isKokoroAvailable().then(setHasKokoro).catch(() => {});
|
|
1592
|
+
// Check both scopes for outdated hooks on startup
|
|
1593
|
+
Promise.all([
|
|
1594
|
+
checkHooksOutdated("global"),
|
|
1595
|
+
checkHooksOutdated("project"),
|
|
1596
|
+
]).then(([g, p]) => {
|
|
1597
|
+
const combined = [...new Set([...g, ...p])];
|
|
1598
|
+
setOutdatedReasons(combined);
|
|
1599
|
+
}).catch(() => {});
|
|
1600
|
+
// Also pre-load existing sounds from global (most common)
|
|
1601
|
+
getExistingSounds("global").then((existing) => {
|
|
1602
|
+
if (Object.keys(existing).length > 0) setSounds(existing);
|
|
1603
|
+
}).catch(() => {});
|
|
1604
|
+
}, []);
|
|
1605
|
+
|
|
1606
|
+
const initSoundsFromPreset = useCallback((pid) => {
|
|
1607
|
+
const preset = PRESETS[pid];
|
|
1608
|
+
if (preset) setSounds({ ...preset.sounds });
|
|
1609
|
+
}, []);
|
|
1610
|
+
|
|
1611
|
+
const content = (() => {
|
|
1612
|
+
switch (screen) {
|
|
1613
|
+
case SCREEN.SCOPE:
|
|
1614
|
+
return h(ScopeScreen, {
|
|
1615
|
+
tts,
|
|
1616
|
+
voice,
|
|
1617
|
+
hasKokoro,
|
|
1618
|
+
outdatedReasons,
|
|
1619
|
+
onToggleTts: () => setTts((v) => !v),
|
|
1620
|
+
onCycleVoice: () => setVoice((v) => {
|
|
1621
|
+
const idx = KOKORO_VOICES.findIndex((x) => x.id === v);
|
|
1622
|
+
return KOKORO_VOICES[(idx + 1) % KOKORO_VOICES.length].id;
|
|
1623
|
+
}),
|
|
1624
|
+
onNext: (s) => {
|
|
1625
|
+
setScope(s);
|
|
1626
|
+
// Refresh sounds/outdated for the selected scope
|
|
1627
|
+
getExistingSounds(s).then((existing) => {
|
|
1628
|
+
if (Object.keys(existing).length > 0) setSounds(existing);
|
|
1629
|
+
});
|
|
1630
|
+
checkHooksOutdated(s).then(setOutdatedReasons).catch(() => {});
|
|
1631
|
+
setScreen(SCREEN.PRESET);
|
|
1632
|
+
},
|
|
1633
|
+
onUpdate: () => {
|
|
1634
|
+
// Quick-apply: use global scope with existing sounds, skip to install
|
|
1635
|
+
setScope("global");
|
|
1636
|
+
setScreen(SCREEN.INSTALLING);
|
|
1637
|
+
},
|
|
1638
|
+
onMusic: () => setScreen(SCREEN.MUSIC_MODE),
|
|
1639
|
+
});
|
|
1640
|
+
|
|
1641
|
+
case SCREEN.PRESET:
|
|
1642
|
+
return h(PresetScreen, {
|
|
1643
|
+
existingSounds: sounds,
|
|
1644
|
+
outdatedReasons,
|
|
1645
|
+
onReapply: () => setScreen(SCREEN.CONFIRM),
|
|
1646
|
+
onNext: (id) => {
|
|
1647
|
+
if (id === "_music") {
|
|
1648
|
+
setScreen(SCREEN.MUSIC_MODE);
|
|
1649
|
+
} else if (id === "_system") {
|
|
1650
|
+
getSystemSounds().then((files) => {
|
|
1651
|
+
const catFiles = categorizeLooseFiles(files);
|
|
1652
|
+
setSelectedGame({ name: "System Sounds", path: "", files: catFiles, fileCount: catFiles.length, hasAudio: catFiles.length > 0 });
|
|
1653
|
+
setScreen(SCREEN.GAME_SOUNDS);
|
|
1654
|
+
});
|
|
1655
|
+
} else if (id === "_scan") {
|
|
1656
|
+
setScreen(SCREEN.GAME_PICK);
|
|
1657
|
+
} else if (id === "_custom") {
|
|
1658
|
+
const firstPreset = Object.keys(PRESETS)[0];
|
|
1659
|
+
setPresetId(firstPreset);
|
|
1660
|
+
initSoundsFromPreset(firstPreset);
|
|
1661
|
+
setScreen(SCREEN.PREVIEW);
|
|
1662
|
+
} else {
|
|
1663
|
+
setPresetId(id);
|
|
1664
|
+
initSoundsFromPreset(id);
|
|
1665
|
+
if (KOKORO_PRESET_VOICES[id]) setVoice(KOKORO_PRESET_VOICES[id]);
|
|
1666
|
+
setScreen(SCREEN.PREVIEW);
|
|
1667
|
+
}
|
|
1668
|
+
},
|
|
1669
|
+
onBack: () => setScreen(SCREEN.SCOPE),
|
|
1670
|
+
});
|
|
1671
|
+
|
|
1672
|
+
case SCREEN.PREVIEW:
|
|
1673
|
+
return h(PreviewScreen, {
|
|
1674
|
+
presetId,
|
|
1675
|
+
sounds,
|
|
1676
|
+
onAccept: (finalSounds) => {
|
|
1677
|
+
setSounds(finalSounds);
|
|
1678
|
+
setScreen(SCREEN.CONFIRM);
|
|
1679
|
+
},
|
|
1680
|
+
onBack: () => setScreen(SCREEN.PRESET),
|
|
1681
|
+
onUpdateSound: (eventId, path) => {
|
|
1682
|
+
setSounds((prev) => {
|
|
1683
|
+
const next = { ...prev };
|
|
1684
|
+
if (path === null) delete next[eventId];
|
|
1685
|
+
else next[eventId] = path;
|
|
1686
|
+
return next;
|
|
1687
|
+
});
|
|
1688
|
+
},
|
|
1689
|
+
});
|
|
1690
|
+
|
|
1691
|
+
case SCREEN.GAME_PICK:
|
|
1692
|
+
return h(GamePickScreen, {
|
|
1693
|
+
onNext: (gameName, gamesList) => {
|
|
1694
|
+
const game = gamesList.find((g) => g.name === gameName);
|
|
1695
|
+
const catFiles = categorizeLooseFiles(game.files);
|
|
1696
|
+
setSelectedGame({ ...game, files: catFiles });
|
|
1697
|
+
setScreen(SCREEN.GAME_SOUNDS);
|
|
1698
|
+
},
|
|
1699
|
+
onExtract: (gameName, gamesList) => {
|
|
1700
|
+
const game = gamesList.find((g) => g.name === gameName);
|
|
1701
|
+
setSelectedGame(game);
|
|
1702
|
+
setScreen(SCREEN.EXTRACTING);
|
|
1703
|
+
},
|
|
1704
|
+
onBack: () => setScreen(SCREEN.PRESET),
|
|
1705
|
+
});
|
|
1706
|
+
|
|
1707
|
+
case SCREEN.GAME_SOUNDS:
|
|
1708
|
+
return h(GameSoundsScreen, {
|
|
1709
|
+
game: selectedGame,
|
|
1710
|
+
sounds,
|
|
1711
|
+
onSelectSound: (eventId, path) => {
|
|
1712
|
+
setSounds((prev) => ({ ...prev, [eventId]: path }));
|
|
1713
|
+
},
|
|
1714
|
+
onDone: () => {
|
|
1715
|
+
setScreen(SCREEN.CONFIRM);
|
|
1716
|
+
},
|
|
1717
|
+
onBack: () => setScreen(SCREEN.GAME_PICK),
|
|
1718
|
+
});
|
|
1719
|
+
|
|
1720
|
+
case SCREEN.EXTRACTING:
|
|
1721
|
+
return h(ExtractingScreen, {
|
|
1722
|
+
game: selectedGame,
|
|
1723
|
+
onDone: (result) => {
|
|
1724
|
+
if (result.error || result.files.length === 0) {
|
|
1725
|
+
// Go back to game pick — extraction failed
|
|
1726
|
+
setScreen(SCREEN.GAME_PICK);
|
|
1727
|
+
} else {
|
|
1728
|
+
// Update the selected game with extracted files and go to sound picker
|
|
1729
|
+
setSelectedGame({
|
|
1730
|
+
...selectedGame,
|
|
1731
|
+
files: result.files,
|
|
1732
|
+
fileCount: result.files.length,
|
|
1733
|
+
hasAudio: true,
|
|
1734
|
+
});
|
|
1735
|
+
setScreen(SCREEN.GAME_SOUNDS);
|
|
1736
|
+
}
|
|
1737
|
+
},
|
|
1738
|
+
onBack: () => setScreen(SCREEN.GAME_PICK),
|
|
1739
|
+
});
|
|
1740
|
+
|
|
1741
|
+
case SCREEN.CONFIRM:
|
|
1742
|
+
return h(ConfirmScreen, {
|
|
1743
|
+
scope,
|
|
1744
|
+
sounds,
|
|
1745
|
+
tts,
|
|
1746
|
+
voice,
|
|
1747
|
+
hasKokoro,
|
|
1748
|
+
onToggleTts: () => setTts((v) => !v),
|
|
1749
|
+
onCycleVoice: () => setVoice((v) => {
|
|
1750
|
+
const idx = KOKORO_VOICES.findIndex((x) => x.id === v);
|
|
1751
|
+
return KOKORO_VOICES[(idx + 1) % KOKORO_VOICES.length].id;
|
|
1752
|
+
}),
|
|
1753
|
+
onConfirm: () => setScreen(SCREEN.INSTALLING),
|
|
1754
|
+
onBack: () => {
|
|
1755
|
+
if (selectedGame) setScreen(SCREEN.GAME_SOUNDS);
|
|
1756
|
+
else setScreen(SCREEN.PREVIEW);
|
|
1757
|
+
},
|
|
1758
|
+
});
|
|
1759
|
+
|
|
1760
|
+
case SCREEN.INSTALLING:
|
|
1761
|
+
return h(InstallingScreen, {
|
|
1762
|
+
scope,
|
|
1763
|
+
sounds,
|
|
1764
|
+
tts,
|
|
1765
|
+
voice,
|
|
1766
|
+
onDone: (result) => {
|
|
1767
|
+
setInstallResult(result);
|
|
1768
|
+
setScreen(SCREEN.DONE);
|
|
1769
|
+
},
|
|
1770
|
+
});
|
|
1771
|
+
|
|
1772
|
+
case SCREEN.DONE:
|
|
1773
|
+
return h(DoneScreen, { result: installResult });
|
|
1774
|
+
|
|
1775
|
+
case SCREEN.MUSIC_MODE:
|
|
1776
|
+
return h(MusicModeScreen, {
|
|
1777
|
+
onRandom: () => {
|
|
1778
|
+
listCachedGames().then((games) => {
|
|
1779
|
+
const allFiles = games.flatMap((g) => g.files.map((f) => ({ ...f, gameName: g.gameName })));
|
|
1780
|
+
setMusicFiles(allFiles);
|
|
1781
|
+
setMusicGameName("All Games");
|
|
1782
|
+
setMusicShuffle(true);
|
|
1783
|
+
setScreen(SCREEN.MUSIC_PLAYING);
|
|
1784
|
+
});
|
|
1785
|
+
},
|
|
1786
|
+
onPickGame: () => setScreen(SCREEN.MUSIC_GAME_PICK),
|
|
1787
|
+
onBack: () => setScreen(SCREEN.SCOPE),
|
|
1788
|
+
});
|
|
1789
|
+
|
|
1790
|
+
case SCREEN.MUSIC_GAME_PICK:
|
|
1791
|
+
return h(MusicGamePickScreen, {
|
|
1792
|
+
onNext: (game) => {
|
|
1793
|
+
setMusicFiles(game.files.map((f) => ({ ...f, gameName: game.name })));
|
|
1794
|
+
setMusicGameName(game.name);
|
|
1795
|
+
setMusicShuffle(false);
|
|
1796
|
+
setScreen(SCREEN.MUSIC_PLAYING);
|
|
1797
|
+
},
|
|
1798
|
+
onExtract: (game) => {
|
|
1799
|
+
setSelectedGame(game);
|
|
1800
|
+
setScreen(SCREEN.MUSIC_EXTRACTING);
|
|
1801
|
+
},
|
|
1802
|
+
onBack: () => setScreen(SCREEN.MUSIC_MODE),
|
|
1803
|
+
});
|
|
1804
|
+
|
|
1805
|
+
case SCREEN.MUSIC_PLAYING:
|
|
1806
|
+
return h(MusicPlayingScreen, {
|
|
1807
|
+
files: musicFiles,
|
|
1808
|
+
gameName: musicGameName,
|
|
1809
|
+
shuffle: musicShuffle,
|
|
1810
|
+
onBack: () => setScreen(SCREEN.MUSIC_MODE),
|
|
1811
|
+
});
|
|
1812
|
+
|
|
1813
|
+
case SCREEN.MUSIC_EXTRACTING:
|
|
1814
|
+
return h(ExtractingScreen, {
|
|
1815
|
+
game: selectedGame,
|
|
1816
|
+
onDone: (result) => {
|
|
1817
|
+
if (result.error || result.files.length === 0) {
|
|
1818
|
+
setScreen(SCREEN.MUSIC_GAME_PICK);
|
|
1819
|
+
} else {
|
|
1820
|
+
// Go straight to playing the extracted files
|
|
1821
|
+
setMusicFiles(result.files.map((f) => ({ ...f, gameName: selectedGame.name })));
|
|
1822
|
+
setMusicGameName(selectedGame.name);
|
|
1823
|
+
setMusicShuffle(true);
|
|
1824
|
+
setScreen(SCREEN.MUSIC_PLAYING);
|
|
1825
|
+
}
|
|
1826
|
+
},
|
|
1827
|
+
onBack: () => setScreen(SCREEN.MUSIC_GAME_PICK),
|
|
1828
|
+
});
|
|
1829
|
+
|
|
1830
|
+
default:
|
|
1831
|
+
return h(Text, { color: "red" }, "Unknown screen");
|
|
1832
|
+
}
|
|
1833
|
+
})();
|
|
1834
|
+
|
|
1835
|
+
return h(Box, { flexDirection: "column" },
|
|
1836
|
+
h(Header, null),
|
|
1837
|
+
content,
|
|
1838
|
+
);
|
|
1839
|
+
};
|
|
1840
|
+
|
|
1841
|
+
// ── Entry ───────────────────────────────────────────────────────
|
|
1842
|
+
export async function run() {
|
|
1843
|
+
const AppComponent = isUninstallMode ? UninstallApp : InstallApp;
|
|
1844
|
+
const instance = render(h(AppComponent));
|
|
1845
|
+
await instance.waitUntilExit();
|
|
1846
|
+
}
|