[gnome-games/wip/exalm/uid: 3/18] Remove GenericGame and make Game a class



commit 2fe637feea7af7e4f2653d3ad1d78904cd7be2a6
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Fri Feb 21 15:35:36 2020 +0500

    Remove GenericGame and make Game a class
    
    GenericGame was the last remaining implementation of Game. With this, it's
    possible to make Game a class instead of an interface.

 plugins/desktop/src/desktop-plugin.vala            |  2 +-
 plugins/dreamcast/src/dreamcast-plugin.vala        |  2 +-
 plugins/game-cube/src/game-cube-plugin.vala        |  2 +-
 plugins/libretro/src/libretro-plugin.vala          |  2 +-
 plugins/love/src/love-plugin.vala                  |  2 +-
 plugins/mame/src/mame-game-uri-adapter.vala        |  2 +-
 plugins/ms-dos/src/ms-dos-plugin.vala              |  2 +-
 plugins/nintendo-ds/src/nintendo-ds-plugin.vala    |  2 +-
 .../playstation/src/playstation-game-factory.vala  |  2 +-
 plugins/sega-cd/src/sega-cd-plugin.vala            |  2 +-
 plugins/sega-saturn/src/sega-saturn-plugin.vala    |  2 +-
 plugins/steam/src/steam-plugin.vala                |  2 +-
 .../turbografx-cd/src/turbografx-cd-plugin.vala    |  2 +-
 plugins/virtual-boy/src/virtual-boy-plugin.vala    |  2 +-
 plugins/wii/src/wii-plugin.vala                    |  2 +-
 src/core/game.vala                                 | 81 +++++++++++++++++++---
 src/database/database.vala                         |  2 +-
 src/generic/generic-game.vala                      | 77 --------------------
 src/meson.build                                    |  1 -
 src/retro/retro-simple-game-uri-adapter.vala       |  2 +-
 20 files changed, 90 insertions(+), 103 deletions(-)
---
diff --git a/plugins/desktop/src/desktop-plugin.vala b/plugins/desktop/src/desktop-plugin.vala
index 9a00b439..8d4759f2 100644
--- a/plugins/desktop/src/desktop-plugin.vala
+++ b/plugins/desktop/src/desktop-plugin.vala
@@ -58,7 +58,7 @@ private class Games.DesktopPlugin : Object, Plugin {
                var title = new DesktopTitle (app_info);
                var icon = new DesktopIcon (app_info);
 
-               var game = new GenericGame (uid, uri, title, platform);
+               var game = new Game (uid, uri, title, platform);
                game.set_icon (icon);
 
                return game;
diff --git a/plugins/dreamcast/src/dreamcast-plugin.vala b/plugins/dreamcast/src/dreamcast-plugin.vala
index 7d04fd5e..0229c113 100644
--- a/plugins/dreamcast/src/dreamcast-plugin.vala
+++ b/plugins/dreamcast/src/dreamcast-plugin.vala
@@ -46,7 +46,7 @@ private class Games.DreamcastPlugin : Object, Plugin {
                        new LocalCover (uri),
                        new GriloCover (media, uid)});
 
-               var game = new GenericGame (uid, uri, title, platform);
+               var game = new Game (uid, uri, title, platform);
                game.set_cover (cover);
 
                return game;
diff --git a/plugins/game-cube/src/game-cube-plugin.vala b/plugins/game-cube/src/game-cube-plugin.vala
index b63436d4..9ae78534 100644
--- a/plugins/game-cube/src/game-cube-plugin.vala
+++ b/plugins/game-cube/src/game-cube-plugin.vala
@@ -46,7 +46,7 @@ private class Games.GameCubePlugin : Object, Plugin {
                        new LocalCover (uri),
                        new GriloCover (media, uid)});
 
-               var game = new GenericGame (uid, uri, title, platform);
+               var game = new Game (uid, uri, title, platform);
                game.set_cover (cover);
 
                return game;
diff --git a/plugins/libretro/src/libretro-plugin.vala b/plugins/libretro/src/libretro-plugin.vala
index 2dd6f8e6..ebe1680f 100644
--- a/plugins/libretro/src/libretro-plugin.vala
+++ b/plugins/libretro/src/libretro-plugin.vala
@@ -58,7 +58,7 @@ private class Games.LibretroPlugin : Object, Plugin {
                var title = new LibretroTitle (core_descriptor);
                var icon = new LibretroIcon (core_descriptor);
 
-               var game = new GenericGame (uid, uri, title, platform);
+               var game = new Game (uid, uri, title, platform);
                game.set_icon (icon);
 
                return game;
diff --git a/plugins/love/src/love-plugin.vala b/plugins/love/src/love-plugin.vala
index 997ad740..30e3d2ec 100644
--- a/plugins/love/src/love-plugin.vala
+++ b/plugins/love/src/love-plugin.vala
@@ -42,7 +42,7 @@ private class Games.LovePlugin : Object, Plugin {
                var icon = new LoveIcon (package);
                var cover = new LocalCover (uri);
 
-               var game = new GenericGame (uid, uri, title, platform);
+               var game = new Game (uid, uri, title, platform);
                game.set_icon (icon);
                game.set_cover (cover);
 
diff --git a/plugins/mame/src/mame-game-uri-adapter.vala b/plugins/mame/src/mame-game-uri-adapter.vala
index fc240914..1bd1e82f 100644
--- a/plugins/mame/src/mame-game-uri-adapter.vala
+++ b/plugins/mame/src/mame-game-uri-adapter.vala
@@ -26,7 +26,7 @@ private class Games.MameGameUriAdapter : GameUriAdapter, Object {
                var title = new GenericTitle (title_string);
                var cover = new LocalCover (uri);
 
-               var game = new GenericGame (uid, uri, title, platform);
+               var game = new Game (uid, uri, title, platform);
                game.set_cover (cover);
 
                return game;
diff --git a/plugins/ms-dos/src/ms-dos-plugin.vala b/plugins/ms-dos/src/ms-dos-plugin.vala
index e650b1b4..f7104eb1 100644
--- a/plugins/ms-dos/src/ms-dos-plugin.vala
+++ b/plugins/ms-dos/src/ms-dos-plugin.vala
@@ -39,7 +39,7 @@ private class Games.MsDosPlugin : Object, Plugin {
                        new LocalCover (uri),
                        new GriloCover (media, uid)});
 
-               var game = new GenericGame (uid, uri, title, platform);
+               var game = new Game (uid, uri, title, platform);
                game.set_cover (cover);
 
                return game;
diff --git a/plugins/nintendo-ds/src/nintendo-ds-plugin.vala b/plugins/nintendo-ds/src/nintendo-ds-plugin.vala
index 18d78963..768925c9 100644
--- a/plugins/nintendo-ds/src/nintendo-ds-plugin.vala
+++ b/plugins/nintendo-ds/src/nintendo-ds-plugin.vala
@@ -44,7 +44,7 @@ private class Games.NintendoDsPlugin : Object, Plugin {
                        new LocalCover (uri),
                        new GriloCover (media, uid)});
 
-               var game = new GenericGame (uid, uri, title, platform);
+               var game = new Game (uid, uri, title, platform);
                game.set_icon (icon);
                game.set_cover (cover);
 
diff --git a/plugins/playstation/src/playstation-game-factory.vala 
b/plugins/playstation/src/playstation-game-factory.vala
index 7722a5aa..6ab77db1 100644
--- a/plugins/playstation/src/playstation-game-factory.vala
+++ b/plugins/playstation/src/playstation-game-factory.vala
@@ -159,7 +159,7 @@ public class Games.PlayStationGameFactory : Object, UriGameFactory {
                        new LocalCover (uri),
                        new GriloCover (media, uid)});
 
-               var game = new GenericGame (uid, uri, title, platform);
+               var game = new Game (uid, uri, title, platform);
                game.set_cover (cover);
                game.set_media_set (media_set);
 
diff --git a/plugins/sega-cd/src/sega-cd-plugin.vala b/plugins/sega-cd/src/sega-cd-plugin.vala
index fd9c2253..13baae0f 100644
--- a/plugins/sega-cd/src/sega-cd-plugin.vala
+++ b/plugins/sega-cd/src/sega-cd-plugin.vala
@@ -88,7 +88,7 @@ private class Games.SegaCDPlugin : Object, Plugin {
                        new LocalCover (uri),
                        new GriloCover (media, uid)});
 
-               var game = new GenericGame (uid, uri, title, platform);
+               var game = new Game (uid, uri, title, platform);
                game.set_cover (cover);
 
                return game;
diff --git a/plugins/sega-saturn/src/sega-saturn-plugin.vala b/plugins/sega-saturn/src/sega-saturn-plugin.vala
index 3aa61f57..fe79b1d7 100644
--- a/plugins/sega-saturn/src/sega-saturn-plugin.vala
+++ b/plugins/sega-saturn/src/sega-saturn-plugin.vala
@@ -70,7 +70,7 @@ private class Games.SegaSaturnPlugin : Object, Plugin {
                        new LocalCover (uri),
                        new GriloCover (media, uid)});
 
-               var game = new GenericGame (uid, uri, title, platform);
+               var game = new Game (uid, uri, title, platform);
                game.set_cover (cover);
 
                return game;
diff --git a/plugins/steam/src/steam-plugin.vala b/plugins/steam/src/steam-plugin.vala
index ba057e12..c45397bc 100644
--- a/plugins/steam/src/steam-plugin.vala
+++ b/plugins/steam/src/steam-plugin.vala
@@ -107,7 +107,7 @@ private class Games.SteamPlugin : Object, Plugin {
                var icon = new SteamIcon (app_id, game_id);
                var cover = new SteamCover (game_id);
 
-               var game = new GenericGame (uid, uri, title, platform);
+               var game = new Game (uid, uri, title, platform);
                game.set_icon (icon);
                game.set_cover (cover);
 
diff --git a/plugins/turbografx-cd/src/turbografx-cd-plugin.vala 
b/plugins/turbografx-cd/src/turbografx-cd-plugin.vala
index a1e09581..0bb5e912 100644
--- a/plugins/turbografx-cd/src/turbografx-cd-plugin.vala
+++ b/plugins/turbografx-cd/src/turbografx-cd-plugin.vala
@@ -49,7 +49,7 @@ private class Games.TurboGrafxCDPlugin : Object, Plugin {
                        new LocalCover (uri),
                        new GriloCover (media, uid)});
 
-               var game = new GenericGame (uid, uri, title, platform);
+               var game = new Game (uid, uri, title, platform);
                game.set_cover (cover);
 
                return game;
diff --git a/plugins/virtual-boy/src/virtual-boy-plugin.vala b/plugins/virtual-boy/src/virtual-boy-plugin.vala
index 16a9ffb4..ee20a746 100644
--- a/plugins/virtual-boy/src/virtual-boy-plugin.vala
+++ b/plugins/virtual-boy/src/virtual-boy-plugin.vala
@@ -47,7 +47,7 @@ private class Games.VirtualBoyPlugin : Object, Plugin {
                        new LocalCover (uri),
                        new GriloCover (media, uid)});
 
-               var game = new GenericGame (uid, uri, title, platform);
+               var game = new Game (uid, uri, title, platform);
                game.set_cover (cover);
 
                return game;
diff --git a/plugins/wii/src/wii-plugin.vala b/plugins/wii/src/wii-plugin.vala
index e570befa..7c507b43 100644
--- a/plugins/wii/src/wii-plugin.vala
+++ b/plugins/wii/src/wii-plugin.vala
@@ -46,7 +46,7 @@ private class Games.WiiPlugin : Object, Plugin {
                        new LocalCover (uri),
                        new GriloCover (media, uid)});
 
-               var game = new GenericGame (uid, uri, title, platform);
+               var game = new Game (uid, uri, title, platform);
                game.set_cover (cover);
 
                return game;
diff --git a/src/core/game.vala b/src/core/game.vala
index 479c5d95..722b32be 100644
--- a/src/core/game.vala
+++ b/src/core/game.vala
@@ -1,16 +1,81 @@
 // This file is part of GNOME Games. License: GPL-3.0+.
 
-public interface Games.Game : Object {
+public class Games.Game : Object {
        public signal void replaced (Game new_game);
 
-       public abstract string name { get; }
+       private string _name;
+       public string name {
+               get {
+                       try {
+                               _name = game_title.get_title ();
+                       }
+                       catch (Error e) {
+                               warning (e.message);
+                       }
 
-       public abstract Uid get_uid ();
-       public abstract Uri get_uri ();
-       public abstract Icon get_icon ();
-       public abstract Cover get_cover ();
-       public abstract Platform get_platform ();
-       public abstract MediaSet? get_media_set ();
+                       if (_name == null)
+                               _name = "";
+
+                       return _name;
+               }
+       }
+
+       private Uid game_uid;
+       private Uri game_uri;
+       private Title game_title;
+       private Icon game_icon;
+       private Cover game_cover;
+       private Platform game_platform;
+       private MediaSet? media_set;
+
+       public Game (Uid uid, Uri uri, Title title, Platform platform) {
+               game_uid = uid;
+               game_uri = uri;
+               game_title = title;
+               game_platform = platform;
+       }
+
+       public Uid get_uid () {
+               return game_uid;
+       }
+
+       public Uri get_uri () {
+               return game_uri;
+       }
+
+       public Icon get_icon () {
+               if (game_icon == null)
+                       game_icon = new DummyIcon ();
+
+               return game_icon;
+       }
+
+       public void set_icon (Icon icon) {
+               game_icon = icon;
+       }
+
+       public Cover get_cover () {
+               if (game_cover == null)
+                       game_cover = new DummyCover ();
+
+               return game_cover;
+       }
+
+       public void set_cover (Cover cover) {
+               game_cover = cover;
+       }
+
+       public MediaSet? get_media_set () {
+               return media_set;
+       }
+
+       public void set_media_set (MediaSet? media_set) {
+               this.media_set = media_set;
+       }
+
+       public Platform get_platform () {
+               return game_platform;
+       }
 
        public bool matches_search_terms (string[] search_terms) {
                if (search_terms.length != 0)
diff --git a/src/database/database.vala b/src/database/database.vala
index 939a5773..df7f8280 100644
--- a/src/database/database.vala
+++ b/src/database/database.vala
@@ -321,7 +321,7 @@ private class Games.Database : Object {
                if (game_platform == null)
                        game_platform = new DummyPlatform ();
 
-               var game = new GenericGame (game_uid, game_uri, game_title, game_platform);
+               var game = new Game (game_uid, game_uri, game_title, game_platform);
 
                if (media_set != null)
                        game.set_media_set (new MediaSet.parse (new Variant.parsed (media_set)));
diff --git a/src/meson.build b/src/meson.build
index aa8a9fe1..1faf34be 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -63,7 +63,6 @@ vala_sources = [
   'gamepad/gamepad-input.vala',
   'gamepad/gamepad-mapping-builder.vala',
 
-  'generic/generic-game.vala',
   'generic/generic-game-uri-adapter.vala',
   'generic/generic-input-capabilities.vala',
   'generic/generic-platform.vala',
diff --git a/src/retro/retro-simple-game-uri-adapter.vala b/src/retro/retro-simple-game-uri-adapter.vala
index 5d553520..d25536a0 100644
--- a/src/retro/retro-simple-game-uri-adapter.vala
+++ b/src/retro/retro-simple-game-uri-adapter.vala
@@ -17,7 +17,7 @@ private class Games.RetroSimpleGameUriAdapter : GameUriAdapter, Object {
                        new LocalCover (uri),
                        new GriloCover (media, uid)});
 
-               var game = new GenericGame (uid, uri, title, platform);
+               var game = new Game (uid, uri, title, platform);
                game.set_cover (cover);
 
                return game;


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