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




commit b553eb9eef8a21864b8b35bc96a4282216bd4830
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Tue Mar 30 02:07:25 2021 +0500

    mame: Migrate to a game parser

 plugins/mame/src/mame-parser.vala | 36 ++++++++++++++++++++++++++++++++++++
 plugins/mame/src/mame-plugin.vala | 31 ++-----------------------------
 plugins/mame/src/meson.build      |  1 +
 3 files changed, 39 insertions(+), 29 deletions(-)
---
diff --git a/plugins/mame/src/mame-parser.vala b/plugins/mame/src/mame-parser.vala
new file mode 100644
index 00000000..2a0ab32d
--- /dev/null
+++ b/plugins/mame/src/mame-parser.vala
@@ -0,0 +1,36 @@
+// This file is part of GNOME Games. License: GPL-3.0+.
+
+public class Games.MameParser : GameParser {
+       private string uid;
+       private Title title;
+
+       public MameParser (Platform platform, Uri uri) {
+               base (platform, uri);
+       }
+
+       public override void parse () throws Error {
+               var supported_games = MameGameInfo.get_supported_games ();
+
+               var file = uri.to_file ();
+               var game_id = file.get_basename ();
+               game_id = /\.zip$/.replace (game_id, game_id.length, 0, "");
+
+               if (!supported_games.contains (game_id))
+                       throw new MameError.INVALID_GAME_ID ("Invalid MAME game id “%s” for “%s”.", game_id, 
uri.to_string ());
+
+               uid = @"mame-$game_id".down ();
+
+               var title_string = supported_games[game_id];
+               title_string = title_string.split ("(")[0];
+               title_string = title_string.strip ();
+               title = new GenericTitle (title_string);
+       }
+
+       public override string get_uid () {
+               return uid;
+       }
+
+       public override Title get_title () {
+               return title;
+       }
+}
diff --git a/plugins/mame/src/mame-plugin.vala b/plugins/mame/src/mame-plugin.vala
index f60ce294..2d613258 100644
--- a/plugins/mame/src/mame-plugin.vala
+++ b/plugins/mame/src/mame-plugin.vala
@@ -12,6 +12,7 @@ private class Games.MamePlugin : Object, Plugin {
        static construct {
                string[] mime_types = { SEARCHED_MIME_TYPE };
                platform = new Platform.with_mime_types (PLATFORM_ID, PLATFORM_NAME, mime_types, 
SPECIFIC_MIME_TYPE, PLATFORM_UID_PREFIX);
+               platform.parser_type = typeof (MameParser);
        }
 
        public Platform[] get_platforms () {
@@ -19,40 +20,12 @@ private class Games.MamePlugin : 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 (SEARCHED_MIME_TYPE);
 
                return { factory };
        }
-
-       private static Game game_for_uri (Uri uri) throws Error {
-               var supported_games = MameGameInfo.get_supported_games ();
-
-               var file = uri.to_file ();
-               var game_id = file.get_basename ();
-               game_id = /\.zip$/.replace (game_id, game_id.length, 0, "");
-
-               if (!supported_games.contains (game_id))
-                       throw new MameError.INVALID_GAME_ID ("Invalid MAME game id “%s” for “%s”.", game_id, 
uri.to_string ());
-
-               var uid_string = @"mame-$game_id".down ();
-               var uid = new Uid (uid_string);
-
-               var title_string = supported_games[game_id];
-               title_string = title_string.split ("(")[0];
-               title_string = title_string.strip ();
-               var title = new GenericTitle (title_string);
-               var media = new GriloMedia (title, SPECIFIC_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]
diff --git a/plugins/mame/src/meson.build b/plugins/mame/src/meson.build
index 40706c2c..071abae1 100644
--- a/plugins/mame/src/meson.build
+++ b/plugins/mame/src/meson.build
@@ -1,6 +1,7 @@
 vala_sources = [
   'mame-error.vala',
   'mame-game-info.vala',
+  'mame-parser.vala',
   'mame-plugin.vala',
 ]
 


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