-
-
Notifications
You must be signed in to change notification settings - Fork 622
Expand file tree
/
Copy pathindex.ts
More file actions
890 lines (845 loc) · 22.9 KB
/
Copy pathindex.ts
File metadata and controls
890 lines (845 loc) · 22.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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
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
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
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
548
549
550
551
552
553
554
555
556
557
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
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
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
888
889
890
import cronstrue from "cronstrue";
import { formatDistanceToNow } from "date-fns";
import { storeToRefs } from "pinia";
import { computed } from "vue";
import { useDisplay } from "vuetify";
import type { RomFileSchema, RomUserStatus } from "@/__generated__";
import type { Config } from "@/stores/config";
import type { Heartbeat } from "@/stores/heartbeat";
import storeNavigation from "@/stores/navigation";
import type { DetailedRom, SimpleRom } from "@/stores/roms";
/**
* Views configuration object.
*/
export const views: Record<
number,
{
view: string;
icon: string;
"size-xl": number;
"size-lg": number;
"size-md": number;
"size-sm": number;
"size-cols": number;
}
> = {
0: {
view: "small",
icon: "mdi-view-comfy",
"size-cols": 4,
"size-sm": 2,
"size-md": 2,
"size-lg": 1,
"size-xl": 1,
},
1: {
view: "big",
icon: "mdi-view-module",
"size-cols": 6,
"size-sm": 3,
"size-md": 3,
"size-lg": 2,
"size-xl": 2,
},
2: {
view: "list",
icon: "mdi-view-list",
"size-cols": 12,
"size-sm": 12,
"size-md": 12,
"size-lg": 12,
"size-xl": 12,
},
};
/**
* Get icon associated to role.
*
* @param role The role as string.
* @returns The mdi icon string.
*/
export function getRoleIcon(role: string) {
switch (role) {
case "admin":
return "mdi-shield-crown-outline";
case "user":
return "mdi-account-outline";
// Legacy roles, kept so any lingering value still renders an icon.
case "editor":
return "mdi-file-edit-outline";
case "viewer":
return "mdi-book-open-variant-outline";
default:
return "mdi-account";
}
}
/**
* Default path for user avatars.
*/
export const defaultAvatarPath = "/assets/default/user.svg";
/**
* Normalize a string by converting it to lowercase and removing diacritics.
*
* @param s The string to normalize.
* @returns The normalized string.
*/
export function normalizeString(s: string) {
return s
.toLowerCase()
.normalize("NFD")
.replace(/[\u0300-\u036f]/g, "");
}
/**
* Convert a cron expression to a human-readable string.
*
* @param expression The cron expression to convert.
* @returns The human-readable string.
*/
export function convertCronExperssion(expression: string) {
let convertedExpression = cronstrue.toString(expression, { verbose: true });
convertedExpression =
convertedExpression.charAt(0).toLocaleLowerCase() +
convertedExpression.substr(1);
return convertedExpression;
}
/**
* Generate a download link for ROM content.
*
* @param rom The ROM object.
* @param files Optional array of file names to include in the download.
* @returns The download link.
*/
export function getDownloadPath({
rom,
fileIDs = [],
}: {
rom: SimpleRom;
fileIDs?: number[];
}) {
const queryParams = new URLSearchParams();
if (fileIDs.length > 0) {
queryParams.append("file_ids", fileIDs.join(","));
}
const queryString = queryParams.toString();
// When a single file is selected, use its real name (extension included) as
// the path segment. EmulatorJS derives the on-disk filename, and therefore
// the file format handed to the core, from the URL. Multi-file roms have no
// root extension (`fs_name` is the folder name), so falling back to it would
// give the core an extension-less file and fail with "Unsupported file format".
const selectedFile =
fileIDs.length === 1
? rom.files?.find((f) => f.id === fileIDs[0])
: undefined;
const contentName = selectedFile?.file_name ?? rom.fs_name;
return `/api/roms/${rom.id}/content/${contentName}${
queryString ? `?${queryString}` : ""
}`;
}
export function getDownloadLink({
rom,
fileIDs = [],
}: {
rom: SimpleRom;
fileIDs?: number[];
}) {
return `${window.location.origin}${encodeURI(
getDownloadPath({ rom, fileIDs }),
)}`;
}
/**
* Format bytes as human-readable text.
*
* @param bytes Number of bytes.
* @param decimals Number of decimal places to display.
* @returns Formatted string.
*/
export function formatBytes(bytes: number, decimals = 2) {
if (bytes === 0) return "0 Bytes";
const k = 1024;
const dm = Math.max(0, decimals);
const sizes = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`;
}
/**
* Convert locale format from app format (fr_FR) to browser format (fr-FR).
*
* @param locale The locale string (e.g., "fr_FR" or "fr-FR").
* @returns The browser-compatible locale string (e.g., "fr-FR").
*/
export function toBrowserLocale(locale: string): string {
return locale.replace("_", "-");
}
/**
* Format a timestamp to a human-readable string.
*
* @param timestamp The timestamp to format.
* @param locale The locale to use for formatting (e.g., "fr_FR" or "fr-FR"). Defaults to "en-US".
* @returns The formatted timestamp.
*/
export function formatTimestamp(
timestamp: string | null,
locale: string = "en-US",
) {
if (!timestamp) return "-";
const date = new Date(timestamp);
return date.toLocaleString(toBrowserLocale(locale));
}
/**
* Format a date to a relative time string (e.g., "3 days ago").
* @param date The date to format.
* @returns The relative time string.
*/
export function formatRelativeDate(date: string | Date) {
return formatDistanceToNow(new Date(date), { addSuffix: true });
}
/**
* Convert a region code to an emoji.
*
* @param region The region code.
* @returns The corresponding emoji.
*/
export function regionToEmoji(region: string) {
switch (region.toLowerCase()) {
case "as":
case "australia":
return "🇦🇺";
case "a":
case "asia":
return "🌏";
case "b":
case "bra":
case "brazil":
return "🇧🇷";
case "c":
case "canada":
return "🇨🇦";
case "ch":
case "chn":
case "china":
return "🇨🇳";
case "e":
case "eu":
case "eur":
case "europe":
return "🇪🇺";
case "f":
case "france":
return "🇫🇷";
case "fn":
case "finland":
return "🇫🇮";
case "g":
case "germany":
return "🇩🇪";
case "gr":
case "greece":
return "🇬🇷";
case "h":
case "holland":
return "🇳🇱";
case "hk":
case "hong kong":
return "🇭🇰";
case "i":
case "italy":
return "🇮🇹";
case "j":
case "jp":
case "japan":
return "🇯🇵";
case "k":
case "korea":
return "🇰🇷";
case "nl":
case "netherlands":
return "🇳🇱";
case "no":
case "norway":
return "🇳🇴";
case "r":
case "russia":
return "🇷🇺";
case "s":
case "spain":
return "🇪🇸";
case "sw":
case "sweden":
return "🇸🇪";
case "t":
case "taiwan":
return "🇹🇼";
case "u":
case "us":
case "usa":
return "🇺🇸";
case "uk":
case "england":
return "🇬🇧";
case "unk":
case "unknown":
return "🌎";
case "unl":
case "unlicensed":
return "🌎";
case "w":
case "global":
case "world":
return "🌎";
default:
return region;
}
}
/**
* Convert a language code to an emoji.
*
* @param language The language code.
* @returns The corresponding emoji.
*/
export function languageToEmoji(language: string) {
switch (language.toLowerCase()) {
case "af":
case "afrikaans":
return "🇿🇦";
case "ar":
case "arabic":
return "🇦🇪";
case "be":
case "belarusian":
return "🇧🇾";
case "bg":
case "bulgarian":
return "🇧🇬";
case "ca":
case "catalan":
return "🇦🇩";
case "cs":
case "czech":
return "🇨🇿";
case "da":
case "danish":
return "🇩🇰";
case "de":
case "german":
return "🇩🇪";
case "el":
case "greek":
return "🇬🇷";
case "en":
case "english":
return "🇬🇧";
case "es":
case "spanish":
return "🇪🇸";
case "et":
case "estonian":
return "🇪🇪";
case "fi":
case "finnish":
return "🇫🇮";
case "fr":
case "french":
return "🇫🇷";
case "he":
case "hebrew":
return "🇮🇱";
case "hi":
case "hindi":
return "🇮🇳";
case "hr":
case "croatian":
return "🇭🇷";
case "hu":
case "hungarian":
return "🇭🇺";
case "hy":
case "armenian":
return "🇦🇲";
case "id":
case "indonesian":
return "🇮🇩";
case "is":
case "icelandic":
return "🇮🇸";
case "it":
case "italian":
return "🇮🇹";
case "ja":
case "japanese":
return "🇯🇵";
case "ko":
case "korean":
return "🇰🇷";
case "la":
case "latin":
return "🇻🇦";
case "lt":
case "lithuanian":
return "🇱🇹";
case "lv":
case "latvian":
return "🇱🇻";
case "mk":
case "macedonian":
return "🇲🇰";
case "nl":
case "dutch":
return "🇳🇱";
case "no":
case "norwegian":
return "🇳🇴";
case "pl":
case "polish":
return "🇵🇱";
case "pt":
case "portuguese":
return "🇵🇹";
case "ro":
case "romanian":
return "🇷🇴";
case "ru":
case "russian":
return "🇷🇺";
case "sk":
case "slovak":
return "🇸🇰";
case "sl":
case "slovenian":
return "🇸🇮";
case "sq":
case "albanian":
return "🇦🇱";
case "sr":
case "serbian":
return "🇷🇸";
case "sv":
case "swedish":
return "🇸🇪";
case "th":
case "thai":
return "🇹🇭";
case "tr":
case "turkish":
return "🇹🇷";
case "uk":
case "ukrainian":
return "🇺🇦";
case "vi":
case "vietnamese":
return "🇻🇳";
case "zh":
case "chinese":
return "🇨🇳";
case "nolang":
case "no language":
return "🌎";
default:
return language;
}
}
/**
* Map of supported EJS cores for each platform.
*/
const _EJS_CORES_MAP: Record<string, string[]> = {
"3do": ["opera"],
acpc: ["cap32", "crocods"],
amiga: ["puae"],
"amiga-cd32": ["puae"],
arcade: [
"mame2003",
"mame2003_plus",
"fbneo",
"fbalpha2012_cps1",
"fbalpha2012_cps2",
],
neogeoaes: ["fbneo"],
neogeomvs: ["fbneo"],
atari2600: ["stella2014"],
"atari-2600-plus": ["stella2014"],
atari5200: ["a5200"],
atari7800: ["prosystem"],
"c-plus-4": ["vice_xplus4"],
c64: ["vice_x64sc", "vice_x64"],
cpet: ["vice_xpet"],
"commodore-64c": ["vice_x64sc", "vice_x64"],
c128: ["vice_x128"],
"commmodore-128": ["vice_x128"],
colecovision: ["gearcoleco"],
doom: ["prboom"],
dos: ["dosbox_pure"],
jaguar: ["virtualjaguar"],
lynx: ["handy"],
"atari-lynx-mkii": ["handy"],
"neo-geo-pocket": ["mednafen_ngp"],
"neo-geo-pocket-color": ["mednafen_ngp"],
nes: ["fceumm", "nestopia"],
famicom: ["fceumm", "nestopia"],
fds: ["fceumm", "nestopia"],
"game-televisison": ["fceumm"],
"new-style-nes": ["fceumm"],
n64: ["mupen64plus_next", "parallel_n64"],
"ique-player": ["mupen64plus_next"],
nds: ["melonds", "desmume", "desmume2015"],
"nintendo-ds-lite": ["melonds", "desmume", "desmume2015"],
"nintendo-dsi": ["melonds", "desmume", "desmume2015"],
"nintendo-dsi-xl": ["melonds", "desmume", "desmume2015"],
gb: ["gambatte", "mgba"],
"game-boy-pocket": ["gambatte", "mgba"],
"game-boy-light": ["gambatte", "mgba"],
gba: ["mgba"],
"game-boy-adavance-sp": ["mgba"],
"game-boy-micro": ["mgba"],
gbc: ["gambatte", "mgba"],
"pc-fx": ["mednafen_pcfx"],
psx: ["pcsx_rearmed", "mednafen_psx_hw"],
"philips-cd-i": ["same_cdi"],
psp: ["ppsspp"],
segacd: ["genesis_plus_gx", "picodrive"],
sega32: ["picodrive"],
gamegear: ["genesis_plus_gx"],
sms: ["genesis_plus_gx"],
"sega-mark-iii": ["genesis_plus_gx"],
"sega-game-box-9": ["genesis_plus_gx"],
"sega-master-system-ii": ["genesis_plus_gx", "smsplus"],
"master-system-super-compact": ["genesis_plus_gx"],
"master-system-girl": ["genesis_plus_gx"],
genesis: ["genesis_plus_gx"],
"sega-mega-drive-2-slash-genesis": ["genesis_plus_gx"],
"sega-mega-jet": ["genesis_plus_gx"],
"mega-pc": ["genesis_plus_gx"],
"tera-drive": ["genesis_plus_gx"],
"sega-nomad": ["genesis_plus_gx"],
saturn: ["yabause"],
snes: ["snes9x"],
sfam: ["snes9x"],
"super-nintendo-original-european-version": ["snes9x"],
"super-famicom-shvc-001": ["snes9x"],
"super-famicom-jr-model-shvc-101": ["snes9x"],
"new-style-super-nes-model-sns-101": ["snes9x"],
tg16: ["mednafen_pce"],
"turbografx-cd": ["mednafen_pce"],
supergrafx: ["mednafen_pce"],
"vic-20": ["vice_xvic"],
virtualboy: ["beetle_vb"],
wonderswan: ["mednafen_wswan"],
swancrystal: ["mednafen_wswan"],
"wonderswan-color": ["mednafen_wswan"],
zxs: ["fuse"],
} as const;
// TODO: Merge with _EJS_CORES_MAP next emukatorjs release (post 4.2.3)
const _EJS_NIGHTLY_CORES_MAP: Record<string, string[]> = {
"3ds": ["azahar"],
"new-nintendo-3ds": ["azahar"],
intellivision: ["freeintv"],
segacd: ["genesis_plus_gx", "genesis_plus_gx_wide", "picodrive"],
gamegear: ["genesis_plus_gx", "genesis_plus_gx_wide"],
sms: ["genesis_plus_gx", "genesis_plus_gx_wide"],
"sega-mark-iii": ["genesis_plus_gx", "genesis_plus_gx_wide"],
"sega-game-box-9": ["genesis_plus_gx", "genesis_plus_gx_wide"],
"sega-master-system-ii": [
"genesis_plus_gx",
"genesis_plus_gx_wide",
"smsplus",
],
"master-system-super-compact": ["genesis_plus_gx", "genesis_plus_gx_wide"],
"master-system-girl": ["genesis_plus_gx", "genesis_plus_gx_wide"],
genesis: ["genesis_plus_gx", "genesis_plus_gx_wide"],
"sega-mega-drive-2-slash-genesis": [
"genesis_plus_gx",
"genesis_plus_gx_wide",
],
"sega-mega-jet": ["genesis_plus_gx", "genesis_plus_gx_wide"],
"mega-pc": ["genesis_plus_gx", "genesis_plus_gx_wide"],
"tera-drive": ["genesis_plus_gx", "genesis_plus_gx_wide"],
"sega-nomad": ["genesis_plus_gx", "genesis_plus_gx_wide"],
snes: ["snes9x", "bsnes"],
sfam: ["snes9x", "bsnes"],
"super-nintendo-original-european-version": ["snes9x", "bsnes"],
"super-famicom-shvc-001": ["snes9x", "bsnes"],
"super-famicom-jr-model-shvc-101": ["snes9x", "bsnes"],
"new-style-super-nes-model-sns-101": ["snes9x", "bsnes"],
};
export type EJSPlatformSlug = keyof typeof _EJS_CORES_MAP;
/**
* Get the supported EJS cores for a given platform.
*
* @param platformSlug The platform slug.
* @param netplayEnabled Pull nightly cores if netplay is enabled.
* @returns An array of supported cores.
*/
export function getSupportedEJSCores(
platformSlug: string,
netplayEnabled: boolean = false,
): string[] {
const coresMap = netplayEnabled
? { ..._EJS_CORES_MAP, ..._EJS_NIGHTLY_CORES_MAP }
: _EJS_CORES_MAP;
return coresMap[platformSlug.toLowerCase() as EJSPlatformSlug] || [];
}
/**
* Check if a given EJS core requires threads enabled.
*
* @param core The core name.
* @returns True if threads are required, false otherwise.
*/
export function areThreadsRequiredForEJSCore(core: string): boolean {
return ["dosbox_pure", "ppsspp", "azahar"].includes(core);
}
const canvas = document.createElement("canvas");
const gl =
canvas.getContext("webgl") || canvas.getContext("experimental-webgl");
/**
* Check if EJS emulation is supported for a given platform.
*
* @param platformSlug The platform slug.
* @param heartbeat The heartbeat object.
* @param config Optional configuration object.
* @returns True if supported, false otherwise.
*/
export function isEJSEmulationSupported(
platformSlug: string,
heartbeat: Heartbeat,
config?: Config,
) {
if (heartbeat.EMULATION.DISABLE_EMULATOR_JS) return false;
const slug = config?.PLATFORMS_VERSIONS[platformSlug] || platformSlug;
return (
getSupportedEJSCores(slug, config?.EJS_NETPLAY_ENABLED).length > 0 &&
gl instanceof WebGLRenderingContext
);
}
// This is a workaround to set the control scheme for Sega systems using the same cores
const _EJS_CONTROL_SCHEMES = {
segacd: "segaCD",
sega32: "sega32x",
gamegear: "segaGG",
sms: "segaMS",
"sega-mark-iii": "segaMS",
"sega-master-system-ii": "segaMS",
"master-system-super-compact": "segaMS",
"master-system-girl": "segaMS",
genesis: "segaMD",
"sega-mega-drive-2-slash-genesis": "segaMD",
"sega-mega-jet": "segaMD",
"mega-pc": "segaMD",
"tera-drive": "segaMD",
"sega-nomad": "segaMD",
saturn: "segaSaturn",
};
type EJSControlSlug = keyof typeof _EJS_CONTROL_SCHEMES;
/**
* Get the control scheme for a given platform.
*
* @param platformSlug The platform slug.
* @returns The control scheme.
*/
export function getControlSchemeForPlatform(
platformSlug: string,
): string | null {
return platformSlug in _EJS_CONTROL_SCHEMES
? _EJS_CONTROL_SCHEMES[platformSlug as EJSControlSlug]
: null;
}
/**
* Check if Ruffle emulation is supported for a given platform.
*
* @param platformSlug The platform slug.
* @param heartbeat The heartbeat object.
* @param config Optional configuration object.
* @returns True if supported, false otherwise.
*/
export function isRuffleEmulationSupported(
platformSlug: string,
heartbeat: Heartbeat,
config?: Config,
) {
if (heartbeat.EMULATION.DISABLE_RUFFLE_RS) return false;
const slug = config?.PLATFORMS_VERSIONS[platformSlug] || platformSlug;
return ["flash", "browser"].includes(slug.toLowerCase());
}
export type PlayingStatus =
RomUserStatus | "backlogged" | "now_playing" | "hidden";
/**
* Map of ROM statuses to their corresponding emoji, text, and i18n key.
*/
export const romStatusMap: Record<
PlayingStatus,
{ emoji: string; text: string; i18nKey: string }
> = {
backlogged: {
emoji: "🔜",
text: "Backlogged",
i18nKey: "rom.status-backlogged",
},
now_playing: {
emoji: "🕹️",
text: "Now Playing",
i18nKey: "rom.status-now-playing",
},
incomplete: {
emoji: "🚧",
text: "Incomplete",
i18nKey: "rom.status-incomplete",
},
finished: { emoji: "🏁", text: "Finished", i18nKey: "rom.status-finished" },
completed_100: {
emoji: "💯",
text: "Completed 100%",
i18nKey: "rom.status-completed-100",
},
retired: { emoji: "🏴", text: "Retired", i18nKey: "rom.status-retired" },
never_playing: {
emoji: "🚫",
text: "Never Playing",
i18nKey: "rom.status-never-playing",
},
hidden: { emoji: "👻", text: "Hidden", i18nKey: "rom.status-hidden" },
};
/**
* Get the emoji for a given ROM status.
*
* @param status The ROM status.
* @returns The corresponding emoji.
*/
export function getEmojiForStatus(status: PlayingStatus) {
if (status) {
return romStatusMap[status].emoji;
} else {
return null;
}
}
/**
* Get the text for a given ROM status.
*
* @param status The ROM status.
* @returns The corresponding text.
*/
export function getTextForStatus(status: PlayingStatus): string | null {
return romStatusMap[status]?.text ?? null;
}
/**
* Get the i18n key for a given ROM status.
*
* @param status The ROM status.
* @returns The corresponding i18n key (e.g., "rom.status-backlogged").
*/
export function getI18nKeyForStatus(status: PlayingStatus): string | null {
return romStatusMap[status]?.i18nKey ?? null;
}
export function isNintendoDSFile(rom: SimpleRom): boolean {
return ["cia", "nds", "3ds", "dsi"].includes(rom.fs_extension.toLowerCase());
}
export function getNintendoDSFiles(
rom: DetailedRom | SimpleRom,
): RomFileSchema[] {
// `files` only ships on DetailedRom. Gallery surfaces pass SimpleRom,
// where the inner-file check is impossible — return an empty list so
// the caller falls back to the extension check.
const files = (rom as DetailedRom).files;
if (!files) return [];
return files.filter((file) => {
const fileName = file.file_name.toLowerCase();
return (
fileName.endsWith(".cia") ||
fileName.endsWith(".nds") ||
fileName.endsWith(".3ds") ||
fileName.endsWith(".dsi")
);
});
}
/**
* Check if a ROM is a valid NDS/3DS/DSi game.
*
* Accepts both SimpleRom (gallery cards) and DetailedRom (detail view).
* With SimpleRom the inner-file check is skipped — only the root
* extension counts — which is what every gallery surface can ever see.
*/
export function isNintendoDSRom(rom: DetailedRom | SimpleRom): boolean {
if (
!["3ds", "nds", "new-nintendo-3ds", "nintendo-dsi"].includes(
rom.platform_slug,
)
)
return false;
const hasValidExtension = isNintendoDSFile(rom);
const hasValidFile = getNintendoDSFiles(rom).length > 0;
return hasValidExtension || hasValidFile;
}
export function calculateMainLayoutWidth() {
const { smAndDown } = useDisplay();
const navigationStore = storeNavigation();
const { mainBarCollapsed } = storeToRefs(navigationStore);
const calculatedWidth = computed(() => {
return smAndDown.value
? "calc(100% - 16px) !important"
: mainBarCollapsed.value
? "calc(100% - 76px) !important"
: "calc(100% - 106px) !important";
});
return { calculatedWidth };
}
/**
* Get the icon for a given platform category.
*
* @param category The platform category.
* @returns The corresponding icon.
*/
export function platformCategoryToIcon(category: string) {
if (!category) return "";
switch (category.toLowerCase()) {
case "console":
return "mdi-gamepad-variant";
case "computer":
return "mdi-desktop-classic";
case "portable console":
return "mdi-nintendo-game-boy";
case "arcade":
return "mdi-gamepad-circle";
case "operating system":
return "mdi-monitor-shimmer";
case "platform":
return "mdi-desktop-tower-monitor";
case "unknown":
default:
return "";
}
}
export const FRONTEND_RESOURCES_PATH = "/assets/romm/resources";
export const CD_BASED_SYSTEMS = new Set([
"3do", // 3DO
"amiga-cd32", // Amiga CD32
"atari-jaguar-cd", // Atari Jaguar CD
"philips-cd-i", // Philips CD-i
"commodore-cdtv", // Commodore CDTV
"dc", // Dreamcast
"fm-towns", // FM Towns
"hyperscan", // HyperScan
"laseractive", // LaserActive
"neo-geo-cd", // Neo Geo CD
"ngc", // Nintendo GameCube
"pc-fx", // PC-FX
"psx", // PlayStation
"ps2", // PlayStation 2
"ps3", // PlayStation 3
"ps4", // PlayStation 4
"ps5", // PlayStation 5
"psp", // PlayStation Portable
"segacd", // Sega CD
"series-x-s", // Xbox Series X/S
"saturn", // Sega Saturn
"super-nes-cd-rom-system", // Super NES CD-ROM System
"tandy-vis", // Tandy Video Information System
"turbografx-cd", // TurboGrafx-CD
"vflash", // V.Flash
"wii", // Wii
"wiiu", // Wii U
"xbox", // Xbox
"xbox360", // Xbox 360
"xboxone", // Xbox One
]);
export function isCDBasedSystem(platformSlug: string): boolean {
return CD_BASED_SYSTEMS.has(platformSlug.toLowerCase());
}
export const ARCADE_SYSTEMS = new Set(["arcade", "neogeoaes", "neogeomvs"]);
export function isArcadeSystem(platformSlug: string): boolean {
return ARCADE_SYSTEMS.has(platformSlug.toLowerCase());
}