From 19cd89f0b3423169144236414bdd78a3afe116e1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jo=C3=A3o=20Magalh=C3=A3es?= <joamag@gmail.com>
Date: Fri, 11 Nov 2022 09:48:51 +0000
Subject: [PATCH] feat: rom extension format

---
 examples/web/index.ts      |  5 ++++-
 examples/web/react/app.tsx | 11 ++++++++---
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/examples/web/index.ts b/examples/web/index.ts
index 94c795f1..4fd1abe1 100644
--- a/examples/web/index.ts
+++ b/examples/web/index.ts
@@ -338,7 +338,6 @@ class GameboyEmulator extends EmulatorBase implements Emulator {
         this.trigger("booted");
     }
 
-    // @todo remove this method, or at least most of it
     async register() {
         await Promise.all([this.registerKeys()]);
     }
@@ -410,6 +409,10 @@ class GameboyEmulator extends EmulatorBase implements Emulator {
         return "https://gitlab.stage.hive.pt/joamag/boytacean/-/blob/master/CHANGELOG.md";
     }
 
+    get romExts(): string[] {
+        return ["gb"];
+    }
+
     get pixelFormat(): PixelFormat {
         return PixelFormat.RGB;
     }
diff --git a/examples/web/react/app.tsx b/examples/web/react/app.tsx
index 8e4167f9..f8982e18 100644
--- a/examples/web/react/app.tsx
+++ b/examples/web/react/app.tsx
@@ -130,6 +130,12 @@ export interface Emulator extends ObservableI {
      */
     get engine(): string | null;
 
+    /**
+     * The complete set of file extensions that this emulator
+     * supports.
+     */
+    get romExts(): string[];
+
     /**
      * The pixel format of the emulator's display
      * image buffer (eg: RGB).
@@ -363,9 +369,8 @@ export const App: FC<AppProps> = ({
     };
 
     const onFile = async (file: File) => {
-        // @todo must make this more flexible and not just
-        // Game Boy only (using the emulator interface)
-        if (!file.name.endsWith(".gb")) {
+        const fileExtension = file.name.split(".").pop() ?? "";
+        if (!emulator.romExts.includes(fileExtension)) {
             showToast(
                 `This is probably not a ${emulator.device} ROM file!`,
                 true
-- 
GitLab