klaudio 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +67 -65
- package/package.json +44 -40
- package/src/cache.js +262 -262
- package/src/cli.js +1205 -999
- package/src/extractor.js +203 -203
- package/src/installer.js +161 -128
- package/src/player.js +359 -359
- package/src/presets.js +5 -5
- package/src/scanner.js +41 -6
- package/src/unity.js +241 -0
package/src/cli.js
CHANGED
|
@@ -1,999 +1,1205 @@
|
|
|
1
|
-
import React, { useState, useEffect, useCallback } from "react";
|
|
2
|
-
import { render, Box, Text, useInput, useApp } from "ink";
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import { getCachedExtraction, cacheExtraction, categorizeLooseFiles, getCategories, sortFilesByPriority } from "./cache.js";
|
|
11
|
-
import { basename, dirname } from "node:path";
|
|
12
|
-
import { tmpdir } from "node:os";
|
|
13
|
-
import { join } from "node:path";
|
|
14
|
-
|
|
15
|
-
const MAX_PLAY_SECONDS = 10;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
},
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
},
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
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
|
-
}
|
|
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
|
-
|
|
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
|
-
const
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
const
|
|
359
|
-
const
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
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
|
-
if (
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
}, [
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
if (
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
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
|
-
return
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
const
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
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
|
-
|
|
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
|
-
const
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
),
|
|
739
|
-
),
|
|
740
|
-
|
|
741
|
-
h(
|
|
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
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
}
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
const
|
|
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
|
-
|
|
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
|
-
|
|
1
|
+
import React, { useState, useEffect, useCallback, useRef } 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 { playSoundWithCancel, getWavDuration } from "./player.js";
|
|
6
|
+
import { getAvailableGames } from "./scanner.js";
|
|
7
|
+
import { install, uninstall, getExistingSounds } from "./installer.js";
|
|
8
|
+
import { getVgmstreamPath, findPackedAudioFiles, extractToWav } from "./extractor.js";
|
|
9
|
+
import { extractUnityResource } from "./unity.js";
|
|
10
|
+
import { getCachedExtraction, cacheExtraction, categorizeLooseFiles, getCategories, sortFilesByPriority } from "./cache.js";
|
|
11
|
+
import { basename, dirname } from "node:path";
|
|
12
|
+
import { tmpdir } from "node:os";
|
|
13
|
+
import { join } from "node:path";
|
|
14
|
+
|
|
15
|
+
const MAX_PLAY_SECONDS = 10;
|
|
16
|
+
const ACCENT = "#76C41E"; // Needle green-yellow midpoint
|
|
17
|
+
|
|
18
|
+
const h = React.createElement;
|
|
19
|
+
|
|
20
|
+
// ── Custom SelectInput components (bright colors for CMD) ────
|
|
21
|
+
const Indicator = ({ isSelected }) =>
|
|
22
|
+
h(Box, { marginRight: 1 }, isSelected
|
|
23
|
+
? h(Text, { color: ACCENT }, "❯")
|
|
24
|
+
: h(Text, null, " "));
|
|
25
|
+
|
|
26
|
+
const Item = ({ isSelected, label }) =>
|
|
27
|
+
h(Text, { color: isSelected ? ACCENT : undefined, bold: isSelected }, label);
|
|
28
|
+
|
|
29
|
+
// ── Non-wrapping SelectInput (clamps at boundaries) ─────────────
|
|
30
|
+
const SelectInput = ({ items = [], isFocused = true, initialIndex = 0, indicatorComponent = Indicator, itemComponent = Item, limit: customLimit, onSelect, onHighlight }) => {
|
|
31
|
+
const hasLimit = typeof customLimit === "number" && items.length > customLimit;
|
|
32
|
+
const limit = hasLimit ? Math.min(customLimit, items.length) : items.length;
|
|
33
|
+
const [scrollOffset, setScrollOffset] = useState(0);
|
|
34
|
+
const [selectedIndex, setSelectedIndex] = useState(initialIndex ? Math.min(initialIndex, items.length - 1) : 0);
|
|
35
|
+
const previousItems = useRef(items);
|
|
36
|
+
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
const prevValues = previousItems.current.map((i) => i.value);
|
|
39
|
+
const curValues = items.map((i) => i.value);
|
|
40
|
+
if (prevValues.length !== curValues.length || prevValues.some((v, i) => v !== curValues[i])) {
|
|
41
|
+
setScrollOffset(0);
|
|
42
|
+
setSelectedIndex(0);
|
|
43
|
+
}
|
|
44
|
+
previousItems.current = items;
|
|
45
|
+
}, [items]);
|
|
46
|
+
|
|
47
|
+
useInput(useCallback((input, key) => {
|
|
48
|
+
if (input === "k" || key.upArrow) {
|
|
49
|
+
if (selectedIndex <= 0) return; // clamp — don't wrap
|
|
50
|
+
const next = selectedIndex - 1;
|
|
51
|
+
let newOffset = scrollOffset;
|
|
52
|
+
if (hasLimit && next < scrollOffset) newOffset = next;
|
|
53
|
+
setSelectedIndex(next);
|
|
54
|
+
setScrollOffset(newOffset);
|
|
55
|
+
if (typeof onHighlight === "function") onHighlight(items[next]);
|
|
56
|
+
}
|
|
57
|
+
if (input === "j" || key.downArrow) {
|
|
58
|
+
if (selectedIndex >= items.length - 1) return; // clamp — don't wrap
|
|
59
|
+
const next = selectedIndex + 1;
|
|
60
|
+
let newOffset = scrollOffset;
|
|
61
|
+
if (hasLimit && next >= scrollOffset + limit) newOffset = next - limit + 1;
|
|
62
|
+
setSelectedIndex(next);
|
|
63
|
+
setScrollOffset(newOffset);
|
|
64
|
+
if (typeof onHighlight === "function") onHighlight(items[next]);
|
|
65
|
+
}
|
|
66
|
+
if (key.return) {
|
|
67
|
+
if (typeof onSelect === "function") onSelect(items[selectedIndex]);
|
|
68
|
+
}
|
|
69
|
+
}, [hasLimit, limit, scrollOffset, selectedIndex, items, onSelect, onHighlight]), { isActive: isFocused });
|
|
70
|
+
|
|
71
|
+
const visible = hasLimit ? items.slice(scrollOffset, scrollOffset + limit) : items;
|
|
72
|
+
return h(Box, { flexDirection: "column" }, visible.map((item, index) => {
|
|
73
|
+
const isSelected = index + scrollOffset === selectedIndex;
|
|
74
|
+
return h(Box, { key: item.key ?? item.value },
|
|
75
|
+
h(indicatorComponent, { isSelected }),
|
|
76
|
+
h(itemComponent, { ...item, isSelected }));
|
|
77
|
+
}));
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
// ── Screens ─────────────────────────────────────────────────────
|
|
81
|
+
const SCREEN = {
|
|
82
|
+
SCOPE: 0,
|
|
83
|
+
PRESET: 1,
|
|
84
|
+
PREVIEW: 2,
|
|
85
|
+
SCANNING: 3,
|
|
86
|
+
GAME_PICK: 4,
|
|
87
|
+
GAME_SOUNDS: 5,
|
|
88
|
+
EXTRACTING: 6,
|
|
89
|
+
CONFIRM: 7,
|
|
90
|
+
INSTALLING: 8,
|
|
91
|
+
DONE: 9,
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const isUninstallMode = process.argv.includes("--uninstall") || process.argv.includes("--remove");
|
|
95
|
+
|
|
96
|
+
// ── Header component ────────────────────────────────────────────
|
|
97
|
+
const Header = () =>
|
|
98
|
+
h(Box, { flexDirection: "column", marginBottom: 1 },
|
|
99
|
+
h(Text, { bold: true, color: ACCENT }, " klaudio"),
|
|
100
|
+
h(Text, { dimColor: true }, isUninstallMode
|
|
101
|
+
? " Remove sound effects from Claude Code"
|
|
102
|
+
: " Add sound effects to your Claude Code sessions"),
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
const NavHint = ({ back = true, extra = "" }) =>
|
|
106
|
+
h(Box, { marginTop: 1 },
|
|
107
|
+
h(Text, { dimColor: true },
|
|
108
|
+
(back ? " esc back" : "") +
|
|
109
|
+
(extra ? (back ? " • " : " ") + extra : "")
|
|
110
|
+
),
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
// ── Screen: Scope ───────────────────────────────────────────────
|
|
114
|
+
const ScopeScreen = ({ onNext }) => {
|
|
115
|
+
const items = [
|
|
116
|
+
{ label: "Global (~/.claude) — sounds in all projects", value: "global" },
|
|
117
|
+
{ label: "This project (.claude/) — project-specific", value: "project" },
|
|
118
|
+
];
|
|
119
|
+
return h(Box, { flexDirection: "column" },
|
|
120
|
+
h(Text, { bold: true }, " Where should sounds be installed?"),
|
|
121
|
+
h(Box, { marginLeft: 2 },
|
|
122
|
+
h(SelectInput, { indicatorComponent: Indicator, itemComponent: Item, items, onSelect: (item) => onNext(item.value) }),
|
|
123
|
+
),
|
|
124
|
+
);
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
// ── Screen: Preset ──────────────────────────────────────────────
|
|
128
|
+
const PresetScreen = ({ onNext, onBack }) => {
|
|
129
|
+
useInput((_, key) => { if (key.escape) onBack(); });
|
|
130
|
+
|
|
131
|
+
const items = [
|
|
132
|
+
...Object.entries(PRESETS).map(([id, p]) => ({
|
|
133
|
+
label: `${p.icon} ${p.name} — ${p.description}`,
|
|
134
|
+
value: id,
|
|
135
|
+
})),
|
|
136
|
+
{ label: "🕹️ Scan local games — find sounds from your Steam & Epic Games library", value: "_scan" },
|
|
137
|
+
{ label: "📁 Custom files — provide your own sound files", value: "_custom" },
|
|
138
|
+
];
|
|
139
|
+
|
|
140
|
+
return h(Box, { flexDirection: "column" },
|
|
141
|
+
h(Text, { bold: true }, " Choose a sound preset:"),
|
|
142
|
+
h(Box, { marginLeft: 2 },
|
|
143
|
+
h(SelectInput, { indicatorComponent: Indicator, itemComponent: Item, items, onSelect: (item) => onNext(item.value) }),
|
|
144
|
+
),
|
|
145
|
+
h(NavHint, { back: true }),
|
|
146
|
+
);
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
// ── Screen: Preview ─────────────────────────────────────────────
|
|
150
|
+
const PreviewScreen = ({ presetId, sounds, onAccept, onBack, onUpdateSound }) => {
|
|
151
|
+
const preset = PRESETS[presetId];
|
|
152
|
+
const eventIds = Object.keys(EVENTS);
|
|
153
|
+
const [currentEvent, setCurrentEvent] = useState(0);
|
|
154
|
+
const [playing, setPlaying] = useState(false);
|
|
155
|
+
const [elapsed, setElapsed] = useState(0);
|
|
156
|
+
const [durations, setDurations] = useState({});
|
|
157
|
+
const cancelRef = React.useRef(null);
|
|
158
|
+
|
|
159
|
+
const eventId = eventIds[currentEvent];
|
|
160
|
+
const eventInfo = EVENTS[eventId];
|
|
161
|
+
const soundFile = sounds[eventId];
|
|
162
|
+
|
|
163
|
+
const stopPlayback = useCallback(() => {
|
|
164
|
+
if (cancelRef.current) { cancelRef.current(); cancelRef.current = null; }
|
|
165
|
+
setPlaying(false);
|
|
166
|
+
setElapsed(0);
|
|
167
|
+
}, []);
|
|
168
|
+
|
|
169
|
+
// Fetch durations for all sound files
|
|
170
|
+
useEffect(() => {
|
|
171
|
+
for (const [eid, path] of Object.entries(sounds)) {
|
|
172
|
+
if (path && !durations[eid]) {
|
|
173
|
+
getWavDuration(path).then((dur) => {
|
|
174
|
+
if (dur != null) setDurations((d) => ({ ...d, [eid]: dur }));
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}, [sounds]);
|
|
179
|
+
|
|
180
|
+
// Auto-play when current event changes (with debounce)
|
|
181
|
+
useEffect(() => {
|
|
182
|
+
if (!soundFile) return;
|
|
183
|
+
stopPlayback();
|
|
184
|
+
const timer = setTimeout(() => {
|
|
185
|
+
setPlaying(true);
|
|
186
|
+
const { promise, cancel } = playSoundWithCancel(soundFile);
|
|
187
|
+
cancelRef.current = cancel;
|
|
188
|
+
promise.catch(() => {}).finally(() => {
|
|
189
|
+
cancelRef.current = null;
|
|
190
|
+
setPlaying(false);
|
|
191
|
+
setElapsed(0);
|
|
192
|
+
});
|
|
193
|
+
}, 150);
|
|
194
|
+
return () => {
|
|
195
|
+
clearTimeout(timer);
|
|
196
|
+
if (cancelRef.current) {
|
|
197
|
+
cancelRef.current();
|
|
198
|
+
cancelRef.current = null;
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
}, [currentEvent]);
|
|
202
|
+
|
|
203
|
+
useInput((_, key) => {
|
|
204
|
+
if (key.escape) {
|
|
205
|
+
if (playing) {
|
|
206
|
+
stopPlayback();
|
|
207
|
+
} else {
|
|
208
|
+
onBack();
|
|
209
|
+
}
|
|
210
|
+
} else if (key.leftArrow || key.upArrow) {
|
|
211
|
+
if (currentEvent > 0) {
|
|
212
|
+
stopPlayback();
|
|
213
|
+
setCurrentEvent((i) => i - 1);
|
|
214
|
+
}
|
|
215
|
+
} else if (key.rightArrow || key.downArrow) {
|
|
216
|
+
if (currentEvent < eventIds.length - 1) {
|
|
217
|
+
stopPlayback();
|
|
218
|
+
setCurrentEvent((i) => i + 1);
|
|
219
|
+
}
|
|
220
|
+
} else if (key.return) {
|
|
221
|
+
stopPlayback();
|
|
222
|
+
onAccept(sounds);
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
// Elapsed timer while playing
|
|
227
|
+
useEffect(() => {
|
|
228
|
+
if (!playing) return;
|
|
229
|
+
setElapsed(0);
|
|
230
|
+
const interval = setInterval(() => setElapsed((e) => e + 1), 1000);
|
|
231
|
+
return () => clearInterval(interval);
|
|
232
|
+
}, [playing]);
|
|
233
|
+
|
|
234
|
+
const stepLabel = `(${currentEvent + 1}/${eventIds.length})`;
|
|
235
|
+
const dur = durations[eventId];
|
|
236
|
+
const durLabel = dur != null ? ` (${dur > MAX_PLAY_SECONDS ? MAX_PLAY_SECONDS : dur}s)` : "";
|
|
237
|
+
|
|
238
|
+
return h(Box, { flexDirection: "column" },
|
|
239
|
+
h(Text, { bold: true }, ` ${preset.icon} ${preset.name}`),
|
|
240
|
+
h(Text, { dimColor: true }, ` ${preset.description}`),
|
|
241
|
+
h(Box, { marginTop: 1, flexDirection: "column" },
|
|
242
|
+
...eventIds.map((eid, i) => {
|
|
243
|
+
const d = durations[eid];
|
|
244
|
+
const dStr = d != null ? ` (${d > MAX_PLAY_SECONDS ? MAX_PLAY_SECONDS : d}s)` : "";
|
|
245
|
+
return h(Text, { key: eid, marginLeft: 2,
|
|
246
|
+
color: i === currentEvent ? "#00FFFF" : i < currentEvent ? "green" : "white",
|
|
247
|
+
bold: i === currentEvent,
|
|
248
|
+
},
|
|
249
|
+
i < currentEvent ? " ✓ " : i === currentEvent ? " ▸ " : " ",
|
|
250
|
+
`${EVENTS[eid].name}: `,
|
|
251
|
+
sounds[eid] ? `${basename(sounds[eid])}${dStr}` : "(skipped)",
|
|
252
|
+
);
|
|
253
|
+
}),
|
|
254
|
+
),
|
|
255
|
+
h(Box, { marginTop: 1, flexDirection: "column", borderStyle: "round", borderColor: playing ? "green" : "cyan", paddingX: 2, paddingY: 0, marginLeft: 2, marginRight: 2 },
|
|
256
|
+
h(Text, { bold: true, color: playing ? "green" : "cyan" },
|
|
257
|
+
`${eventInfo.name} ${stepLabel}`,
|
|
258
|
+
),
|
|
259
|
+
h(Text, { dimColor: true },
|
|
260
|
+
soundFile
|
|
261
|
+
? `Sound: ${basename(soundFile)}${durLabel}`
|
|
262
|
+
: "No sound file selected",
|
|
263
|
+
),
|
|
264
|
+
h(Text, { dimColor: true },
|
|
265
|
+
`Triggers: ${eventInfo.description}`,
|
|
266
|
+
),
|
|
267
|
+
playing
|
|
268
|
+
? h(Box, { marginTop: 1 },
|
|
269
|
+
h(Text, { color: "green", bold: true }, h(Spinner, { type: "dots" })),
|
|
270
|
+
h(Text, { color: "green", bold: true }, ` Now playing: ${basename(soundFile)} ${elapsed}s / ${MAX_PLAY_SECONDS}s max`),
|
|
271
|
+
)
|
|
272
|
+
: null,
|
|
273
|
+
),
|
|
274
|
+
h(NavHint, { back: true, extra: "↑↓ switch events • enter accept all" }),
|
|
275
|
+
);
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
// ── Screen: Game Pick (with progressive background scanning) ────
|
|
279
|
+
const GamePickScreen = ({ onNext, onExtract, onBack }) => {
|
|
280
|
+
const [games, setGames] = useState([]);
|
|
281
|
+
const [scanning, setScanning] = useState(true);
|
|
282
|
+
const [scanStatus, setScanStatus] = useState("Discovering game directories...");
|
|
283
|
+
const [filter, setFilter] = useState("");
|
|
284
|
+
|
|
285
|
+
// Start scanning on mount, add games progressively
|
|
286
|
+
useEffect(() => {
|
|
287
|
+
let cancelled = false;
|
|
288
|
+
getAvailableGames(
|
|
289
|
+
(progress) => {
|
|
290
|
+
if (cancelled) return;
|
|
291
|
+
if (progress.phase === "dirs") {
|
|
292
|
+
setScanStatus(`Scanning ${progress.dirs.length} directories...`);
|
|
293
|
+
} else if (progress.phase === "scanning") {
|
|
294
|
+
setScanStatus(`Scanning: ${progress.game}`);
|
|
295
|
+
}
|
|
296
|
+
},
|
|
297
|
+
(game) => {
|
|
298
|
+
if (cancelled) return;
|
|
299
|
+
// Add each game as it's found (only if it has audio or can extract)
|
|
300
|
+
setGames((prev) => {
|
|
301
|
+
if (prev.some((g) => g.name === game.name)) return prev;
|
|
302
|
+
const next = [...prev, game];
|
|
303
|
+
// Sort: playable first, then extractable, then others
|
|
304
|
+
next.sort((a, b) => {
|
|
305
|
+
if (a.hasAudio !== b.hasAudio) return a.hasAudio ? -1 : 1;
|
|
306
|
+
if (a.canExtract !== b.canExtract) return a.canExtract ? -1 : 1;
|
|
307
|
+
return a.name.localeCompare(b.name);
|
|
308
|
+
});
|
|
309
|
+
return next;
|
|
310
|
+
});
|
|
311
|
+
},
|
|
312
|
+
).then(() => {
|
|
313
|
+
if (!cancelled) setScanning(false);
|
|
314
|
+
}).catch(() => {
|
|
315
|
+
if (!cancelled) setScanning(false);
|
|
316
|
+
});
|
|
317
|
+
return () => { cancelled = true; };
|
|
318
|
+
}, []);
|
|
319
|
+
|
|
320
|
+
useInput((input, key) => {
|
|
321
|
+
if (key.escape) {
|
|
322
|
+
if (filter) setFilter("");
|
|
323
|
+
else onBack();
|
|
324
|
+
} else if (key.backspace || key.delete) {
|
|
325
|
+
setFilter((f) => f.slice(0, -1));
|
|
326
|
+
} else if (input && !key.ctrl && !key.meta && input.length === 1 && input.charCodeAt(0) >= 32) {
|
|
327
|
+
setFilter((f) => f + input);
|
|
328
|
+
}
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
const usableGames = games.filter((g) => g.hasAudio || g.canExtract);
|
|
332
|
+
const noAudio = games.filter((g) => !g.hasAudio && !g.canExtract);
|
|
333
|
+
|
|
334
|
+
const allItems = usableGames
|
|
335
|
+
.sort((a, b) => a.name.localeCompare(b.name))
|
|
336
|
+
.map((g) => {
|
|
337
|
+
if (g.hasAudio) {
|
|
338
|
+
return {
|
|
339
|
+
key: `play:${g.name}`,
|
|
340
|
+
label: `${g.name} (${g.fileCount} audio files)`,
|
|
341
|
+
value: `play:${g.name}`,
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
const hasUnity = (g.unityAudioCount || 0) > 0;
|
|
345
|
+
const hasPacked = (g.packedAudioCount || 0) > 0;
|
|
346
|
+
const detail = hasUnity && !hasPacked
|
|
347
|
+
? `${g.unityAudioCount} Unity audio resource(s) — extract`
|
|
348
|
+
: hasPacked && !hasUnity
|
|
349
|
+
? `${g.packedAudioCount} packed — extract with vgmstream`
|
|
350
|
+
: `${g.packedAudioCount} packed + ${g.unityAudioCount} Unity — extract`;
|
|
351
|
+
return {
|
|
352
|
+
key: `extract:${g.name}`,
|
|
353
|
+
label: `${g.name} (${detail})`,
|
|
354
|
+
value: `extract:${g.name}`,
|
|
355
|
+
};
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
const filterLower = filter.toLowerCase();
|
|
359
|
+
const items = filter
|
|
360
|
+
? allItems.filter((i) => i.label.toLowerCase().includes(filterLower))
|
|
361
|
+
: allItems;
|
|
362
|
+
|
|
363
|
+
return h(Box, { flexDirection: "column" },
|
|
364
|
+
scanning
|
|
365
|
+
? h(Box, { marginLeft: 2 },
|
|
366
|
+
h(Text, { color: ACCENT }, h(Spinner, { type: "dots" })),
|
|
367
|
+
h(Text, null, ` ${scanStatus}`),
|
|
368
|
+
games.length > 0
|
|
369
|
+
? h(Text, { color: "green" }, ` (${games.length} found)`)
|
|
370
|
+
: null,
|
|
371
|
+
)
|
|
372
|
+
: h(Text, { bold: true, marginLeft: 2 },
|
|
373
|
+
` Found ${games.length} game(s):`,
|
|
374
|
+
),
|
|
375
|
+
filter
|
|
376
|
+
? h(Box, { marginLeft: 4 },
|
|
377
|
+
h(Text, { color: "yellow" }, "Filter: "),
|
|
378
|
+
h(Text, { bold: true }, filter),
|
|
379
|
+
h(Text, { dimColor: true }, ` (${items.length} match${items.length !== 1 ? "es" : ""})`),
|
|
380
|
+
)
|
|
381
|
+
: items.length > 0
|
|
382
|
+
? h(Text, { dimColor: true, marginLeft: 4 }, "Type to filter... (select a game while scan continues)")
|
|
383
|
+
: null,
|
|
384
|
+
items.length > 0
|
|
385
|
+
? h(Box, { marginLeft: 2 },
|
|
386
|
+
h(SelectInput, { indicatorComponent: Indicator, itemComponent: Item,
|
|
387
|
+
items,
|
|
388
|
+
limit: 15,
|
|
389
|
+
onSelect: (item) => {
|
|
390
|
+
const [type, ...rest] = item.value.split(":");
|
|
391
|
+
const name = rest.join(":");
|
|
392
|
+
if (type === "extract") onExtract(name, games);
|
|
393
|
+
else onNext(name, games);
|
|
394
|
+
},
|
|
395
|
+
}),
|
|
396
|
+
)
|
|
397
|
+
: !scanning
|
|
398
|
+
? h(Text, { color: "yellow", marginLeft: 4 }, "No games with usable audio found.")
|
|
399
|
+
: null,
|
|
400
|
+
noAudio.length > 0 && !filter && !scanning
|
|
401
|
+
? h(Box, { flexDirection: "column", marginTop: 1, marginLeft: 4 },
|
|
402
|
+
h(Text, { dimColor: true },
|
|
403
|
+
`${noAudio.length} game(s) with no extractable audio:`,
|
|
404
|
+
),
|
|
405
|
+
h(Text, { dimColor: true },
|
|
406
|
+
noAudio.map((g) => g.name).join(", "),
|
|
407
|
+
),
|
|
408
|
+
)
|
|
409
|
+
: null,
|
|
410
|
+
h(NavHint, { back: true }),
|
|
411
|
+
);
|
|
412
|
+
};
|
|
413
|
+
|
|
414
|
+
// ── Screen: Game Sound Picker ───────────────────────────────────
|
|
415
|
+
// Three-phase: category pick → file pick → preview/accept/repick
|
|
416
|
+
const CATEGORY_LABELS = {
|
|
417
|
+
all: "All sounds", ambient: "Ambient", music: "Music", sfx: "SFX",
|
|
418
|
+
ui: "UI", voice: "Voice / Dialogue", creature: "Creatures / Animals", other: "Other",
|
|
419
|
+
};
|
|
420
|
+
const CATEGORY_ICONS = {
|
|
421
|
+
voice: "🗣", creature: "🐾", ui: "🖱", sfx: "💥",
|
|
422
|
+
ambient: "🌿", music: "🎵", other: "📦", all: "📂",
|
|
423
|
+
};
|
|
424
|
+
|
|
425
|
+
const GameSoundsScreen = ({ game, sounds, onSelectSound, onDone, onBack }) => {
|
|
426
|
+
const eventIds = Object.keys(EVENTS);
|
|
427
|
+
const [currentEvent, setCurrentEvent] = useState(0);
|
|
428
|
+
const [playing, setPlaying] = useState(false);
|
|
429
|
+
const [elapsed, setElapsed] = useState(0);
|
|
430
|
+
const [highlightedFile, setHighlightedFile] = useState(null);
|
|
431
|
+
const [fileDurations, setFileDurations] = useState({});
|
|
432
|
+
const [filter, setFilter] = useState("");
|
|
433
|
+
const [activeCategory, setActiveCategory] = useState(null); // null = show category picker
|
|
434
|
+
const [autoPreview, setAutoPreview] = useState(true);
|
|
435
|
+
const [justSelected, setJustSelected] = useState(null); // brief confirmation flash
|
|
436
|
+
const cancelRef = React.useRef(null);
|
|
437
|
+
|
|
438
|
+
// Determine available categories with counts
|
|
439
|
+
const hasCategories = game.files.some((f) => f.category);
|
|
440
|
+
const { categories, counts } = hasCategories
|
|
441
|
+
? getCategories(game.files)
|
|
442
|
+
: { categories: ["all"], counts: {} };
|
|
443
|
+
const meaningfulCats = categories.filter((c) => c !== "all" && (counts[c] || 0) >= 2);
|
|
444
|
+
const showCategoryPicker = meaningfulCats.length >= 2;
|
|
445
|
+
|
|
446
|
+
// Sort files: voice first, then by priority
|
|
447
|
+
const sortedFiles = hasCategories ? sortFilesByPriority(game.files) : game.files;
|
|
448
|
+
|
|
449
|
+
// Fetch durations for visible files
|
|
450
|
+
useEffect(() => {
|
|
451
|
+
for (const f of sortedFiles.slice(0, 50)) {
|
|
452
|
+
if (!fileDurations[f.path]) {
|
|
453
|
+
getWavDuration(f.path).then((dur) => {
|
|
454
|
+
if (dur != null) setFileDurations((d) => ({ ...d, [f.path]: dur }));
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
}, [game.files]);
|
|
459
|
+
|
|
460
|
+
// Filter files by category
|
|
461
|
+
const categoryFiles = activeCategory && activeCategory !== "all"
|
|
462
|
+
? sortedFiles.filter((f) => f.category === activeCategory).slice(0, 50)
|
|
463
|
+
: sortedFiles.slice(0, 50);
|
|
464
|
+
|
|
465
|
+
// Stop current playback helper
|
|
466
|
+
const stopPlayback = useCallback(() => {
|
|
467
|
+
if (cancelRef.current) {
|
|
468
|
+
cancelRef.current();
|
|
469
|
+
cancelRef.current = null;
|
|
470
|
+
}
|
|
471
|
+
setPlaying(false);
|
|
472
|
+
setElapsed(0);
|
|
473
|
+
}, []);
|
|
474
|
+
|
|
475
|
+
// Auto-preview: play sound when highlighted file changes (with debounce)
|
|
476
|
+
useEffect(() => {
|
|
477
|
+
if (!autoPreview || !highlightedFile || highlightedFile === "_skip") {
|
|
478
|
+
return;
|
|
479
|
+
}
|
|
480
|
+
// Cancel previous playback immediately
|
|
481
|
+
if (cancelRef.current) {
|
|
482
|
+
cancelRef.current();
|
|
483
|
+
cancelRef.current = null;
|
|
484
|
+
}
|
|
485
|
+
setPlaying(false);
|
|
486
|
+
setElapsed(0);
|
|
487
|
+
// Debounce: wait 150ms before starting playback so scrubbing doesn't spam
|
|
488
|
+
const timer = setTimeout(() => {
|
|
489
|
+
setPlaying(true);
|
|
490
|
+
setElapsed(0);
|
|
491
|
+
const { promise, cancel } = playSoundWithCancel(highlightedFile);
|
|
492
|
+
cancelRef.current = cancel;
|
|
493
|
+
promise.catch(() => {}).finally(() => {
|
|
494
|
+
cancelRef.current = null;
|
|
495
|
+
setPlaying(false);
|
|
496
|
+
setElapsed(0);
|
|
497
|
+
});
|
|
498
|
+
}, 150);
|
|
499
|
+
return () => {
|
|
500
|
+
clearTimeout(timer);
|
|
501
|
+
if (cancelRef.current) {
|
|
502
|
+
cancelRef.current();
|
|
503
|
+
cancelRef.current = null;
|
|
504
|
+
}
|
|
505
|
+
};
|
|
506
|
+
}, [highlightedFile, autoPreview]);
|
|
507
|
+
|
|
508
|
+
useInput((input, key) => {
|
|
509
|
+
if (key.tab) {
|
|
510
|
+
// Tab cycles through events + Apply tab (if any sounds assigned)
|
|
511
|
+
stopPlayback();
|
|
512
|
+
const hasSounds = Object.values(sounds).some(Boolean);
|
|
513
|
+
const tabCount = hasSounds ? eventIds.length + 1 : eventIds.length;
|
|
514
|
+
setCurrentEvent((i) => (i + 1) % tabCount);
|
|
515
|
+
setHighlightedFile(null);
|
|
516
|
+
setActiveCategory(null);
|
|
517
|
+
setFilter("");
|
|
518
|
+
} else if (key.escape) {
|
|
519
|
+
if (playing) {
|
|
520
|
+
stopPlayback();
|
|
521
|
+
} else if (filter) {
|
|
522
|
+
setFilter("");
|
|
523
|
+
} else if (activeCategory !== null && showCategoryPicker) {
|
|
524
|
+
stopPlayback();
|
|
525
|
+
setActiveCategory(null);
|
|
526
|
+
} else {
|
|
527
|
+
stopPlayback();
|
|
528
|
+
onBack();
|
|
529
|
+
}
|
|
530
|
+
} else if (input === "p" && !key.ctrl && !key.meta) {
|
|
531
|
+
// Toggle auto-preview
|
|
532
|
+
setAutoPreview((prev) => {
|
|
533
|
+
if (prev) stopPlayback();
|
|
534
|
+
return !prev;
|
|
535
|
+
});
|
|
536
|
+
} else if (activeCategory !== null) {
|
|
537
|
+
if (key.backspace || key.delete) {
|
|
538
|
+
setFilter((f) => f.slice(0, -1));
|
|
539
|
+
} else if (input && input !== "p" && !key.ctrl && !key.meta && input.length === 1 && input.charCodeAt(0) >= 32) {
|
|
540
|
+
setFilter((f) => f + input);
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
});
|
|
544
|
+
|
|
545
|
+
// Elapsed timer while playing
|
|
546
|
+
useEffect(() => {
|
|
547
|
+
if (!playing) return;
|
|
548
|
+
setElapsed(0);
|
|
549
|
+
const interval = setInterval(() => {
|
|
550
|
+
setElapsed((e) => e + 1);
|
|
551
|
+
}, 1000);
|
|
552
|
+
return () => clearInterval(interval);
|
|
553
|
+
}, [playing]);
|
|
554
|
+
|
|
555
|
+
const eventId = eventIds[currentEvent];
|
|
556
|
+
const eventInfo = EVENTS[eventId];
|
|
557
|
+
const stepLabel = `(${currentEvent + 1}/${eventIds.length})`;
|
|
558
|
+
|
|
559
|
+
const advance = useCallback((selectedFile, selectedEventId) => {
|
|
560
|
+
stopPlayback();
|
|
561
|
+
// Show confirmation flash
|
|
562
|
+
if (selectedFile) {
|
|
563
|
+
setJustSelected({ file: basename(selectedFile), event: EVENTS[selectedEventId]?.name || selectedEventId });
|
|
564
|
+
}
|
|
565
|
+
const doAdvance = () => {
|
|
566
|
+
setJustSelected(null);
|
|
567
|
+
// Move to next event that hasn't been assigned yet, or wrap around
|
|
568
|
+
const nextUnassigned = eventIds.findIndex((eid, i) => i > currentEvent && !sounds[eid]);
|
|
569
|
+
if (nextUnassigned >= 0) {
|
|
570
|
+
setCurrentEvent(nextUnassigned);
|
|
571
|
+
} else {
|
|
572
|
+
// All done or wrapped — go to next sequential
|
|
573
|
+
setCurrentEvent((i) => Math.min(i + 1, eventIds.length - 1));
|
|
574
|
+
}
|
|
575
|
+
setHighlightedFile(null);
|
|
576
|
+
setActiveCategory(null);
|
|
577
|
+
setFilter("");
|
|
578
|
+
};
|
|
579
|
+
if (selectedFile) {
|
|
580
|
+
setTimeout(doAdvance, 600);
|
|
581
|
+
} else {
|
|
582
|
+
doAdvance();
|
|
583
|
+
}
|
|
584
|
+
}, [currentEvent, eventIds, sounds, stopPlayback]);
|
|
585
|
+
|
|
586
|
+
const nowPlayingFile = playing && highlightedFile && highlightedFile !== "_skip"
|
|
587
|
+
? highlightedFile : null;
|
|
588
|
+
|
|
589
|
+
const hasAnySounds = Object.values(sounds).some(Boolean);
|
|
590
|
+
const allAssigned = eventIds.every((eid) => sounds[eid]);
|
|
591
|
+
// currentEvent can be eventIds.length to mean "Done" tab
|
|
592
|
+
const onDoneTab = currentEvent >= eventIds.length;
|
|
593
|
+
|
|
594
|
+
const headerBox = h(Box, { marginLeft: 2, marginBottom: 1, flexDirection: "column", borderStyle: "round", borderColor: nowPlayingFile ? "green" : ACCENT, paddingX: 2 },
|
|
595
|
+
h(Text, { bold: true, color: nowPlayingFile ? "green" : ACCENT },
|
|
596
|
+
`${game.name}`,
|
|
597
|
+
),
|
|
598
|
+
h(Box, { marginTop: 0, gap: 2 },
|
|
599
|
+
...eventIds.map((eid, i) => {
|
|
600
|
+
const assigned = sounds[eid];
|
|
601
|
+
const isCurrent = i === currentEvent;
|
|
602
|
+
const truncName = assigned ? basename(assigned).slice(0, 20) : null;
|
|
603
|
+
const prefix = isCurrent ? "▸" : assigned ? "✓" : "·";
|
|
604
|
+
const label = truncName
|
|
605
|
+
? `${prefix} ${EVENTS[eid].name}: ${truncName}`
|
|
606
|
+
: `${prefix} ${EVENTS[eid].name}`;
|
|
607
|
+
return h(Text, {
|
|
608
|
+
key: eid,
|
|
609
|
+
bold: isCurrent,
|
|
610
|
+
color: isCurrent ? ACCENT : assigned ? "green" : "gray",
|
|
611
|
+
}, label);
|
|
612
|
+
}),
|
|
613
|
+
h(Text, {
|
|
614
|
+
key: "_done",
|
|
615
|
+
bold: onDoneTab,
|
|
616
|
+
color: onDoneTab ? ACCENT : hasAnySounds ? "green" : "gray",
|
|
617
|
+
}, onDoneTab ? "▸ ✓ Apply" : hasAnySounds ? "· ✓ Apply" : "· Apply"),
|
|
618
|
+
h(Text, { dimColor: true }, "(tab)"),
|
|
619
|
+
),
|
|
620
|
+
onDoneTab
|
|
621
|
+
? h(Text, { dimColor: true }, "Press enter to apply your sound selections")
|
|
622
|
+
: sounds[eventId]
|
|
623
|
+
? h(Text, { color: "green" }, `✓ ${basename(sounds[eventId])} — ${eventInfo.description}`)
|
|
624
|
+
: h(Text, { dimColor: true }, `${eventInfo.description}`),
|
|
625
|
+
);
|
|
626
|
+
|
|
627
|
+
const nowPlayingBar = h(Box, { marginLeft: 2, height: 1 },
|
|
628
|
+
justSelected
|
|
629
|
+
? h(Text, { color: "green", bold: true }, ` ✓ Selected "${justSelected.file}" for ${justSelected.event}`)
|
|
630
|
+
: nowPlayingFile
|
|
631
|
+
? h(Box, null,
|
|
632
|
+
h(Text, { color: "green", bold: true }, h(Spinner, { type: "dots" })),
|
|
633
|
+
h(Text, { color: "green", bold: true }, ` Now playing: ${basename(nowPlayingFile)} ${elapsed}s / ${MAX_PLAY_SECONDS}s max`),
|
|
634
|
+
)
|
|
635
|
+
: h(Text, { dimColor: true }, " "),
|
|
636
|
+
);
|
|
637
|
+
|
|
638
|
+
// Apply tab: show summary and confirm
|
|
639
|
+
if (onDoneTab) {
|
|
640
|
+
const confirmItems = [
|
|
641
|
+
{ label: "✓ Apply sounds", value: "apply" },
|
|
642
|
+
{ label: "← Back to editing", value: "back" },
|
|
643
|
+
];
|
|
644
|
+
return h(Box, { flexDirection: "column" },
|
|
645
|
+
headerBox,
|
|
646
|
+
h(Box, { flexDirection: "column", marginLeft: 4, marginBottom: 1 },
|
|
647
|
+
...eventIds.map((eid) =>
|
|
648
|
+
h(Text, { key: eid, color: sounds[eid] ? "green" : "gray" },
|
|
649
|
+
sounds[eid] ? ` ✓ ${EVENTS[eid].name}: ${basename(sounds[eid])}` : ` · ${EVENTS[eid].name}: (skipped)`,
|
|
650
|
+
),
|
|
651
|
+
),
|
|
652
|
+
),
|
|
653
|
+
h(Box, { marginLeft: 2 },
|
|
654
|
+
h(SelectInput, { indicatorComponent: Indicator, itemComponent: Item,
|
|
655
|
+
items: confirmItems,
|
|
656
|
+
onSelect: (item) => {
|
|
657
|
+
if (item.value === "apply") {
|
|
658
|
+
stopPlayback();
|
|
659
|
+
onDone();
|
|
660
|
+
} else {
|
|
661
|
+
setCurrentEvent(0);
|
|
662
|
+
}
|
|
663
|
+
},
|
|
664
|
+
}),
|
|
665
|
+
),
|
|
666
|
+
nowPlayingBar,
|
|
667
|
+
h(NavHint, { back: true }),
|
|
668
|
+
);
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
// Phase 0: Category picker
|
|
672
|
+
if (activeCategory === null && showCategoryPicker) {
|
|
673
|
+
const catItems = [
|
|
674
|
+
...meaningfulCats.map((cat) => ({
|
|
675
|
+
label: `${CATEGORY_ICONS[cat] || "📁"} ${CATEGORY_LABELS[cat] || cat} (${counts[cat]} sounds)`,
|
|
676
|
+
value: cat,
|
|
677
|
+
})),
|
|
678
|
+
{ label: `${CATEGORY_ICONS.all} All sounds (${game.files.length})`, value: "all" },
|
|
679
|
+
{ label: "(skip this event)", value: "_skip" },
|
|
680
|
+
];
|
|
681
|
+
|
|
682
|
+
return h(Box, { flexDirection: "column" },
|
|
683
|
+
headerBox,
|
|
684
|
+
h(Text, { bold: true, marginLeft: 4 }, "Pick a category:"),
|
|
685
|
+
h(Box, { marginLeft: 2 },
|
|
686
|
+
h(SelectInput, { indicatorComponent: Indicator, itemComponent: Item,
|
|
687
|
+
items: catItems,
|
|
688
|
+
onSelect: (item) => {
|
|
689
|
+
if (item.value === "_skip") {
|
|
690
|
+
advance();
|
|
691
|
+
} else {
|
|
692
|
+
setActiveCategory(item.value);
|
|
693
|
+
}
|
|
694
|
+
},
|
|
695
|
+
}),
|
|
696
|
+
),
|
|
697
|
+
nowPlayingBar,
|
|
698
|
+
h(NavHint, { back: true }),
|
|
699
|
+
);
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
// Phase 1: Browse and pick files (auto-preview plays on highlight)
|
|
703
|
+
const filterLower = filter.toLowerCase();
|
|
704
|
+
const allFileItems = categoryFiles.map((f) => {
|
|
705
|
+
const dur = fileDurations[f.path];
|
|
706
|
+
const durStr = dur != null ? ` (${dur > MAX_PLAY_SECONDS ? MAX_PLAY_SECONDS + "s max" : dur + "s"})` : "";
|
|
707
|
+
const catTag = (!activeCategory || activeCategory === "all") && f.category && f.category !== "other"
|
|
708
|
+
? `[${(CATEGORY_LABELS[f.category] || f.category).toUpperCase()}] ` : "";
|
|
709
|
+
const name = f.displayName || f.name;
|
|
710
|
+
return {
|
|
711
|
+
label: `${catTag}${name}${durStr}`,
|
|
712
|
+
value: f.path,
|
|
713
|
+
};
|
|
714
|
+
});
|
|
715
|
+
|
|
716
|
+
const filteredFiles = filter
|
|
717
|
+
? allFileItems.filter((i) => i.label.toLowerCase().includes(filterLower))
|
|
718
|
+
: allFileItems;
|
|
719
|
+
|
|
720
|
+
const fileItems = [
|
|
721
|
+
...filteredFiles,
|
|
722
|
+
...(!filter ? [{ label: "(skip this event)", value: "_skip" }] : []),
|
|
723
|
+
];
|
|
724
|
+
|
|
725
|
+
const catLabel = activeCategory && activeCategory !== "all"
|
|
726
|
+
? `${CATEGORY_ICONS[activeCategory] || ""} ${CATEGORY_LABELS[activeCategory] || activeCategory}`
|
|
727
|
+
: null;
|
|
728
|
+
|
|
729
|
+
return h(Box, { flexDirection: "column" },
|
|
730
|
+
headerBox,
|
|
731
|
+
catLabel
|
|
732
|
+
? h(Text, { bold: true, color: ACCENT, marginLeft: 4 }, catLabel)
|
|
733
|
+
: null,
|
|
734
|
+
h(Box, { marginLeft: 4 },
|
|
735
|
+
h(Text, { color: autoPreview ? "green" : "gray", bold: autoPreview },
|
|
736
|
+
autoPreview ? "♫ Auto-preview ON" : "♫ Auto-preview OFF"
|
|
737
|
+
),
|
|
738
|
+
h(Text, { dimColor: true }, " (p to toggle)"),
|
|
739
|
+
),
|
|
740
|
+
filter
|
|
741
|
+
? h(Box, { marginLeft: 4 },
|
|
742
|
+
h(Text, { color: "yellow" }, "Filter: "),
|
|
743
|
+
h(Text, { bold: true }, filter),
|
|
744
|
+
h(Text, { dimColor: true }, ` (${filteredFiles.length} match${filteredFiles.length !== 1 ? "es" : ""})`),
|
|
745
|
+
)
|
|
746
|
+
: categoryFiles.length > 15
|
|
747
|
+
? h(Text, { dimColor: true, marginLeft: 4 }, "Type to filter...")
|
|
748
|
+
: null,
|
|
749
|
+
fileItems.length > 0
|
|
750
|
+
? h(Box, { marginLeft: 2 },
|
|
751
|
+
h(SelectInput, { indicatorComponent: Indicator, itemComponent: Item,
|
|
752
|
+
items: fileItems,
|
|
753
|
+
limit: 15,
|
|
754
|
+
onHighlight: (item) => {
|
|
755
|
+
setHighlightedFile(item.value);
|
|
756
|
+
},
|
|
757
|
+
onSelect: (item) => {
|
|
758
|
+
stopPlayback();
|
|
759
|
+
if (item.value === "_skip") {
|
|
760
|
+
advance(null, null);
|
|
761
|
+
} else {
|
|
762
|
+
onSelectSound(eventId, item.value);
|
|
763
|
+
advance(item.value, eventId);
|
|
764
|
+
}
|
|
765
|
+
},
|
|
766
|
+
}),
|
|
767
|
+
)
|
|
768
|
+
: h(Text, { color: "yellow", marginLeft: 4 }, "No matches."),
|
|
769
|
+
nowPlayingBar,
|
|
770
|
+
h(NavHint, { back: true, extra: "tab switch event" }),
|
|
771
|
+
);
|
|
772
|
+
};
|
|
773
|
+
|
|
774
|
+
// ── Screen: Extracting ──────────────────────────────────────────
|
|
775
|
+
const ExtractingScreen = ({ game, onDone, onBack }) => {
|
|
776
|
+
const [status, setStatus] = useState("Checking cache...");
|
|
777
|
+
const [extracted, setExtracted] = useState(0);
|
|
778
|
+
|
|
779
|
+
useInput((_, key) => { if (key.escape) onBack(); });
|
|
780
|
+
|
|
781
|
+
useEffect(() => {
|
|
782
|
+
let cancelled = false;
|
|
783
|
+
|
|
784
|
+
(async () => {
|
|
785
|
+
try {
|
|
786
|
+
// Check cache first
|
|
787
|
+
const cached = await getCachedExtraction(game.name);
|
|
788
|
+
if (cached && cached.files.length > 0) {
|
|
789
|
+
setStatus(`Found ${cached.files.length} cached sounds`);
|
|
790
|
+
if (!cancelled) {
|
|
791
|
+
onDone({
|
|
792
|
+
files: cached.files.map((f) => ({
|
|
793
|
+
path: f.path,
|
|
794
|
+
name: f.name,
|
|
795
|
+
displayName: f.displayName,
|
|
796
|
+
category: f.category,
|
|
797
|
+
dir: dirname(f.path),
|
|
798
|
+
})),
|
|
799
|
+
categories: cached.categories,
|
|
800
|
+
fromCache: true,
|
|
801
|
+
});
|
|
802
|
+
}
|
|
803
|
+
return;
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
const outputDir = join(tmpdir(), "klonk-extract", game.name.replace(/[^a-zA-Z0-9]/g, "_"));
|
|
807
|
+
const allOutputs = [];
|
|
808
|
+
|
|
809
|
+
// Unity .resource files — extract FSB5 banks directly (no vgmstream needed for PCM16)
|
|
810
|
+
const fsbFiles = []; // Vorbis .fsb files that need vgmstream conversion
|
|
811
|
+
if (game.unityResources && game.unityResources.length > 0) {
|
|
812
|
+
setStatus(`Extracting Unity audio from ${game.unityResources.length} resource file(s)...`);
|
|
813
|
+
for (const resPath of game.unityResources) {
|
|
814
|
+
if (cancelled) return;
|
|
815
|
+
setStatus(`Extracting: ${basename(resPath)}`);
|
|
816
|
+
try {
|
|
817
|
+
const extracted = await extractUnityResource(resPath, outputDir);
|
|
818
|
+
for (const f of extracted) {
|
|
819
|
+
if (f.path.endsWith(".wav")) {
|
|
820
|
+
allOutputs.push(f.path);
|
|
821
|
+
} else if (f.path.endsWith(".fsb")) {
|
|
822
|
+
fsbFiles.push({ path: f.path, name: f.name });
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
setExtracted(allOutputs.length);
|
|
826
|
+
} catch { /* skip */ }
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
// Convert extracted .fsb Vorbis files via vgmstream, or handle traditional packed audio
|
|
831
|
+
const needsVgmstream = fsbFiles.length > 0 || (allOutputs.length === 0 && !game.unityResources?.length);
|
|
832
|
+
if (needsVgmstream) {
|
|
833
|
+
// Get vgmstream-cli (downloads if needed)
|
|
834
|
+
setStatus("Getting vgmstream-cli...");
|
|
835
|
+
const vgmstream = await getVgmstreamPath((msg) => {
|
|
836
|
+
if (!cancelled) setStatus(msg);
|
|
837
|
+
});
|
|
838
|
+
|
|
839
|
+
// Convert Unity-extracted .fsb files
|
|
840
|
+
for (const fsb of fsbFiles) {
|
|
841
|
+
if (cancelled) return;
|
|
842
|
+
setStatus(`Converting: ${fsb.name}`);
|
|
843
|
+
try {
|
|
844
|
+
const outputs = await extractToWav(fsb.path, outputDir, vgmstream);
|
|
845
|
+
allOutputs.push(...outputs);
|
|
846
|
+
setExtracted(allOutputs.length);
|
|
847
|
+
} catch { /* skip */ }
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
// Also scan for traditional packed audio (Wwise/FMOD)
|
|
851
|
+
if (allOutputs.length === 0 || !game.unityResources?.length) {
|
|
852
|
+
setStatus(`Scanning ${game.name} for packed audio...`);
|
|
853
|
+
const packedFiles = await findPackedAudioFiles(game.path, 30);
|
|
854
|
+
|
|
855
|
+
if (packedFiles.length === 0 && allOutputs.length === 0) {
|
|
856
|
+
if (!cancelled) onDone({ files: [], error: "No extractable audio files found" });
|
|
857
|
+
return;
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
setStatus(`Found ${packedFiles.length} files. Extracting...`);
|
|
861
|
+
|
|
862
|
+
for (const file of packedFiles) {
|
|
863
|
+
if (cancelled) return;
|
|
864
|
+
setStatus(`Extracting: ${file.name}`);
|
|
865
|
+
try {
|
|
866
|
+
const outputs = await extractToWav(file.path, outputDir, vgmstream);
|
|
867
|
+
allOutputs.push(...outputs);
|
|
868
|
+
setExtracted(allOutputs.length);
|
|
869
|
+
} catch {
|
|
870
|
+
// Skip files that fail
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
if (!cancelled) {
|
|
877
|
+
// Cache the results with category metadata
|
|
878
|
+
const rawFiles = allOutputs.map((p) => ({ path: p, name: basename(p) }));
|
|
879
|
+
setStatus("Caching extracted sounds...");
|
|
880
|
+
const manifest = await cacheExtraction(game.name, rawFiles, game.path);
|
|
881
|
+
|
|
882
|
+
onDone({
|
|
883
|
+
files: manifest.files.map((f) => ({
|
|
884
|
+
path: f.path,
|
|
885
|
+
name: f.name,
|
|
886
|
+
displayName: f.displayName,
|
|
887
|
+
category: f.category,
|
|
888
|
+
dir: dirname(f.path),
|
|
889
|
+
})),
|
|
890
|
+
categories: manifest.categories,
|
|
891
|
+
});
|
|
892
|
+
}
|
|
893
|
+
} catch (err) {
|
|
894
|
+
if (!cancelled) onDone({ files: [], error: err.message });
|
|
895
|
+
}
|
|
896
|
+
})();
|
|
897
|
+
|
|
898
|
+
return () => { cancelled = true; };
|
|
899
|
+
}, []);
|
|
900
|
+
|
|
901
|
+
return h(Box, { flexDirection: "column" },
|
|
902
|
+
h(Box, { marginLeft: 2, flexDirection: "column", borderStyle: "round", borderColor: ACCENT, paddingX: 2 },
|
|
903
|
+
h(Text, { bold: true, color: ACCENT }, `Extracting audio from ${game.name}`),
|
|
904
|
+
h(Box, { marginTop: 1 },
|
|
905
|
+
h(Text, { color: ACCENT }, h(Spinner, { type: "dots" })),
|
|
906
|
+
h(Text, null, ` ${status}`),
|
|
907
|
+
),
|
|
908
|
+
extracted > 0
|
|
909
|
+
? h(Text, { color: "green" }, ` ${extracted} sound(s) extracted so far`)
|
|
910
|
+
: null,
|
|
911
|
+
),
|
|
912
|
+
h(NavHint, { back: true }),
|
|
913
|
+
);
|
|
914
|
+
};
|
|
915
|
+
|
|
916
|
+
// ── Screen: Confirm ─────────────────────────────────────────────
|
|
917
|
+
const ConfirmScreen = ({ scope, sounds, onConfirm, onBack }) => {
|
|
918
|
+
useInput((_, key) => { if (key.escape) onBack(); });
|
|
919
|
+
|
|
920
|
+
const items = [
|
|
921
|
+
{ label: "✓ Yes, install!", value: "yes" },
|
|
922
|
+
{ label: "✗ No, go back", value: "no" },
|
|
923
|
+
];
|
|
924
|
+
|
|
925
|
+
const soundEntries = Object.entries(sounds).filter(([_, path]) => path);
|
|
926
|
+
|
|
927
|
+
return h(Box, { flexDirection: "column" },
|
|
928
|
+
h(Text, { bold: true, marginLeft: 2 }, " Ready to install:"),
|
|
929
|
+
h(Box, { marginTop: 1, flexDirection: "column" },
|
|
930
|
+
h(Text, { marginLeft: 4 }, `Scope: ${scope === "global" ? "Global (~/.claude)" : "This project (.claude/)"}`),
|
|
931
|
+
...soundEntries.map(([eid, path]) =>
|
|
932
|
+
h(Text, { key: eid, marginLeft: 4 },
|
|
933
|
+
`${EVENTS[eid].name} → ${basename(path)}`
|
|
934
|
+
)
|
|
935
|
+
),
|
|
936
|
+
),
|
|
937
|
+
h(Box, { marginTop: 1, marginLeft: 2 },
|
|
938
|
+
h(SelectInput, { indicatorComponent: Indicator, itemComponent: Item, items, onSelect: (item) => {
|
|
939
|
+
if (item.value === "yes") onConfirm();
|
|
940
|
+
else onBack();
|
|
941
|
+
}}),
|
|
942
|
+
),
|
|
943
|
+
h(NavHint, { back: true }),
|
|
944
|
+
);
|
|
945
|
+
};
|
|
946
|
+
|
|
947
|
+
// ── Screen: Installing ──────────────────────────────────────────
|
|
948
|
+
const InstallingScreen = ({ scope, sounds, onDone }) => {
|
|
949
|
+
useEffect(() => {
|
|
950
|
+
const validSounds = {};
|
|
951
|
+
for (const [eventId, path] of Object.entries(sounds)) {
|
|
952
|
+
if (path) validSounds[eventId] = path;
|
|
953
|
+
}
|
|
954
|
+
install({ scope, sounds: validSounds }).then(onDone).catch((err) => {
|
|
955
|
+
onDone({ error: err.message });
|
|
956
|
+
});
|
|
957
|
+
}, []);
|
|
958
|
+
|
|
959
|
+
return h(Box, { marginLeft: 2 },
|
|
960
|
+
h(Text, { color: ACCENT }, h(Spinner, { type: "dots" })),
|
|
961
|
+
h(Text, null, " Installing sounds..."),
|
|
962
|
+
);
|
|
963
|
+
};
|
|
964
|
+
|
|
965
|
+
// ── Screen: Done ────────────────────────────────────────────────
|
|
966
|
+
const DoneScreen = ({ result }) => {
|
|
967
|
+
const { exit } = useApp();
|
|
968
|
+
|
|
969
|
+
useEffect(() => {
|
|
970
|
+
// Play the "stop" sound as a demo if it was installed
|
|
971
|
+
if (result.installedSounds?.stop) {
|
|
972
|
+
playSoundWithCancel(result.installedSounds.stop).promise.catch(() => {});
|
|
973
|
+
}
|
|
974
|
+
const timer = setTimeout(() => exit(), 1500);
|
|
975
|
+
return () => clearTimeout(timer);
|
|
976
|
+
}, []);
|
|
977
|
+
|
|
978
|
+
if (result.error) {
|
|
979
|
+
return h(Box, { flexDirection: "column", marginLeft: 2 },
|
|
980
|
+
h(Text, { color: "red", bold: true }, " ✗ Installation failed:"),
|
|
981
|
+
h(Text, { color: "red" }, ` ${result.error}`),
|
|
982
|
+
);
|
|
983
|
+
}
|
|
984
|
+
|
|
985
|
+
return h(Box, { flexDirection: "column", marginLeft: 2 },
|
|
986
|
+
h(Text, { color: "green", bold: true }, " ✓ Sounds installed!"),
|
|
987
|
+
h(Box, { marginTop: 1, flexDirection: "column" },
|
|
988
|
+
h(Text, null, ` Sound files: ${result.soundsDir}`),
|
|
989
|
+
h(Text, null, ` Config: ${result.settingsFile}`),
|
|
990
|
+
),
|
|
991
|
+
h(Box, { marginTop: 1, flexDirection: "column" },
|
|
992
|
+
h(Text, null, " Your Claude Code sessions will now play sounds for:"),
|
|
993
|
+
...Object.keys(result.installedSounds).map((eventId) =>
|
|
994
|
+
h(Text, { key: eventId, color: "green" }, ` • ${EVENTS[eventId].name}`)
|
|
995
|
+
),
|
|
996
|
+
),
|
|
997
|
+
h(Box, { marginTop: 1 },
|
|
998
|
+
h(Text, { dimColor: true }, " To remove: npx klonk --uninstall"),
|
|
999
|
+
),
|
|
1000
|
+
);
|
|
1001
|
+
};
|
|
1002
|
+
|
|
1003
|
+
// ── Uninstall App ───────────────────────────────────────────────
|
|
1004
|
+
const UninstallApp = () => {
|
|
1005
|
+
const { exit } = useApp();
|
|
1006
|
+
const [phase, setPhase] = useState("scope"); // scope | working | done | notfound
|
|
1007
|
+
const [scope, setScope] = useState(null);
|
|
1008
|
+
|
|
1009
|
+
useEffect(() => {
|
|
1010
|
+
if (phase === "working" && scope) {
|
|
1011
|
+
uninstall(scope).then((ok) => {
|
|
1012
|
+
setPhase(ok ? "done" : "notfound");
|
|
1013
|
+
setTimeout(() => exit(), 500);
|
|
1014
|
+
});
|
|
1015
|
+
}
|
|
1016
|
+
}, [phase, scope]);
|
|
1017
|
+
|
|
1018
|
+
if (phase === "scope") {
|
|
1019
|
+
return h(Box, { flexDirection: "column" },
|
|
1020
|
+
h(Header, null),
|
|
1021
|
+
h(ScopeScreen, {
|
|
1022
|
+
onNext: (s) => { setScope(s); setPhase("working"); },
|
|
1023
|
+
}),
|
|
1024
|
+
);
|
|
1025
|
+
}
|
|
1026
|
+
|
|
1027
|
+
if (phase === "working") {
|
|
1028
|
+
return h(Box, { flexDirection: "column" },
|
|
1029
|
+
h(Header, null),
|
|
1030
|
+
h(Box, { marginLeft: 2 },
|
|
1031
|
+
h(Text, { color: ACCENT }, h(Spinner, { type: "dots" })),
|
|
1032
|
+
h(Text, null, " Removing sounds..."),
|
|
1033
|
+
),
|
|
1034
|
+
);
|
|
1035
|
+
}
|
|
1036
|
+
|
|
1037
|
+
if (phase === "done") {
|
|
1038
|
+
return h(Box, { flexDirection: "column" },
|
|
1039
|
+
h(Header, null),
|
|
1040
|
+
h(Text, { color: "green", marginLeft: 2 }, " ✓ Klonk hooks removed."),
|
|
1041
|
+
);
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
return h(Box, { flexDirection: "column" },
|
|
1045
|
+
h(Header, null),
|
|
1046
|
+
h(Text, { color: "yellow", marginLeft: 2 }, " No Klonk configuration found."),
|
|
1047
|
+
);
|
|
1048
|
+
};
|
|
1049
|
+
|
|
1050
|
+
// ── Main Install App ────────────────────────────────────────────
|
|
1051
|
+
const InstallApp = () => {
|
|
1052
|
+
const [screen, setScreen] = useState(SCREEN.SCOPE);
|
|
1053
|
+
const [scope, setScope] = useState(null);
|
|
1054
|
+
const [presetId, setPresetId] = useState(null);
|
|
1055
|
+
const [sounds, setSounds] = useState({});
|
|
1056
|
+
const [selectedGame, setSelectedGame] = useState(null);
|
|
1057
|
+
const [installResult, setInstallResult] = useState(null);
|
|
1058
|
+
|
|
1059
|
+
const initSoundsFromPreset = useCallback((pid) => {
|
|
1060
|
+
const preset = PRESETS[pid];
|
|
1061
|
+
if (preset) setSounds({ ...preset.sounds });
|
|
1062
|
+
}, []);
|
|
1063
|
+
|
|
1064
|
+
const content = (() => {
|
|
1065
|
+
switch (screen) {
|
|
1066
|
+
case SCREEN.SCOPE:
|
|
1067
|
+
return h(ScopeScreen, {
|
|
1068
|
+
onNext: (s) => {
|
|
1069
|
+
setScope(s);
|
|
1070
|
+
getExistingSounds(s).then((existing) => {
|
|
1071
|
+
if (Object.keys(existing).length > 0) setSounds(existing);
|
|
1072
|
+
});
|
|
1073
|
+
setScreen(SCREEN.PRESET);
|
|
1074
|
+
},
|
|
1075
|
+
});
|
|
1076
|
+
|
|
1077
|
+
case SCREEN.PRESET:
|
|
1078
|
+
return h(PresetScreen, {
|
|
1079
|
+
onNext: (id) => {
|
|
1080
|
+
if (id === "_scan") {
|
|
1081
|
+
setScreen(SCREEN.GAME_PICK);
|
|
1082
|
+
} else if (id === "_custom") {
|
|
1083
|
+
const firstPreset = Object.keys(PRESETS)[0];
|
|
1084
|
+
setPresetId(firstPreset);
|
|
1085
|
+
initSoundsFromPreset(firstPreset);
|
|
1086
|
+
setScreen(SCREEN.PREVIEW);
|
|
1087
|
+
} else {
|
|
1088
|
+
setPresetId(id);
|
|
1089
|
+
initSoundsFromPreset(id);
|
|
1090
|
+
setScreen(SCREEN.PREVIEW);
|
|
1091
|
+
}
|
|
1092
|
+
},
|
|
1093
|
+
onBack: () => setScreen(SCREEN.SCOPE),
|
|
1094
|
+
});
|
|
1095
|
+
|
|
1096
|
+
case SCREEN.PREVIEW:
|
|
1097
|
+
return h(PreviewScreen, {
|
|
1098
|
+
presetId,
|
|
1099
|
+
sounds,
|
|
1100
|
+
onAccept: (finalSounds) => {
|
|
1101
|
+
setSounds(finalSounds);
|
|
1102
|
+
setScreen(SCREEN.CONFIRM);
|
|
1103
|
+
},
|
|
1104
|
+
onBack: () => setScreen(SCREEN.PRESET),
|
|
1105
|
+
onUpdateSound: (eventId, path) => {
|
|
1106
|
+
setSounds((prev) => {
|
|
1107
|
+
const next = { ...prev };
|
|
1108
|
+
if (path === null) delete next[eventId];
|
|
1109
|
+
else next[eventId] = path;
|
|
1110
|
+
return next;
|
|
1111
|
+
});
|
|
1112
|
+
},
|
|
1113
|
+
});
|
|
1114
|
+
|
|
1115
|
+
case SCREEN.GAME_PICK:
|
|
1116
|
+
return h(GamePickScreen, {
|
|
1117
|
+
onNext: (gameName, gamesList) => {
|
|
1118
|
+
const game = gamesList.find((g) => g.name === gameName);
|
|
1119
|
+
const catFiles = categorizeLooseFiles(game.files);
|
|
1120
|
+
setSelectedGame({ ...game, files: catFiles });
|
|
1121
|
+
setScreen(SCREEN.GAME_SOUNDS);
|
|
1122
|
+
},
|
|
1123
|
+
onExtract: (gameName, gamesList) => {
|
|
1124
|
+
const game = gamesList.find((g) => g.name === gameName);
|
|
1125
|
+
setSelectedGame(game);
|
|
1126
|
+
setScreen(SCREEN.EXTRACTING);
|
|
1127
|
+
},
|
|
1128
|
+
onBack: () => setScreen(SCREEN.PRESET),
|
|
1129
|
+
});
|
|
1130
|
+
|
|
1131
|
+
case SCREEN.GAME_SOUNDS:
|
|
1132
|
+
return h(GameSoundsScreen, {
|
|
1133
|
+
game: selectedGame,
|
|
1134
|
+
sounds,
|
|
1135
|
+
onSelectSound: (eventId, path) => {
|
|
1136
|
+
setSounds((prev) => ({ ...prev, [eventId]: path }));
|
|
1137
|
+
},
|
|
1138
|
+
onDone: () => {
|
|
1139
|
+
setScreen(SCREEN.CONFIRM);
|
|
1140
|
+
},
|
|
1141
|
+
onBack: () => setScreen(SCREEN.GAME_PICK),
|
|
1142
|
+
});
|
|
1143
|
+
|
|
1144
|
+
case SCREEN.EXTRACTING:
|
|
1145
|
+
return h(ExtractingScreen, {
|
|
1146
|
+
game: selectedGame,
|
|
1147
|
+
onDone: (result) => {
|
|
1148
|
+
if (result.error || result.files.length === 0) {
|
|
1149
|
+
// Go back to game pick — extraction failed
|
|
1150
|
+
setScreen(SCREEN.GAME_PICK);
|
|
1151
|
+
} else {
|
|
1152
|
+
// Update the selected game with extracted files and go to sound picker
|
|
1153
|
+
setSelectedGame({
|
|
1154
|
+
...selectedGame,
|
|
1155
|
+
files: result.files,
|
|
1156
|
+
fileCount: result.files.length,
|
|
1157
|
+
hasAudio: true,
|
|
1158
|
+
});
|
|
1159
|
+
setScreen(SCREEN.GAME_SOUNDS);
|
|
1160
|
+
}
|
|
1161
|
+
},
|
|
1162
|
+
onBack: () => setScreen(SCREEN.GAME_PICK),
|
|
1163
|
+
});
|
|
1164
|
+
|
|
1165
|
+
case SCREEN.CONFIRM:
|
|
1166
|
+
return h(ConfirmScreen, {
|
|
1167
|
+
scope,
|
|
1168
|
+
sounds,
|
|
1169
|
+
onConfirm: () => setScreen(SCREEN.INSTALLING),
|
|
1170
|
+
onBack: () => {
|
|
1171
|
+
if (selectedGame) setScreen(SCREEN.GAME_SOUNDS);
|
|
1172
|
+
else setScreen(SCREEN.PREVIEW);
|
|
1173
|
+
},
|
|
1174
|
+
});
|
|
1175
|
+
|
|
1176
|
+
case SCREEN.INSTALLING:
|
|
1177
|
+
return h(InstallingScreen, {
|
|
1178
|
+
scope,
|
|
1179
|
+
sounds,
|
|
1180
|
+
onDone: (result) => {
|
|
1181
|
+
setInstallResult(result);
|
|
1182
|
+
setScreen(SCREEN.DONE);
|
|
1183
|
+
},
|
|
1184
|
+
});
|
|
1185
|
+
|
|
1186
|
+
case SCREEN.DONE:
|
|
1187
|
+
return h(DoneScreen, { result: installResult });
|
|
1188
|
+
|
|
1189
|
+
default:
|
|
1190
|
+
return h(Text, { color: "red" }, "Unknown screen");
|
|
1191
|
+
}
|
|
1192
|
+
})();
|
|
1193
|
+
|
|
1194
|
+
return h(Box, { flexDirection: "column" },
|
|
1195
|
+
h(Header, null),
|
|
1196
|
+
content,
|
|
1197
|
+
);
|
|
1198
|
+
};
|
|
1199
|
+
|
|
1200
|
+
// ── Entry ───────────────────────────────────────────────────────
|
|
1201
|
+
export async function run() {
|
|
1202
|
+
const AppComponent = isUninstallMode ? UninstallApp : InstallApp;
|
|
1203
|
+
const instance = render(h(AppComponent));
|
|
1204
|
+
await instance.waitUntilExit();
|
|
1205
|
+
}
|