[gnome-games/wip/exalm/rebrand: 80/124] wii: Migrate to a game parser




commit 4f32a968e02df67034b88c18a4374a6064f50e6c
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Tue Mar 30 04:02:51 2021 +0500

    wii: Migrate to a game parser

 plugins/wii/src/meson.build     |  1 +
 plugins/wii/src/wii-parser.vala | 24 ++++++++++++++++++++++++
 plugins/wii/src/wii-plugin.vala | 27 ++-------------------------
 3 files changed, 27 insertions(+), 25 deletions(-)
---
diff --git a/plugins/wii/src/meson.build b/plugins/wii/src/meson.build
index 8141c95a..6ad57ea1 100644
--- a/plugins/wii/src/meson.build
+++ b/plugins/wii/src/meson.build
@@ -1,5 +1,6 @@
 vala_sources = [
   'wii-header.vala',
+  'wii-parser.vala',
   'wii-plugin.vala',
 ]
 
diff --git a/plugins/wii/src/wii-parser.vala b/plugins/wii/src/wii-parser.vala
new file mode 100644
index 00000000..7c4ff86e
--- /dev/null
+++ b/plugins/wii/src/wii-parser.vala
@@ -0,0 +1,24 @@
+// This file is part of GNOME Games. License: GPL-3.0+.
+
+public class Games.WiiParser : GameParser {
+       private string uid;
+
+       public WiiParser (Platform platform, Uri uri) {
+               base (platform, uri);
+       }
+
+       public override void parse () throws Error {
+               var file = uri.to_file ();
+               var header = new WiiHeader (file);
+               header.check_validity ();
+
+               var prefix = platform.get_uid_prefix ();
+               var game_id = header.get_game_id ();
+
+               uid = @"$prefix-$game_id".down ();
+       }
+
+       public override string get_uid () {
+               return uid;
+       }
+}
diff --git a/plugins/wii/src/wii-plugin.vala b/plugins/wii/src/wii-plugin.vala
index 81dec08c..e6655cca 100644
--- a/plugins/wii/src/wii-plugin.vala
+++ b/plugins/wii/src/wii-plugin.vala
@@ -10,6 +10,7 @@ private class Games.WiiPlugin : Object, Plugin {
 
        static construct {
                platform = new Platform (PLATFORM_ID, PLATFORM_NAME, MIME_TYPE, PLATFORM_UID_PREFIX);
+               platform.parser_type = typeof (WiiParser);
        }
 
        public Platform[] get_platforms () {
@@ -17,36 +18,12 @@ private class Games.WiiPlugin : Object, Plugin {
        }
 
        public UriGameFactory[] get_uri_game_factories () {
-               var game_uri_adapter = new GenericGameUriAdapter (game_for_uri);
+               var game_uri_adapter = new RetroSimpleGameUriAdapter (platform);
                var factory = new GenericUriGameFactory (game_uri_adapter);
                factory.add_mime_type (MIME_TYPE);
 
                return { factory };
        }
-
-       private static string get_uid (WiiHeader header) throws Error {
-               var game_id = header.get_game_id ();
-
-               return @"$PLATFORM_UID_PREFIX-$game_id".down ();
-       }
-
-       private static Game game_for_uri (Uri uri) throws Error {
-               var file = uri.to_file ();
-               var header = new WiiHeader (file);
-               header.check_validity ();
-
-               var uid = new Uid (get_uid (header));
-               var title = new FilenameTitle (uri);
-               var media = new GriloMedia (title, MIME_TYPE);
-               var cover = new CompositeCover ({
-                       new LocalCover (uri),
-                       new GriloCover (media, uid)});
-
-               var game = new Game (uid, uri, title, platform);
-               game.set_cover (cover);
-
-               return game;
-       }
 }
 
 [ModuleInit]


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]